Unity3d console customization, unity3d Console
Sun Guangdong: 2015-2-7/1: 19 reprint please indicate the source: http://blog.csdn.net/u010019717
More comprehensive content please see my game pretty cool address: http://www.unitymanual.com/space-uid-18602.html
Let's take a look at the effect first: Say goodbye to boring and monotonous!
In fact, it is very simple to mark the string with Rich Text. It is enough to use it because unity supports it.
You can read the following details:
Http://docs.unity3d.com/Manual/StyledText.html
Then we will test it in the Editor and in the game respectively.
Add the following code:
Create the "Editor" folder and add the following two files.
EditorHelper. cs
Using UnityEngine; using System. collections; public static class EditorHelper {//......} /// <summary> // format the Log output of the personalized editor /// </summary> public static class EditorLog {public static void Log (string log) {Debug. log (string. format ("<B> <color = {0}> <size = {1}> {2} </size> </color> </B> ", "lime", 15, log);} public static void LogError (string logError) {Debug. logError (string. format ("<B> <color = {0}> <size = {1}> {2} </size> </color> </B> ", "red", 15, logError);} public static void LogWarning (string logWarning) {Debug. logWarning (string. format ("<B> <color = {0}> <size = {1}> {2} </size> </color> </B> ", "yellow", 15, logWarning ));}}
MyEditor. cs
Using UnityEngine; using System. collections; using UnityEditor; public class MyEditor: EditorWindow {[MenuItem ("Game/My EditorWindow # % & a")] // shortcut key Shift + Ctrl + Alt + Astatic void Init () {// Get existing open window or if none, make a new one: MyEditor window = (MyEditor) EditorWindow. getWindow (typeof (MyEditor);} // Use this for initializationvoid OnEnable () {EditorLog. log ("this is the normal output test of the Editor! "); EditorLog. LogWarning (" this is a test of Editor warning output! "); EditorLog. LogError (" this is a test of Editor error output! ");}}
Click the following menu in the editor to view the console output.
Continue to write the script. It is not placed under a special folder.
GameHelper. cs
Using UnityEngine; using System. collections; public static class GameHelper {//......} /// <summary> /// format the Log output of the personalized editor /// </summary> public static class GameLog {public static void Log (string log) {Debug. log (string. format ("<B> <color = {0}> <size = {1}> {2} </size> </color> </B> ", "lime", 15, log);} public static void LogError (string logError) {Debug. logError (string. format ("<B> <color = {0}> <size = {1}> {2} </size> </color> </B> ", "red", 15, logError);} public static void LogWarning (string logWarning) {Debug. logWarning (string. format ("<B> <color = {0}> <size = {1}> {2} </size> </color> </B> ", "yellow", 15, logWarning ));}}
GameLogTest. cs
Using UnityEngine; using System. Collections; [ExecuteInEditMode] public class GameLogTest: MonoBehaviour {// Use this for initializationvoid Start () {GameLog. Log ("this is a test of normal Game output! "); GameLog. LogWarning (" this is a test of the Game warning output! "); GameLog. LogError (" this is a test of Game error output! ") ;}// Update is called once per framevoid Update (){}}
Run the scriptGameLogTest. cs is mounted to any object in the scenario. The new output is displayed.
OK