Unity In-Game Debug Console with Log Filtering - Display and Filter Unity Logs in Your Game
using\u0020System.Collections.Generic;using\u0020UnityEngine;
///\u0020
///\u0020A\u0020console\u0020to\u0020display\u0020Unity's\u0020debug\u0020logs\u0020in-game.
///\u0020
///\u0020
///\u0020The\u0020hotkey\u0020to\u0020show\u0020and\u0020hide\u0020the\u0020console\u0020window.
///\u0020
///\u0020
///\u0020A\u0020window\u0020that\u0020displayss\u0020the\u0020recorded\u0020logs.
///\u0020
///\u0020<param\u0020name="windowID">Window\u0020ID.void\u0020ConsoleWindow(int\u0020windowID){scrollPosition\u0020=\u0020GUILayout.BeginScrollView(scrollPosition);currentFilterType\u0020=\u0020(LogFilterType)GUILayout.SelectionGrid((int)currentFilterType,\u0020new\u0020string[]\u0020{\u0020"All",\u0020"Log",\u0020"Warning",\u0020"Error",\u0020"Exception"\u0020},\u00205);//\u0020Iterate\u0020through\u0020the\u0020recorded\u0020logs.\nfor\u0020(int\u0020i\u0020=\u00200;\u0020i\u0020<\u0020logs.Count;\u0020i++){var\u0020log\u0020=\u0020logs[i];if\u0020(currentFilterType\u0020==\u0020LogFilterType.All\u0020||\u0020log.type.ToString()\u0020==\u0020currentFilterType.ToString()){//\u0020Combine\u0020identical\u0020messages\u0020if\u0020collapse\u0020option\u0020is\u0020chosen.\nif\u0020(collapse){var\u0020messageSameAsPrevious\u0020=\u0020i\u0020>\u00200\u0020&&\u0020log.message\u0020==\u0020logs[i\u0020-\u00201].message;if\u0020(messageSameAsPrevious){continue;}}GUI.contentColor\u0020=\u0020logTypeColors[log.type];if\u0020(log.type\u0020==\u0020LogType.Exception){GUILayout.Label(log.message\u0020+\u0020"\n<color=while>"\u0020+\u0020log.stackTrace\u0020+\u0020"");}else{GUILayout.Label(log.message);}}}GUILayout.EndScrollView();GUI.contentColor\u0020=\u0020Color.white;GUILayout.BeginHorizontal();if\u0020(GUILayout.Button(clearLabel)){logs.Clear();}if\u0020(GUILayout.Button(collapseLabel)){collapse\u0020=\u0020!collapse;}GUILayout.EndHorizontal();//\u0020Allow\u0020the\u0020window\u0020to\u0020be\u0020dragged\u0020by\u0020its\u0020title\u0020bar.\n//GUI.DragWindow(titleBarRect);}
///\u0020
///\u0020Records\u0020a\u0020log\u0020from\u0020the\u0020log\u0020callback.
///\u0020
///\u0020<param\u0020name="message">Message.
///\u0020<param\u0020name="stackTrace">Trace\u0020of\u0020where\u0020the\u0020message\u0020came\u0020from.
///\u0020<param\u0020name="type">Type\u0020of\u0020message\u0020(error,\u0020exception,\u0020warning,\u0020assert).void\u0020HandleLog(string\u0020message,\u0020string\u0020stackTrace,\u0020LogType\u0020type){logs.Add(new\u0020Log(){message\u0020=\u0020message,stackTrace\u0020=\u0020stackTrace,type\u0020=\u0020type,});
原文地址: https://www.cveoy.top/t/topic/qjbG 著作权归作者所有。请勿转载和采集!