• 就会打印到这里。 但是在打包后,只有从Log中找到,能不能找到一个可以实时显示的工具呢? 很明显,必须有啊!!要不写这篇不就是瞎扯了么?!! 我辗转腾挪,到处寻觅,我肯定不是第一个有这个想

    本文章由cartzhang编写,转载请注明出处。 所有权利保留。 

    文章链接:http://blog.csdn.net/cartzhang/article/details/49818953

    作者:cartzhang


    一、Unity 打印日志

    Unity中,在其编辑器上有个专门的Console,快捷键:shift + Ctrl+ c 。

    代码中的Debug.Log("this is a test");就会打印到这里。


    但是在打包后,只有从Log中找到,能不能找到一个可以实时显示的工具呢?

    很明显,必须有啊!!要不写这篇不就是瞎扯了么?!!


    我辗转腾挪,到处寻觅,我肯定不是第一个有这个想法的人。

    终于有一天,我来到了七环!!!找到了几种方法,与君共享!!


    二、我想有个控制台

    之前说的Debug.Log();此函数是打印Unity控制台的。

    好办,有高人已经重新把控制台给换了地方,打印到界面的控制台上。

    就是类似控制台的一个界面。

    先放结果图样:



    1.问题来了,怎么实现的呢?

    上代码:

    我给改了名字叫TestConsole.cs了,因为之前名字为Console,这样想我这样都在一个工程中为大家测试,容易造成混乱。

    //#define USE_TESTCONSOLE
    using System.Collections.Generic;
    using UnityEngine;
    
    namespace Consolation
    {
        /// <summary>
        /// A console to display Unity's debug logs in-game.
        /// </summary>
        class TestConsole : MonoBehaviour
        {
    #if USE_TESTCONSOLE
            struct Log
            {
                public string message;
                public string stackTrace;
                public LogType type;
            }
    
            #region Inspector Settings
    
            /// <summary>
            /// The hotkey to show and hide the console window.
            /// </summary>
            public KeyCode toggleKey = KeyCode.BackQuote;
    
            /// <summary>
            /// Whether to open the window by shaking the device (mobile-only).
            /// </summary>
            public bool shakeToOpen = true;
    
            /// <summary>
            /// The (squared) acceleration above which the window should open.
            /// </summary>
            public float shakeAcceleration = 3f;
    
            /// <summary>
            /// Whether to only keep a certain number of logs.
            ///
            /// Setting this can be helpful if memory usage is a concern.
            /// </summary>
            public bool restrictLogCount = false;
    
            /// <summary>
            /// Number of logs to keep before removing old ones.
            /// </summary>
            public int maxLogs = 1000;
    
            #endregion
    
            readonly List<Log> logs = new List<Log>();
            Vector2 scrollPosition;
            bool visible;
            bool collapse;
    
            // Visual elements:
    
            static readonly Dictionary<LogType, Color> logTypeColors = new Dictionary<LogType, Color>
    		{
    			{ LogType.Assert, Color.white },
    			{ LogType.Error, Color.red },
    			{ LogType.Exception, Color.red },
    			{ LogType.Log, Color.white },
    			{ LogType.Warning, Color.yellow },
    		};
    
            const string windowTitle = "Console";
            const int margin = 20;
            static readonly GUIContent clearLabel = new GUIContent("Clear", "Clear the contents of the console.");
            static readonly GUIContent collapseLabel = new GUIContent("Collapse", "Hide repeated messages.");
    
            readonly Rect titleBarRect = new Rect(0, 0, 10000, 20);
            Rect windowRect = new Rect(margin, margin, Screen.width - (margin * 2), Screen.height - (margin * 2));
    
            void OnEnable()
            {
    #if UNITY_5
    			Application.logMessageReceived += HandleLog;
    #else
                Application.RegisterLogCallback(HandleLog);
    #endif
            }
    
            void OnDisable()
            {
    #if UNITY_5
    			Application.logMessageReceived -= HandleLog;
    #else
                Application.RegisterLogCallback(null);
    #endif
            }
    
            void Update()
            {
                if (Input.GetKeyDown(toggleKey))
                {
                    visible = !visible;
                }
    
                if (shakeToOpen && Input.acceleration.sqrMagnitude > shakeAcceleration)
                {
                    visible = true;
                }
            }
    
            void OnGUI()
            {
                if (!visible)
                {
                    return;
                }
    
                windowRect = GUILayout.Window(123456, windowRect, DrawConsoleWindow, windowTitle);
            }
    
            /// <summary>
            /// Displays a window that lists the recorded logs.
            /// </summary>
            /// <param name="windowID">Window ID.</param>
            void DrawConsoleWindow(int windowID)
            {
                DrawLogsList();
                DrawToolbar();
    
                // Allow the window to be dragged by its title bar.
                GUI.DragWindow(titleBarRect);
            }
    
            /// <summary>
            /// Displays a scrollable list of logs.
            /// </summary>
            void DrawLogsList()
            {
                scrollPosition = GUILayout.BeginScrollView(scrollPosition);
    
                // Iterate through the recorded logs.
                for (var i = 0; i < logs.Count; i++)
                {
                    var log = logs[i];
    
                    // Combine identical messages if collapse option is chosen.
                    if (collapse && i > 0)
                    {
                        var previousMessage = logs[i - 1].message;
    
                        if (log.message == previousMessage)
                        {
                            continue;
                        }
                    }
    
                    GUI.contentColor = logTypeColors[log.type];
                    GUILayout.Label(log.message);
                }
    
                GUILayout.EndScrollView();
    
                // Ensure GUI colour is reset before drawing other components.
                GUI.contentColor = Color.white;
            }
    
            /// <summary>
            /// Displays options for filtering and changing the logs list.
            /// </summary>
            void DrawToolbar()
            {
                GUILayout.BeginHorizontal();
    
                if (GUILayout.Button(clearLabel))
                {
                    logs.Clear();
                }
    
                collapse = GUILayout.Toggle(collapse, collapseLabel, GUILayout.ExpandWidth(false));
    
                GUILayout.EndHorizontal();
            }
    
            /// <summary>
            /// Records a log from the log callback.
            /// </summary>
            /// <param name="message">Message.</param>
            /// <param name="stackTrace">Trace of where the message came from.</param>
            /// <param name="type">Type of message (error, exception, warning, assert).</param>
            void HandleLog(string message, string stackTrace, LogType type)
            {
                logs.Add(new Log
                {
                    message = message,
                    stackTrace = stackTrace,
                    type = type,
                });
    
                TrimExcessLogs();
            }
    
            /// <summary>
            /// Removes old logs that exceed the maximum number allowed.
            /// </summary>
            void TrimExcessLogs()
            {
                if (!restrictLogCount)
                {
                    return;
                }
    
                var amountToRemove = Mathf.Max(logs.Count - maxLogs, 0);
    
                if (amountToRemove == 0)
                {
                    return;
                }
    
                logs.RemoveRange(0, amountToRemove);
            }
    #endif
        }
    }


    我在代码最前面添加了宏定义,使用的时候屏蔽此宏定义即可

    2.怎么使用呢?


    恩。我写的使用很简单。
    随便写个C#代码,在Update中测试的。
    // Update is called once per frame
    	void Update ()
        {
            //DebugConsole.Log(" test s");
            Debug.Log("Debug log  test");
            Console.WriteLine("this is Console Write line test ");
            ///
            //DebugConsole.instance.AddMessage("this is instance AddMessage test by cartzhang", "warning");
            //DebugConsole.Log("this is debug console log test cartzhang");
    	}

    3.结果上面已经说明了。

    这里就不重复了。

    4.这怎么实现的呢?

    原理很简单。写一个面板,往上面写字啊!

    说下啊,这个有个切换按键,就是可以控制是否显示这个面板的,按键为BackQuote,你也可以修改,BackQuote这个键呢,在ESC按键的下面就是这个“~”。

    三、这不是我想要的,我要显示在屏幕上。

    我想要显示在控制台上,就是CMD出来的那样。

    可以啊!

    1. 直接写在屏幕上的代码

    不过,我先赠送一个显示在屏幕上的。
    这样我觉得大部分的人就会满足了,最起码不用自己写GUI .Label()了啊。

    说明这个是国外友人好早之前写的,我只改变了其中某些不符合现在Unity 5 的语句,其他没有动。

    还是代码:
    /*==== DebugConsole.cs ====================================================
    * Class for handling multi-line, multi-color debugging messages.
    * Original Author: Jeremy Hollingsworth
    * Based On: Version 1.2.1 Mar 02, 2006
    * 
    * Modified: Simon Waite
    * Date: 22 Feb 2007
    *
    * Modification to original script to allow pixel-correct line spacing
    *
    * Setting the boolean pixelCorrect changes the units in lineSpacing property
    * to pixels, so you have a pixel correct gui font in your console.
    *
    * It also checks every frame if the screen is resized to make sure the 
    * line spacing is correct (To see this; drag and let go in the editor 
    * and the text spacing will snap back)
    *
    * USAGE:
    * ::Drop in your standard assets folder (if you want to change any of the
    * default settings in the inspector, create an empty GameObject and attach
    * this script to it from you standard assets folder.  That will provide
    * access to the default settings in the inspector)
    * 
    * ::To use, call DebugConsole.functionOrProperty() where 
    * functionOrProperty = one of the following:
    * 
    * -Log(string message, string color)  Adds "message" to the list with the
    * "color" color. Color is optional and can be any of the following: "error",
    * "warning", or "normal".  Default is normal.
    * 
    * Clear() Clears all messages
    * 
    * isVisible (true,false)  Toggles the visibility of the output.  Does _not_
    * clear the messages.
    * 
    * isDraggable (true, false)  Toggles mouse drag functionality
    * =========================================================================*/
    //#define USE_DEBUGCONSOLE
     
     using UnityEngine;
     using System.Collections;
    
    
    public class DebugConsole : MonoBehaviour
     {
    #if USE_DEBUGCONSOLE
        public GameObject DebugGui = null;             // The GUI that will be duplicated
        public Vector3 defaultGuiPosition = new Vector3(0.01F, 0.98F, 0F);
        public Vector3 defaultGuiScale = new Vector3(0.5F, 0.5F, 1F);
        public Color normal = Color.green;
        public Color warning = Color.yellow;
        public Color error = Color.red;
        public int maxMessages = 30;                   // The max number of messages displayed
        public float lineSpacing = 0.02F;              // The amount of space between lines
        public ArrayList messages = new ArrayList();
        public ArrayList guis = new ArrayList();
        public ArrayList colors = new ArrayList();
        public bool draggable = true;                  // Can the output be dragged around at runtime by default? 
        public bool visible = true;                    // Does output show on screen by default or do we have to enable it with code? 
        public bool pixelCorrect = false; // set to be pixel Correct linespacing
        public static bool isVisible
        {                                      
            get
            {
                return DebugConsole.instance.visible;
            }
     
            set
            {
                DebugConsole.instance.visible = value;
                if (value == true)
                {
                    DebugConsole.instance.Display();
                }
                else if (value == false)
                {
                    DebugConsole.instance.ClearScreen();
                }
            }
        }
     
        public static bool isDraggable
        {                                      
            get
            {
                return DebugConsole.instance.draggable;
            }
     
            set
            {
                DebugConsole.instance.draggable = value;
     
            }
        }
     
     
        private static DebugConsole s_Instance = null;   // Our instance to allow this script to be called without a direct connection.
        public static DebugConsole instance
        {
            get
            {
                if (s_Instance == null)
                {
                    s_Instance = FindObjectOfType(typeof(DebugConsole)) as DebugConsole;
                    if (s_Instance == null)
                    {
                        GameObject console = new GameObject();
                        console.AddComponent<DebugConsole>();
                        console.name = "DebugConsoleController";
                        s_Instance = FindObjectOfType(typeof(DebugConsole)) as DebugConsole;
                        DebugConsole.instance.InitGuis();
                    }
     
                }
     
                return s_Instance;
            }
        }
     
        void Awake()
        {
            s_Instance = this;
            InitGuis();
     
        }
     
        protected bool guisCreated = false;
        protected float screenHeight =-1;
        public void InitGuis()
        {
        	float usedLineSpacing = lineSpacing;
            screenHeight = Screen.height;
            if(pixelCorrect)
                usedLineSpacing = 1.0F / screenHeight * usedLineSpacing;  
     
            if (guisCreated == false)
            {
                if (DebugGui == null)  // If an external GUIText is not set, provide the default GUIText
                {
                    DebugGui = new GameObject();
                    DebugGui.AddComponent<GUIText>();
                    DebugGui.name = "DebugGUI(0)";
                    DebugGui.transform.position = defaultGuiPosition;
                    DebugGui.transform.localScale = defaultGuiScale;
                }
     
                // Create our GUI objects to our maxMessages count
                Vector3 position = DebugGui.transform.position;
                guis.Add(DebugGui);
                int x = 1;
     
                while (x < maxMessages)
                {
                    position.y -= usedLineSpacing;
                    GameObject clone = null;
                    clone = (GameObject)Instantiate(DebugGui, position, transform.rotation);
                    clone.name = string.Format("DebugGUI({0})", x);
                    guis.Add(clone);
                    position = clone.transform.position;
                    x += 1;
                }
     
                x = 0;
                while (x < guis.Count)
                {
                    GameObject temp = (GameObject)guis[x];
                    temp.transform.parent = DebugGui.transform;
                    x++;
                }
                guisCreated = true;
            } else {
            	// we're called on a screensize change, so fiddle with sizes
                Vector3 position = DebugGui.transform.position;
                for(int x=0;x < guis.Count; x++)
                {
                    position.y -= usedLineSpacing;
                	GameObject temp = (GameObject)guis[x];
                    temp.transform.position= position;
                }    	
            }
        }
     
     
     
        bool connectedToMouse = false;  
        void Update()
        {
        	// If we are visible and the screenHeight has changed, reset linespacing
        	if (visible == true && screenHeight != Screen.height)
            {
                InitGuis();
            }
            if (draggable == true)
            {
                if (Input.GetMouseButtonDown(0))
                {
                    if (connectedToMouse == false && DebugGui.GetComponent<GUIText>().HitTest((Vector3)Input.mousePosition) == true)
                    {
                        connectedToMouse = true;
                    }
                    else if (connectedToMouse == true)
                    {
                        connectedToMouse = false;
                    }
     
                }
     
                if (connectedToMouse == true)
                {
                    float posX = DebugGui.transform.position.x;
                    float posY = DebugGui.transform.position.y;
                    posX = Input.mousePosition.x / Screen.width;
                    posY = Input.mousePosition.y / Screen.height;
                    DebugGui.transform.position = new Vector3(posX, posY, 0F);
                }
            }
     
        }
        //+++++++++ INTERFACE FUNCTIONS ++++++++++++++++++++++++++++++++
        public static void Log(string message, string color)
        {
            DebugConsole.instance.AddMessage(message, color);
     
        }
        //++++ OVERLOAD ++++
        public static void Log(string message)
        {
            DebugConsole.instance.AddMessage(message);
        }
     
        public static void Clear()
        {
            DebugConsole.instance.ClearMessages();
        }
        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     
     
        //---------- void AddMesage(string message, string color) ------
        //Adds a mesage to the list
        //--------------------------------------------------------------
     
        public void AddMessage(string message, string color)
        {
            messages.Add(message);
            colors.Add(color);
            Display();
        }
        //++++++++++ OVERLOAD for AddMessage ++++++++++++++++++++++++++++
        // Overloads AddMessage to only require one argument(message)
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        public void AddMessage(string message)
        {
            messages.Add(message);
            colors.Add("normal");
            Display();
        }
     
     
        //----------- void ClearMessages() ------------------------------
        // Clears the messages from the screen and the lists
        //---------------------------------------------------------------
        public void ClearMessages()
        {
            messages.Clear();
            colors.Clear();
            ClearScreen();
        }
     
     
        //-------- void ClearScreen() ----------------------------------
        // Clears all output from all GUI objects
        //--------------------------------------------------------------
        void ClearScreen()
        {
            if (guis.Count < maxMessages)
            {
                //do nothing as we haven't created our guis yet
            }
            else
            {
                int x = 0;
                while (x < guis.Count)
                {
                    GameObject gui = (GameObject)guis[x];   
                    gui.GetComponent<GUIText>().text = "";
                    //increment and loop
                    x += 1;
                }
            }
        }   
     
     
        //---------- void Prune() ---------------------------------------
        // Prunes the array to fit within the maxMessages limit
        //---------------------------------------------------------------
        void Prune()
        {
            int diff;
            if (messages.Count > maxMessages)
            {
                if (messages.Count <= 0)
                {
                    diff = 0;
                }
                else
                {
                    diff = messages.Count - maxMessages;
                }
                messages.RemoveRange(0, (int)diff);
                colors.RemoveRange(0, (int)diff);
            }
     
        }
     
        //---------- void Display() -------------------------------------
        // Displays the list and handles coloring
        //---------------------------------------------------------------
        void Display()
        {
            //check if we are set to display
            if (visible == false)
            {
                ClearScreen();
            }
            else if (visible == true)
            {
     
     
                if (messages.Count > maxMessages)
                {
                    Prune();
                }
     
                // Carry on with display
                int x = 0;
                if (guis.Count < maxMessages)
                {
                    //do nothing as we havent created our guis yet
                }
                else
                {
                    while (x < messages.Count)
                    {
                        GameObject gui = (GameObject)guis[x];   
     
                        //set our color
                        switch ((string)colors[x])
                        {
                            case "normal": gui.GetComponent<GUIText>().material.color = normal;
                                break;
                            case "warning": gui.GetComponent<GUIText>().material.color = warning;
                                break;
                            case "error": gui.GetComponent<GUIText>().material.color = error;
                                break;
                        }
     
                        //now set the text for this element
                        gui.GetComponent<GUIText>().text = (string)messages[x];
     
                        //increment and loop
                        x += 1;
                    }
                }
     
            }
        }
    #endif
     
     }// End DebugConsole Class
    

    2.使用方法


     //DebugConsole.instance.AddMessage("this is instance AddMessage test by cartzhang", "warning");
            //DebugConsole.Log("this is debug console log test cartzhang");

    3.结果如图




    四、这还不是我想要的,我要显示在控制台上,就是CMD出来的那样。

    好吧,你赢了!!

    你往下看吧!


    -----------THE END ---------------

    若有问题,请随时联系!
    非常感谢!
    --------

    由于担心篇幅过长,写成下一篇吧。
    再次感谢各位!


    展开全文
  • unity3d控制台输出

    2019-07-26 17:00:47
  • inputfield标签控制台打印object这说明没有字符串给入这是因为inputfield下的text不能人为写入值,只能在game界面输入。所以这个标签里的text做个默认值不好搞。...

    inputfield标签控制台打印object

    这说明没有字符串给入

    这是因为

    inputfield下的text不能人为写入值,只能在game界面输入。

    所以这个标签里的text做个默认值不好搞。

    展开全文
  • 蓝鸥Unity开发基础——控制台输入输出学习笔记一、控制台输入语句——Console.ReadLine ();从控制台中输入一些文本信息我们的程序中需要使用一个字符串类型的变量接收从控制台中读取的输入信息二、控制台输出语句1...

    蓝鸥Unity开发基础——控制台输入输出学习笔记

    一、控制台输入语句——Console.ReadLine ();
    从控制台中输入一些文本信息到我们的程序中
     
    需要使用一个字符串类型的变量接收从控制台中读取的输入信息
    二、控制台输出语句
    1、Console.WriteLine();会在当前打印的信息末尾加上信息回车换行
    2、Console.Write (");不会再末尾加上回车换行
    三、格式化输出——{}
    在格式化输出中,大括号表示占位符,大括号中需要一个索引号,索引是从0开始的

    索引不能使用超出范围的索引,索引可以重复使用

    using System;

    namespace Lesson09
    {
        class MainClass
        {
            public static void Main (string[] args)
            {
                /* 控制台输出语句
                 * 1Console.WriteLine“”;
                 * 2Console.Write (" ");
                */
                //Console 控制台
                //在控制台上写一行文本,“Hello”
                //控制台输出,输出一些信息显示在控制台上

                //WriteLine        会在当前打印的信息末尾加上信息回车换行
                //Write    不会再末尾加上回车换行
                Console.WriteLine ("Hello ");
                Console.Write ("World!");
                Console.Write ("老王");

                /* 控制台输入*/
                //从控制台中输入一些文本信息到我们的程序中
                //需要使用一个字符串类型的变量接收从控制台中读取的输入信息
                //string str = Console.ReadLine();
                //Console.WriteLine ("你刚才输入了:" + str);

                Console.WriteLine ("请输入你的年龄:" );
                string agestr = Console.ReadLine ();
                int age = int.Parse (agestr);
                //Console.WriteLine ("你的哥哥的年龄要大于等于:"+age );

                /* 格式化输入*/
                //在格式化输出中,大括号表示占位符,大括号中需要一个索引号,索引是从0开始的
                //Console.WriteLine ("你的哥哥的年龄要大于等于{0}岁:",age );
                //Console.WriteLine ("你的哥哥的年龄要大于等于{0},身高肯定超过{1}厘米,他的口头禅是{2}",age,178,"红红火火恍恍惚惚" );
                Console.WriteLine ("你的哥哥的年龄要大于等于{2},身高肯定超过{0}厘米,他的口头禅是{1}",178,"红红火火恍恍惚惚",age );
        
                //不能使用超出范围的索引,索引可以重复使用

            }
        }
    }



    展开全文
  • Unity里面有个Console控制台系统,可以打印在脚本中的Debug日志,警告和错误。但是有时我们在手机上,或者打出的exe可执行应用执行时,无法看到日志,想找错误的话非常麻烦。 所以想了个办法,实现了一个控制台日志...

    前言

    Unity里面有个Console控制台系统,可以打印在脚本中的Debug日志,警告和错误。但是有时我们在手机上,或者打出的exe可执行应用执行时,无法看到日志,想找错误的话非常麻烦。
    所以想了个办法,实现了一个控制台日志的GUI显示,不管是手机还是发布的app,随时可以显示日志到屏幕上。
    如果想LogGUI,添加到任意游戏对象身上作为组件即可。

    下面直接上代码

    //#define USE_TESTCONSOLE
    using System.Collections.Generic;
    using UnityEngine;
    
    /// <summary>
    /// A console to display Unity's debug logs in-game.
    /// </summary>
    class LogGUI : MonoBehaviour
    {
    #if LogGUI
            struct Log
            {
                public string message;
                public string stackTrace;
                public LogType type;
            }
     
        #region Inspector Settings
     
            /// <summary>
            /// The hotkey to show and hide the console window.
            /// </summary>
            public KeyCode toggleKey = KeyCode.BackQuote;
     
            /// <summary>
            /// Whether to open the window by shaking the device (mobile-only).
            /// </summary>
            public bool shakeToOpen = true;
     
            /// <summary>
            /// The (squared) acceleration above which the window should open.
            /// </summary>
            public float shakeAcceleration = 3f;
     
            /// <summary>
            /// Whether to only keep a certain number of logs.
            ///
            /// Setting this can be helpful if memory usage is a concern.
            /// </summary>
            public bool restrictLogCount = false;
     
            /// <summary>
            /// Number of logs to keep before removing old ones.
            /// </summary>
            public int maxLogs = 1000;
     
        #endregion
     
            readonly List<Log> logs = new List<Log>();
            Vector2 scrollPosition;
            bool visible;
            bool collapse;
     
            // Visual elements:
            static readonly Dictionary<LogType, Color> logTypeColors = new Dictionary<LogType, Color>
    		{
    			{ LogType.Assert, Color.white },
    			{ LogType.Error, Color.red },
    			{ LogType.Exception, Color.red },
    			{ LogType.Log, Color.white },
    			{ LogType.Warning, Color.yellow },
    		};
     
            const string windowTitle = "Console";
            const int margin = 20;
            static readonly GUIContent clearLabel = new GUIContent("Clear", "Clear the contents of the console.");
            static readonly GUIContent collapseLabel = new GUIContent("Collapse", "Hide repeated messages.");
     
            readonly Rect titleBarRect = new Rect(0, 0, 10000, 20);
            Rect windowRect = new Rect(margin, margin, Screen.width - (margin * 2), Screen.height - (margin * 2));
     
            void OnEnable()
            {
    #if UNITY_5
    			Application.logMessageReceived += HandleLog;
    #else
                Application.RegisterLogCallback(HandleLog);
    #endif
            }
     
            void OnDisable()
            {
    #if UNITY_5
    			Application.logMessageReceived -= HandleLog;
    #else
                Application.RegisterLogCallback(null);
    #endif
            }
     
            void Update()
            {
                if (Input.GetKeyDown(toggleKey))
                {
                    visible = !visible;
                }
     
                if (shakeToOpen && Input.acceleration.sqrMagnitude > shakeAcceleration)
                {
                    visible = true;
                }
            }
     
            void OnGUI()
            {
                //i(!visible)
                //{            //  return;
                //} 
                windowRect = GUILayout.Window(123456, windowRect, DrawConsoleWindow, windowTitle);
            }
     
            /// <summary>
            /// Displays a window that lists the recorded logs.
            /// </summary>
            /// <param name="windowID">Window ID.</param>
            void DrawConsoleWindow(int windowID)
            {
                DrawLogsList();
                DrawToolbar();
     
                // Allow the window to be dragged by its title bar.
                GUI.DragWindow(titleBarRect);
            }
     
            /// <summary>
            /// Displays a scrollable list of logs.
            /// </summary>
            void DrawLogsList()
            {
                scrollPosition = GUILayout.BeginScrollView(scrollPosition);
     
                // Iterate through the recorded logs.
                for (var i = 0; i < logs.Count; i++)
                {
                    var log = logs[i];
     
                    // Combine identical messages if collapse option is chosen.
                    if (collapse && i > 0)
                    {
                        var previousMessage = logs[i - 1].message;
     
                        if (log.message == previousMessage)
                        {
                            continue;
                        }
                    }
     
                    GUI.contentColor = logTypeColors[log.type];
                    GUILayout.Label(log.message);
                }
     
                GUILayout.EndScrollView();
     
                // Ensure GUI colour is reset before drawing other components.
                GUI.contentColor = Color.white;
            }
     
            /// <summary>
            /// Displays options for filtering and changing the logs list.
            /// </summary>
            void DrawToolbar()
            {
                GUILayout.BeginHorizontal();
     
                if (GUILayout.Button(clearLabel))
                {
                    logs.Clear();
                }
     
                collapse = GUILayout.Toggle(collapse, collapseLabel, GUILayout.ExpandWidth(false));
     
                GUILayout.EndHorizontal();
            }
     
            /// <summary>
            /// Records a log from the log callback.
            /// </summary>
            /// <param name="message">Message.</param>
            /// <param name="stackTrace">Trace of where the message came from.</param>
            /// <param name="type">Type of message (error, exception, warning, assert).</param>
            void HandleLog(string message, string stackTrace, LogType type)
            {
                logs.Add(new Log
                {
                    message = message,
                    stackTrace = stackTrace,
                    type = type,
                });
     
                TrimExcessLogs();
            }
     
            /// <summary>
            /// Removes old logs that exceed the maximum number allowed.
            /// </summary>
            void TrimExcessLogs()
            {
                if (!restrictLogCount)
                {
                    return;
                }
     
                var amountToRemove = Mathf.Max(logs.Count - maxLogs, 0);
     
                if (amountToRemove == 0)
                {
                    return;
                }
     
                logs.RemoveRange(0, amountToRemove);
            }
    #endif
    }
    
    
    展开全文
  • 接上一个汽车控制,现在我需要实现的是在...我拿来改了一下,灰常对不起,我找了半天找不原博地址了,我说一下修改的内容吧,由于原程序虽然可以打印log,但是不能和控制台一样往下实时刷新,就是它的界面始终在第...
  • 项目里,有同事把外部的 cmake 编译 C++ 的脚本集成 unity编辑器里来 ,并且把编译输出实时打印到 Unity控制台里。实现这一功能主要依赖于 .net framework 的 System.Diagnostics.Process 类。 Process 类可以...
  • 为了方便在安卓和苹果手机上查看打印,就用GUI仿照unity的Colsole做了一个显示在屏幕上的Colsole,第一次用GUI做的比较简陋,最后有下载地址。 using System.Collections.Generic; using UnityEngine; // ┌...
  • 描述:将Unity控制台输出的信息输出手机端 条件:有一个公网IP,或者一台服务器 原理:服务端程序在服务端运行,主要负责把消息转发给其他客户端; 客户端程序将消息发送给服务端,同时将其封装为一个dll用于...
  • 今天在调试的时候,将一个鼠标事件打印到控制台,但是发现每个事件只打印一次。一开始还以为逻辑写错了只执行了一次,最后发现,在console窗口的左上角有一个“Collapse”选项,如果选上的话,那么连续的相同日志将...
  • unity3D-游戏/AR/VR在线就业班 C#控制台输入输出学习笔记
  • 今天介绍个非常NB 酷炫的Unity功能 请勿模仿 上代码 在Start()里面加上以下代码 void Start () { Debug.Log("->" + "我是控制台带颜色的字体" + ""); Debug.Log("->" + "我是控制台带颜色的字体" + "")...
  • unity控制台日志双击定位 打开该设置项完整路径Editor--->Project Settings-->Player--->Other Setting ...
  • 今天我们来一起来学习Unity3D中一个很重要的概念:碰撞。为什么说碰撞很重要呢?因为在游戏中无时无刻不充满碰撞啊,在飞行类游戏中我们需要判断炮弹是否击中了敌人,在RPG游戏中我们需要判断玩家是否对敌人造成了...
  •  在屏幕上打印游戏中的消息是经常需要的功能,本文实现一个带有一定特色的文字消息打印,效果如图所示:消息列表框会根 据消息缓存的行数来决定显示速度,如果缓存列表里存储的消息行数比较多,则显示的速度会...
  • 本文章由cartzhang编写,转载请注明出处。 所有权利保留。 文章链接:http://blog.csdn.net/cartzhang/article/details/49884507 作者:cartzhang 第一部分博客链接: ...
  • Unity3D命令行参数

    2020-07-03 11:44:37
    unity3d的一些命令行参数在自动化工具开发时要用到,很有用,记一下! 参数详情 -batchmode 在 批处理模式下运行Unity。应始终与其他命令行参数一起使用,因为它确保不会弹出窗口,无需任何人为的干预。当脚本代码...
  • Unity 实现Debug实时输出屏幕或控制台上,并将Log信息记录在日志文件中
  • 前几天项目要上线,打包出来的放安卓手机上出现了bug,但是在编辑器里面却没有报错,所以我们主程就写出来了这一个功能来调试bug,我觉得很好用,所以拿出来分享一下 主要就是一个回调函数 Application....
1 2 3 4 5 ... 20
收藏数 731
精华内容 292