コード例 #1
0
        void OnEnable()
        {
            // Only one instance of debug console is allowed
            if (instance == null)
            {
                instance       = this;
                pooledLogItems = new List <DebugLogItem>();

                canvasTR = transform;

                // Associate sprites with log types
                logSpriteRepresentations = new Dictionary <LogType, Sprite>
                {
                    { LogType.Log, infoLog },
                    { LogType.Warning, warningLog },
                    { LogType.Error, errorLog },
                    { LogType.Exception, errorLog },
                    { LogType.Assert, errorLog }
                };

                // Initially, all log types are visible
                filterInfoButton.color    = filterButtonsSelectedColor;
                filterWarningButton.color = filterButtonsSelectedColor;
                filterErrorButton.color   = filterButtonsSelectedColor;

                // When collapse is disabled and all log types are visible (initial state),
                // the order of the debug entries to show on screen is the same as
                // the order they were intercepted
                collapsedLogEntries          = new List <DebugLogEntry>();
                uncollapsedLogEntriesIndices = new List <int>();
                indicesOfListEntriesToShow   = uncollapsedLogEntriesIndices;

                recycledListView.SetLogItemHeight(logItemPrefab.Transform.sizeDelta.y);
                recycledListView.SetCollapsedEntriesList(collapsedLogEntries);
                recycledListView.SetEntryIndicesList(indicesOfListEntriesToShow);

                // If it is a singleton object, don't destroy it between scene changes
                if (singleton)
                {
                    DontDestroyOnLoad(gameObject);
                }
            }
            else if (this != instance)
            {
                Destroy(gameObject);
                return;
            }

            // Intercept debug entries
            Application.logMessageReceived -= ReceivedLog;
            Application.logMessageReceived += ReceivedLog;

            if (receiveLogcatLogsInAndroid)
            {
                if (logcatListener == null)
                {
                    logcatListener = new DebugLogLogcatListener();
                }

                logcatListener.Start(logcatArguments);
            }

            // Listen for entered commands
            commandInputField.onValidateInput -= OnValidateCommand;
            commandInputField.onValidateInput += OnValidateCommand;

            /*Debug.LogAssertion( "assert" );
             * Debug.LogError( "error" );
             * Debug.LogException( new System.IO.EndOfStreamException() );
             * Debug.LogWarning( "warning" );
             * Debug.Log( "log" );*/
        }