Exemplo n.º 1
0
        private void DrawLogBox(LogData log, Rect logBoxRect, int index, bool isCollapsed = false)
        {
            GUIStyle iconStyle;

            switch (log.type)
            {
            case LogType.Error:
            case LogType.Exception:
            case LogType.Assert:
                iconStyle = UnityDebugViewerWindowStyleUtility.errorIconStyle;
                break;

            case LogType.Warning:
                iconStyle = UnityDebugViewerWindowStyleUtility.warningIconStyle;
                break;

            case LogType.Log:
                iconStyle = UnityDebugViewerWindowStyleUtility.infoIconStyle;
                break;

            default:
                iconStyle = null;
                break;
            }
            if (iconStyle == null)
            {
                return;
            }


            if (index == this.editorManager.activeEditor.selectedLogIndex)
            {
                logBoxStyle = UnityDebugViewerWindowUtility.activeControlID == this.logBoxControlID ? logBoxStyle = UnityDebugViewerWindowStyleUtility.selectedLogBoxStyle : UnityDebugViewerWindowStyleUtility.inactiveLogBoxStyle;
            }
            else
            {
                logBoxStyle = index % 2 == 0 ? UnityDebugViewerWindowStyleUtility.oddLogBoxtyle : UnityDebugViewerWindowStyleUtility.evenLogBoxtyle;
            }
            GUI.DrawTexture(logBoxRect, logBoxStyle.normal.background);


            string logContent       = log.GetContent(showTime);
            var    logBoxGUIContent = new GUIContent(logContent);
            var    logContentHeight = logBoxStyle.CalcHeight(logBoxGUIContent, logBoxRect.width);

            logBoxStyle.alignment = logContentHeight > logBoxHeight ? TextAnchor.UpperLeft : TextAnchor.MiddleLeft;
            EditorGUI.LabelField(logBoxRect, logBoxGUIContent, logBoxStyle);

            var logBoxMidHeight = logBoxRect.y + logBoxRect.height / 2;
            var iconSize        = iconStyle.CalcSize(GUIContent.none);
            var iconRect        = new Rect(5, logBoxMidHeight - iconSize.y / 2, iconSize.x, iconSize.y);

            EditorGUI.LabelField(iconRect, GUIContent.none, iconStyle);

            if (collapse)
            {
                /// make sure the number label display in a fixed relative position of the window
                int        num             = this.editorManager.activeEditor.GetLogNum(log);
                GUIContent labelGUIContent = new GUIContent(num.ToString());
                var        labelSize       = UnityDebugViewerWindowStyleUtility.collapsedNumLabelStyle.CalcSize(labelGUIContent);
                Rect       labelRect       = new Rect(position.width - labelSize.x - 20, logBoxRect.y + logBoxRect.height / 2 - labelSize.y / 2, labelSize.x, labelSize.y);

                EditorGUI.LabelField(labelRect, labelGUIContent, UnityDebugViewerWindowStyleUtility.collapsedNumLabelStyle);
            }

            EventType eventType = Event.current.GetTypeForControl(this.logBoxControlID);

#if UNITY_5 || UNITY_5_3_OR_NEWER
            if (eventType == EventType.MouseDown)
#else
            if (eventType == EventType.mouseDown)
#endif
            {
                /// process event
                if (logBoxRect.Contains(Event.current.mousePosition))
                {
                    this.editorManager.activeEditor.selectedLogIndex = index;

                    if (Event.current.button == 0 && Event.current.clickCount == 2)
                    {
                        UnityDebugViewerWindowUtility.JumpToSource(log);
                    }

                    UnityDebugViewerWindowUtility.activeControlID = this.logBoxControlID;
                    Event.current.Use();
                }

                if (Event.current.button == 2)
                {
                    MoveToSpecificLogBox(this.editorManager.activeEditor.selectedLogIndex);

                    Event.current.Use();
                }
            }
#if UNITY_5 || UNITY_5_3_OR_NEWER
            else if (eventType == EventType.MouseUp)
#else
            else if (eventType == EventType.mouseUp)
#endif
            {
                if (logBoxRect.Contains(Event.current.mousePosition) && Event.current.button == 1)
                {
                    ShowCopyMenu(logContent);

                    UnityDebugViewerWindowUtility.activeControlID = this.logBoxControlID;
                    Event.current.Use();
                }
            }
#if UNITY_5 || UNITY_5_3_OR_NEWER
            else if (eventType == EventType.KeyUp)
#else
            else if (eventType == EventType.keyUp)
#endif
            {
                if (this.logBoxControlID == UnityDebugViewerWindowUtility.activeControlID)
                {
                    bool changeSelectedLog = false;
                    int  selectedIndex     = this.editorManager.activeEditor.selectedLogIndex;
                    if (Event.current.keyCode == KeyCode.UpArrow)
                    {
                        selectedIndex--;
                        changeSelectedLog = true;
                    }
                    else if (Event.current.keyCode == KeyCode.DownArrow)
                    {
                        selectedIndex++;
                        changeSelectedLog = true;
                    }

                    if (changeSelectedLog)
                    {
                        this.editorManager.activeEditor.selectedLogIndex = Mathf.Clamp(selectedIndex, 0, this.logList.Count - 1);

                        MoveToSpecificLogBox(this.editorManager.activeEditor.selectedLogIndex);

                        Event.current.Use();
                    }
                }
            }
        }
        public bool ShouldDisplay(LogData log)
        {
            bool canDisplayInType;

            switch (log.type)
            {
            case LogType.Log:
                canDisplayInType = this.showLog;
                break;

            case LogType.Warning:
                canDisplayInType = this.showWarning;
                break;

            case LogType.Error:
            case LogType.Exception:
            case LogType.Assert:
                canDisplayInType = this.showError;
                break;

            default:
                canDisplayInType = false;
                break;
            }

            if (canDisplayInType)
            {
                if (string.IsNullOrEmpty(searchText))
                {
                    return(true);
                }
                else
                {
                    string logContent = log.GetContent(showTime);
                    string input      = logContent.ToLower();
                    string pattern    = searchText.ToLower();
                    if (searchWithRegex)
                    {
                        try
                        {
                            if (Regex.IsMatch(logContent, searchText))
                            {
                                return(true);
                            }
                            else
                            {
                                if (Regex.IsMatch(input, pattern))
                                {
                                    return(true);
                                }
                                else
                                {
                                    return(input.Contains(pattern));
                                }
                            }
                        }
                        catch
                        {
                            /// 正则表达式匹配出现错误,则使用普通匹配
                            return(input.Contains(pattern));
                        }
                    }
                    else
                    {
                        return(input.Contains(pattern));
                    }
                }
            }
            else
            {
                return(false);
            }
        }
        public static void AddLog(string info, string extraMessage, List <StackFrame> stackFrameList, LogType type, string modeName)
        {
            var logData = new LogData(info, extraMessage, stackFrameList, type);

            AddLog(logData, modeName);
        }
 public static void AddLog(LogData data, string modeName)
 {
     UnityDebugViewerEditorManager.GetEditor(modeName).AddLog(data);
 }
        public static void AddLog(string info, string stack, LogType type, string modeName)
        {
            var logData = new LogData(info, stack, type);

            AddLog(logData, modeName);
        }