コード例 #1
0
        private void DrawStackBox(LogStackData stack, int index, ref Vector2 drawPos)
        {
            if (string.IsNullOrEmpty(stack.sourceContent))
            {
                stack.sourceContent = UnityDebugViewerEditorUtility.GetSourceContent(stack.filePath, stack.lineNumber);
            }

            var stackBoxGUIContent = new GUIContent(string.Format("\n{0}\n{1}", stack.fullStackMessage, stack.sourceContent));

            if (this.selectedStackIndex == index)
            {
                stackBoxStyle = UnityDebugViewerWindowUtility.activeControlID == this.stackBoxControlID ? stackBoxStyle = UnityDebugViewerWindowStyleUtility.selectedStackBoxStyle : UnityDebugViewerWindowStyleUtility.inactiveStackBoxStyle;
            }
            else
            {
                stackBoxStyle = index % 2 == 0 ? UnityDebugViewerWindowStyleUtility.oddStackBoxStyle : UnityDebugViewerWindowStyleUtility.evenStackBoxStyle;
            }

            var height       = stackBoxStyle.CalcHeight(stackBoxGUIContent, this.lowerPanelRect.width);
            var stackBoxRect = new Rect(drawPos.x, drawPos.y, this.lowerPanelRect.width, height);

            EditorGUI.LabelField(stackBoxRect, stackBoxGUIContent, stackBoxStyle);
            EditorGUILayout.GetControlRect(false, height);

            this.stackRectList[index] = stackBoxRect;
            drawPos.y += height;

            if (stackBoxRect.Contains(Event.current.mousePosition))
            {
                EventType eventType = Event.current.GetTypeForControl(this.stackBoxControlID);
#if UNITY_5 || UNITY_5_3_OR_NEWER
                if (eventType == EventType.MouseDown)
#else
                if (eventType == EventType.mouseDown)
#endif
                {
                    if (Event.current.button == 0 && Event.current.clickCount == 2)
                    {
                        UnityDebugViewerWindowUtility.JumpToSource(stack);
                    }

                    this.selectedStackIndex = index;

                    UnityDebugViewerWindowUtility.activeControlID = this.stackBoxControlID;
                    Event.current.Use();
                }
#if UNITY_5 || UNITY_5_3_OR_NEWER
                if (eventType == EventType.MouseUp && Event.current.button == 1)
#else
                if (eventType == EventType.mouseUp && Event.current.button == 1)
#endif
                {
                    ShowCopyMenu(stack.fullStackMessage);

                    UnityDebugViewerWindowUtility.activeControlID = this.stackBoxControlID;
                    Event.current.Use();
                }
            }
        }
コード例 #2
0
        public static bool JumpToSource(string filePath, int lineNumber)
        {
            var validFilePath = UnityDebugViewerEditorUtility.ConvertToSystemFilePath(filePath);

            if (File.Exists(validFilePath))
            {
                if (InternalEditorUtility.OpenFileAtLineExternal(validFilePath, lineNumber))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #3
0
        public LogStackData(Match match)
        {
            if (match == null)
            {
                SetDefaultValue();
                return;
            }

            this.sourceContent = String.Empty;

            this.className  = match.Result("${className}");
            this.methodName = match.Result("${methodName}");


            this.filePath = UnityDebugViewerEditorUtility.ConvertToSystemFilePath(match.Result("${filePath}"));
            string lineNumberStr = match.Result("${lineNumber}");
            int    lineNumber;

            this.lineNumber = int.TryParse(lineNumberStr, out lineNumber) ? lineNumber : -1;


            if (this.filePath.Equals("${filePath}") || this.lineNumber == -1)
            {
                this.fullStackMessage = string.Format("{0}:{1}", this.className, this.methodName);
            }
            else
            {
                if (this.className.Equals("${className}") || this.methodName.Equals("${methodName}"))
                {
                    if (this.className.Equals("${className}"))
                    {
                        this.className = "UnknowClass";
                    }

                    if (this.methodName.Equals("${methodName}"))
                    {
                        this.methodName = "UnknowMethod()";
                    }
                }

                if (this.methodName.Contains("(") == false)
                {
                    this.methodName += "()";
                }

                this.fullStackMessage = string.Format("{0}:{1} (at {2}:{3})", this.className, this.methodName, this.filePath, this.lineNumber);
            }
        }
コード例 #4
0
        /// <summary>
        /// 使用string注册mode,并返回对应的UnityDebugViewerEditor实例
        /// </summary>
        /// <param name="mode"></param>
        /// <param name="order"></param>
        /// <returns></returns>
        public static void RegisterMode <T>(string mode, int order = int.MaxValue) where T : UnityDebugViewerIntermediaryEditor
        {
            /// 避免重复注册同名Mode
            if (modeList.Contains(mode))
            {
                return;
            }

            int index = -1;

            for (int i = 0; i < modeOrderList.Count; i++)
            {
                if (order < modeOrderList[i])
                {
                    index = i;
                    break;
                }
            }

            if (index >= 0)
            {
                modeOrderList.Insert(index, order);
                modeList.Insert(index, mode);
            }
            else
            {
                modeOrderList.Add(order);
                modeList.Add(mode);
            }

            UnityDebugViewerIntermediaryEditor intermediaryEditor = UnityDebugViewerEditorUtility.GetScriptableObjectInstance <T>();

            if (intermediaryEditorDic.ContainsKey(mode))
            {
                intermediaryEditorDic[mode] = intermediaryEditor;
            }
            else
            {
                intermediaryEditorDic.Add(mode, intermediaryEditor);
            }
        }
コード例 #5
0
        public static string GetAdbPath()
        {
            if (!String.IsNullOrEmpty(adbPath))
            {
                return(adbPath);
            }

#if UNITY_2019_1_OR_NEWER
            ADB adb = ADB.GetInstance();
            if (abd != null)
            {
                adbPath = adb.GetADBPath();
            }
#else
            string androidSdkRoot = EditorPrefs.GetString("AndroidSdkRoot");
            if (!string.IsNullOrEmpty(androidSdkRoot))
            {
                adbPath = Path.Combine(androidSdkRoot, Path.Combine("platform-tools", "adb"));
            }
#endif

            if (string.IsNullOrEmpty(adbPath))
            {
                MonoScript ms       = MonoScript.FromScriptableObject(UnityDebugViewerADBUtility.GetADBInstance());
                string     filePath = AssetDatabase.GetAssetPath(ms);
                filePath = UnityDebugViewerEditorUtility.ConvertToSystemFilePath(filePath);

                string currentScriptDirectory = Path.GetDirectoryName(filePath);
                string parentDirectory        = Directory.GetParent(currentScriptDirectory).FullName;
                parentDirectory = Directory.GetParent(parentDirectory).FullName;

                string defaultAdbPath = UnityDebugViewerEditorUtility.ConvertToSystemFilePath(UnityDebugViewerADBUtility.DEFAULT_ADB_PATH);

                adbPath = Path.Combine(Path.Combine(parentDirectory, defaultAdbPath), "adb");
            }

            return(adbPath);
        }