为了方便在安卓和苹果手机上查看打印,就用GUI仿照unity的Colsole做了一个显示在屏幕上的Colsole,第一次用GUI做的比较简陋,实际项目不要这样做,log多了会卡,或者优化一下。
using System.Collections.Generic;
using UnityEngine;
// ┌────────────────┐
// │┌┐ ┌┐ ┌┐ │
// │└┘ └┘ └┘ │
// │┌──────────────┐│
// ││ ││
// ││ ScrollView ││
// ││ ││
// │└──────────────┘│
// │┌──────────────┐│
// │└──────────────┘│
// └────────────────┘
public class ConsoleLogOutput : MonoBehaviour
{
/// <summary>
/// log信息
/// </summary>
struct LogMsg
{
public string condition;
public string stackTrace;
public LogType type;
public LogMsg(string condition, string stackTrace, LogType type)
{
//因为GUIButton字符串长度有限制(button宽度限制),对显示的log信息长度做截取
if (condition.Length > 100)
this.condition = condition.Substring(0, 100);
else
this.condition = condition;
this.stackTrace = condition + "\n" + stackTrace;
this.type = type;
}
}
/// <summary>
/// 控制台是否是打开的
/// </summary>
bool isDrawGui = false;
/// <summary>
/// 全部log信息列表
/// </summary>
List<LogMsg> _logAllMsg;
List<LogMsg> logAllMsg
{
get
{
if (_logAllMsg == null)
{
_logAllMsg = new List<LogMsg>();
}
return _logAllMsg;
}
}
/// <summary>
/// log信息列表
/// </s