Ejemplo n.º 1
0
        private void Awake()
        {
            // Only one instance of debug console is allowed
            if (instance == null)
            {
                instance = this;

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

            pooledLogEntries = new List <DebugLogEntry>(16);
            pooledLogItems   = new List <DebugLogItem>(16);
            queuedLogEntries = new DynamicCircularBuffer <QueuedDebugLogEntry>(16);
            commandHistory   = new CircularBuffer <string>(commandHistorySize);

            logEntriesLock = new object();

            canvasTR                       = (RectTransform)transform;
            logItemsScrollRectTR           = (RectTransform)logItemsScrollRect.transform;
            logItemsScrollRectOriginalSize = logItemsScrollRectTR.sizeDelta;

            // 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;

            collapsedLogEntries          = new List <DebugLogEntry>(128);
            collapsedLogEntriesMap       = new Dictionary <DebugLogEntry, int>(128);
            uncollapsedLogEntriesIndices = new DebugLogIndexList();
            indicesOfListEntriesToShow   = new DebugLogIndexList();

            recycledListView.Initialize(this, collapsedLogEntries, indicesOfListEntriesToShow, logItemPrefab.Transform.sizeDelta.y);
            recycledListView.UpdateItemsInTheList(true);

            if (minimumHeight < 200f)
            {
                minimumHeight = 200f;
            }

            if (!enableSearchbar)
            {
                searchbar = null;
                searchbarSlotTop.gameObject.SetActive(false);
                searchbarSlotBottom.gameObject.SetActive(false);
            }

            nullPointerEventData = new PointerEventData(null);
        }
Ejemplo n.º 2
0
        private void OnEnable()
        {
            // Only one instance of debug console is allowed
            if (instance == null)
            {
                instance       = this;
                pooledLogItems = new List <DebugLogItem>();
                commandHistory = new CircularBuffer <string>(commandHistorySize);

                canvasTR = (RectTransform)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;

                collapsedLogEntries          = new List <DebugLogEntry>(128);
                collapsedLogEntriesMap       = new Dictionary <DebugLogEntry, int>(128);
                uncollapsedLogEntriesIndices = new DebugLogIndexList();
                indicesOfListEntriesToShow   = new DebugLogIndexList();

                recycledListView.Initialize(this, collapsedLogEntries, indicesOfListEntriesToShow, logItemPrefab.Transform.sizeDelta.y);
                recycledListView.UpdateItemsInTheList(true);

                nullPointerEventData = new PointerEventData(null);

                // 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 !UNITY_EDITOR && UNITY_ANDROID
                if (logcatListener == null)
                {
                    logcatListener = new DebugLogLogcatListener();
                }

                logcatListener.Start(logcatArguments);
#endif
            }

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

            if (minimumHeight < 200f)
            {
                minimumHeight = 200f;
            }

            DebugLogConsole.AddCommandInstance("save_logs", "Saves logs to a file", "SaveLogsToFile", this);

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