コード例 #1
0
        public static CustomDialog CreateExceptionDialog(string title, string message, VCException e)
        {
            bool         stackTraceToggle      = false;
            bool         innerStackTraceToggle = false;
            bool         detailsToggle         = false;
            bool         isCritical            = e is VCCriticalException;
            Vector2      scrollPos             = Vector2.zero;
            CustomDialog dialog = CustomDialog.Create(title);

            dialog
            .CenterOnScreen()
            .SetBodyGUI(() =>
            {
                if (e != null)
                {
                    scrollPos = GUILayout.BeginScrollView(scrollPos);
                    if (!string.IsNullOrEmpty(message))
                    {
                        EditorGUILayout.HelpBox(message, isCritical ? MessageType.Error : MessageType.Warning);
                    }

                    if (!string.IsNullOrEmpty(e.ErrorDetails))
                    {
                        detailsToggle = GUILayout.Toggle(detailsToggle, "Details", EditorStyles.foldout);
                        if (detailsToggle)
                        {
                            using (GUILayoutHelper.VerticalIdented(14))
                            {
                                GUILayout.BeginVertical(GUI.skin.box);
                                GUILayout.TextField(e.ErrorDetails);
                                GUILayout.EndVertical();
                            }
                        }
                    }

                    if (!string.IsNullOrEmpty(e.StackTrace))
                    {
                        stackTraceToggle = GUILayout.Toggle(stackTraceToggle, "Stacktrace", EditorStyles.foldout);
                        if (stackTraceToggle)
                        {
                            using (GUILayoutHelper.VerticalIdented(14))
                            {
                                GUILayout.BeginVertical(GUI.skin.box);
                                GUILayout.TextField(e.StackTrace);
                                GUILayout.EndVertical();
                            }
                        }
                    }

                    if (e.InnerException != null)
                    {
                        if (!string.IsNullOrEmpty(e.InnerException.StackTrace))
                        {
                            innerStackTraceToggle = GUILayout.Toggle(innerStackTraceToggle, "Inner Stacktrace", EditorStyles.foldout);
                            if (innerStackTraceToggle)
                            {
                                using (GUILayoutHelper.VerticalIdented(14))
                                {
                                    GUILayout.BeginVertical(GUI.skin.box);
                                    GUILayout.TextField(e.InnerException.StackTrace);
                                    GUILayout.EndVertical();
                                }
                            }
                        }
                    }
                    GUILayout.FlexibleSpace();
                    GUILayout.EndScrollView();
                }
            })
            .AddButton("OK", () => dialog.Close(), GUILayout.Width(60f))
            .AddButton("Copy To Clipboard", () =>
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("Title: {0}\r\n\r\n", title);
                if (!string.IsNullOrEmpty(message))
                {
                    sb.AppendFormat("Message: {0}\r\n", message);
                }
                if (!string.IsNullOrEmpty(e.ErrorDetails))
                {
                    sb.AppendFormat("\r\nDetails:\r\n{0}\r\n", e.ErrorDetails);
                }
                if (!string.IsNullOrEmpty(e.StackTrace))
                {
                    sb.AppendFormat("\r\nStacktrace:\r\n{0}\r\n", e.StackTrace);
                }
                if (e.InnerException != null && !string.IsNullOrEmpty(e.StackTrace))
                {
                    sb.AppendFormat("\r\nInner Stacktrace:\r\n{0}\r\n", e.InnerException.StackTrace);
                }

                EditorGUIUtility.systemCopyBuffer = sb.ToString();
            });

            return(dialog);
        }