資源簡介
Unity的debug輸出顯示在游戲場景Game ;Unity的debug輸出顯示在游戲場景中

代碼片段和文件信息
using?UnityEngine;
using?System.Collections;
using?System.Collections.Generic;
public?class?DebugConsole?:?MonoBehaviour
{?
????private?static?DebugConsole?instance?=?null;?
????public?class?Log
????{
????????public?string?msg;
????????public?string?stacktrace;
????????public?LogType?type;
????????public?Log(string?msg?string?stacktrace?LogType?type)
????????{
????????????this.msg?=?msg;
????????????this.stacktrace?=?stacktrace;
????????????this.type?=?type;
????????}
????}
????
????static?readonly?Dictionary?logTypeColors?=?new?Dictionary
????????{
????????????{?LogType.Assert?Color.white?}
????????????{?LogType.Error?Color.red?}
????????????{?LogType.Exception?Color.red?}
????????????{?LogType.Log?Color.white?}
????????????{?LogType.Warning?Color.yellow?}
????????};
????private?double?lastInterval?=?0.0;
????private?int?frames?=?0;
????private?float?m_fps;
????private?float?m_accumTime?=?0;
????private?float?m_fpsUpdateInterval?=?0.5f;
????private?string?strFPS;
????private?string?strMem;
????private?List?m_logs?=?new?List();
????private?Vector2?scrollPosition?=?Vector2.zero;
????private?bool?m_logEnabled?=?true;
????void?Awake()
????{
????????if?(instance?==?null)
????????{
????????????instance?=?this;
????????????DontDestroyonload(gameobject);
????????}
????}
????void?Start()
????{
????????lastInterval?=?Time.realtimeSinceStartup;
????????frames?=?0;
????}
????void?HandleLog(string?msg?string?stacktrace?LogType?type)
????{
????????if?(!m_logEnabled)
????????{
????????????return;
????????}
????????//if?(type?==?LogType.Assert?||?type?==?LogType.Error?||?type?==?LogType.Exception)?{
????????m_logs.Add(new?Log(msg?stacktrace?type));
????????//}
????????scrollPosition.y?=?float.MaxValue;
????}
????void?OnEnable()
????{
????????Application.logMessageReceived?+=?HandleLog;
????}
????void?OnDisable()
????{
????????Application.logMessageReceived?-=?HandleLog;
????}
????//?Update?is?called?once?per?frame
????void?Update()
????{
????????++frames;
????????float?timeNow?=?Time.realtimeSinceStartup;
????????if?(timeNow?-?lastInterval?>?m_fpsUpdateInterval)
????????{
????????????float?fps?=?frames?/?(float)(timeNow?-?lastInterval);
????????????float?ms?=?1000.0f?/?Mathf.Max(fps?0.0001f);
????????????strFPS?=?string.Format(“{0}?ms?{1}FPS“?ms.ToString(“f1“)?fps.ToString(“f2“));
????????????frames?=?0;
????????????lastInterval?=?timeNow;
????????}
????????//?system?info
????????if?(Time.frameCount?%?30?==?0)
????????{
????????????strMem?=?string.Format(“memory?:?{0}?MB“?System.GC.GetTotalMemory(false)?/?(1024?*?1024));
????????}
????}
????void?OnGUI()
????{
????????GUI.skin.label.fontSize?=?24;?
????????GUI.skin.button.fontSize?=?24;
????????GUI.skin.button.margin?=?new?RectOffset(20?10?10?10);
????????GUILayout.Label(strFPS);
????????//GUILayout.Label?(strM
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????4213??2017-12-05?15:29??DebugConsole.cs
- 上一篇:粒子群優化算法優化CEC基準測試函數
- 下一篇:R語言LDA對鸞尾花數據分類
評論
共有 條評論