Exemple #1
0
        // A debug entry is received
        private void ReceivedLog(string logString, string stackTrace, LogType logType)
        {
#if UNITY_EDITOR
            if (isQuittingApplication)
            {
                return;
            }
#endif

            // Truncate the log if it is longer than maxLogLength
            int logLength = logString.Length;
            if (stackTrace == null)
            {
                if (logLength > maxLogLength)
                {
                    logString = logString.Substring(0, maxLogLength - 11) + "<truncated>";
                }
            }
            else
            {
                logLength += stackTrace.Length;
                if (logLength > maxLogLength)
                {
                    // Decide which log component(s) to truncate
                    int halfMaxLogLength = maxLogLength / 2;
                    if (logString.Length >= halfMaxLogLength)
                    {
                        if (stackTrace.Length >= halfMaxLogLength)
                        {
                            // Truncate both logString and stackTrace
                            logString = logString.Substring(0, halfMaxLogLength - 11) + "<truncated>";

                            // If stackTrace doesn't end with a blank line, its last line won't be visible in the console for some reason
                            stackTrace = stackTrace.Substring(0, halfMaxLogLength - 12) + "<truncated>\n";
                        }
                        else
                        {
                            // Truncate logString
                            logString = logString.Substring(0, maxLogLength - stackTrace.Length - 11) + "<truncated>";
                        }
                    }
                    else
                    {
                        // Truncate stackTrace
                        stackTrace = stackTrace.Substring(0, maxLogLength - logString.Length - 12) + "<truncated>\n";
                    }
                }
            }

            QueuedDebugLogEntry queuedLogEntry = new QueuedDebugLogEntry(logString, stackTrace, logType);

            lock ( logEntriesLock )
            {
                queuedLogEntries.Add(queuedLogEntry);
            }
        }
Exemple #2
0
        // A debug entry is received
        private void ReceivedLog(string logString, string stackTrace, LogType logType)
        {
#if UNITY_EDITOR
            if (isQuittingApplication)
            {
                return;
            }
#endif

            QueuedDebugLogEntry queuedLogEntry = new QueuedDebugLogEntry(logString, stackTrace, logType);

            lock ( logEntriesLock )
            {
                queuedLogEntries.Add(queuedLogEntry);
            }
        }
Exemple #3
0
        // If snapToBottom is enabled, force the scrollbar to the bottom
        private void LateUpdate()
        {
            int queuedLogCount = queuedLogs.Count;

            if (queuedLogCount > 0)
            {
                for (int i = 0; i < queuedLogCount; i++)
                {
                    QueuedDebugLogEntry logEntry = queuedLogs[i];
                    ReceivedLog(logEntry.logString, logEntry.stackTrace, logEntry.logType);
                }

                queuedLogs.Clear();
            }

            if (screenDimensionsChanged)
            {
                // Update the recycled list view
                if (isLogWindowVisible)
                {
                    recycledListView.OnViewportDimensionsChanged();
                }
                else
                {
                    popupManager.OnViewportDimensionsChanged();
                }

                screenDimensionsChanged = false;
            }

            if (snapToBottom)
            {
                logItemsScrollRect.verticalNormalizedPosition = 0f;

                if (snapToBottomButton.activeSelf)
                {
                    snapToBottomButton.SetActive(false);
                }
            }
            else
            {
                float scrollPos = logItemsScrollRect.verticalNormalizedPosition;
                if (snapToBottomButton.activeSelf != (scrollPos > 1E-6f && scrollPos < 0.9999f))
                {
                    snapToBottomButton.SetActive(!snapToBottomButton.activeSelf);
                }
            }

            if (toggleWithKey)
            {
                if (Input.GetKeyDown(toggleKey))
                {
                    if (isLogWindowVisible)
                    {
                        ShowPopup();
                    }
                    else
                    {
                        ShowLogWindow();
                    }
                }
            }

            if (isLogWindowVisible && commandInputField.isFocused)
            {
                if (Input.GetKeyDown(KeyCode.UpArrow))
                {
                    if (commandHistoryIndex == -1)
                    {
                        commandHistoryIndex = commandHistory.Count - 1;
                    }
                    else if (--commandHistoryIndex < 0)
                    {
                        commandHistoryIndex = 0;
                    }

                    if (commandHistoryIndex >= 0 && commandHistoryIndex < commandHistory.Count)
                    {
                        commandInputField.text          = commandHistory[commandHistoryIndex];
                        commandInputField.caretPosition = commandInputField.text.Length;
                    }
                }
                else if (Input.GetKeyDown(KeyCode.DownArrow))
                {
                    if (commandHistoryIndex == -1)
                    {
                        commandHistoryIndex = commandHistory.Count - 1;
                    }
                    else if (++commandHistoryIndex >= commandHistory.Count)
                    {
                        commandHistoryIndex = commandHistory.Count - 1;
                    }

                    if (commandHistoryIndex >= 0 && commandHistoryIndex < commandHistory.Count)
                    {
                        commandInputField.text = commandHistory[commandHistoryIndex];
                    }
                }
            }

#if !UNITY_EDITOR && UNITY_ANDROID
            if (logcatListener != null)
            {
                string log;
                while ((log = logcatListener.GetLog()) != null)
                {
                    ReceivedLog("LOGCAT: " + log, string.Empty, LogType.Log);
                }
            }
#endif
        }
Exemple #4
0
        // Present the log entry in the console
        private void ProcessLog(QueuedDebugLogEntry queuedLogEntry)
        {
            LogType       logType = queuedLogEntry.logType;
            DebugLogEntry logEntry;

            if (pooledLogEntries.Count > 0)
            {
                logEntry = pooledLogEntries[pooledLogEntries.Count - 1];
                pooledLogEntries.RemoveAt(pooledLogEntries.Count - 1);
            }
            else
            {
                logEntry = new DebugLogEntry();
            }

            logEntry.Initialize(queuedLogEntry.logString, queuedLogEntry.stackTrace, null);

            // Check if this entry is a duplicate (i.e. has been received before)
            int  logEntryIndex;
            bool isEntryInCollapsedEntryList = collapsedLogEntriesMap.TryGetValue(logEntry, out logEntryIndex);

            if (!isEntryInCollapsedEntryList)
            {
                // It is not a duplicate,
                // add it to the list of unique debug entries
                logEntry.logTypeSpriteRepresentation = logSpriteRepresentations[logType];

                logEntryIndex = collapsedLogEntries.Count;
                collapsedLogEntries.Add(logEntry);
                collapsedLogEntriesMap[logEntry] = logEntryIndex;
            }
            else
            {
                // It is a duplicate, pool the duplicate log entry and
                // increment the original debug item's collapsed count
                pooledLogEntries.Add(logEntry);

                logEntry = collapsedLogEntries[logEntryIndex];
                logEntry.count++;
            }

            // Add the index of the unique debug entry to the list
            // that stores the order the debug entries are received
            uncollapsedLogEntriesIndices.Add(logEntryIndex);

            // If this debug entry matches the current filters,
            // add it to the list of debug entries to show
            Sprite logTypeSpriteRepresentation = logEntry.logTypeSpriteRepresentation;

            if (isCollapseOn && isEntryInCollapsedEntryList)
            {
                if (isLogWindowVisible)
                {
                    recycledListView.OnCollapsedLogEntryAtIndexUpdated(logEntryIndex);
                }
            }
            else if (logFilter == DebugLogFilter.All ||
                     (logTypeSpriteRepresentation == infoLog && ((logFilter & DebugLogFilter.Info) == DebugLogFilter.Info)) ||
                     (logTypeSpriteRepresentation == warningLog && ((logFilter & DebugLogFilter.Warning) == DebugLogFilter.Warning)) ||
                     (logTypeSpriteRepresentation == errorLog && ((logFilter & DebugLogFilter.Error) == DebugLogFilter.Error)))
            {
                indicesOfListEntriesToShow.Add(logEntryIndex);

                if (isLogWindowVisible)
                {
                    recycledListView.OnLogEntriesUpdated(false);
                }
            }

            if (logType == LogType.Log)
            {
                infoEntryCount++;
                infoEntryCountText.text = infoEntryCount.ToString();

                // If debug popup is visible, notify it of the new debug entry
                if (!isLogWindowVisible)
                {
                    popupManager.NewInfoLogArrived();
                }
            }
            else if (logType == LogType.Warning)
            {
                warningEntryCount++;
                warningEntryCountText.text = warningEntryCount.ToString();

                // If debug popup is visible, notify it of the new debug entry
                if (!isLogWindowVisible)
                {
                    popupManager.NewWarningLogArrived();
                }
            }
            else
            {
                errorEntryCount++;
                errorEntryCountText.text = errorEntryCount.ToString();

                // If debug popup is visible, notify it of the new debug entry
                if (!isLogWindowVisible)
                {
                    popupManager.NewErrorLogArrived();
                }
            }
        }