private static void Testing_Invoke(string klass, string method, params object[] prms)
 {
     try
     {
         AppDomain  currentDomain = AppDomain.CurrentDomain;
         Assembly[] assemblies    = currentDomain.GetAssemblies();
         for (int i = 0; i < assemblies.Length; i++)
         {
             Assembly assembly = assemblies[i];
             if (assembly.GetName().Name != "UnityEditor" && assembly.GetName().Name != "UnityEngine")
             {
                 Type[] typesFromAssembly = AssemblyHelper.GetTypesFromAssembly(assembly);
                 for (int j = 0; j < typesFromAssembly.Length; j++)
                 {
                     Type type = typesFromAssembly[j];
                     if (type.Name == klass)
                     {
                         type.InvokeMember(method, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, prms);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         if (GUIUtility.ShouldRethrowException(ex))
         {
             throw;
         }
         ASEditorBackend.Testing_Invoke(AssetServer.GetString("s_ExceptionHandlerClass"), AssetServer.GetString("s_ExceptionHandlerFunction"), new object[]
         {
             ex
         });
     }
 }
 private static void Testing_Invoke(string klass, string method, params object[] prms)
 {
     try
     {
         AppDomain currentDomain = AppDomain.CurrentDomain;
         foreach (Assembly assembly in currentDomain.GetAssemblies())
         {
             if ((assembly.GetName().Name != "UnityEditor") && (assembly.GetName().Name != "UnityEngine"))
             {
                 foreach (System.Type type in AssemblyHelper.GetTypesFromAssembly(assembly))
                 {
                     if (type.Name == klass)
                     {
                         type.InvokeMember(method, BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static, null, null, prms);
                     }
                 }
             }
         }
     }
     catch (Exception exception)
     {
         if (GUIUtility.ShouldRethrowException(exception))
         {
             throw;
         }
         object[] objArray1 = new object[] { exception };
         Testing_Invoke(AssetServer.GetString("s_ExceptionHandlerClass"), AssetServer.GetString("s_ExceptionHandlerFunction"), objArray1);
     }
 }
 private static bool EndContainerGUIFromException(Exception exception)
 {
     if (UIElementsUtility.s_ContainerStack.Count > 0)
     {
         GUIUtility.EndContainer();
         UIElementsUtility.s_ContainerStack.Pop();
     }
     return(GUIUtility.ShouldRethrowException(exception));
 }
 private static bool EndContainerGUIFromException(Exception exception)
 {
     foreach (var uiElementsUtility in s_Utilities)
     {
         if (uiElementsUtility.EndContainerGUIFromException(exception))
         {
             return(true);
         }
     }
     return(GUIUtility.ShouldRethrowException(exception));
 }
Esempio n. 5
0
        private static bool EndContainerGUIFromException(Exception exception)
        {
            // only End if we have a current container
            if (s_ContainerStack.Count > 0)
            {
                GUIUtility.EndContainer();
                s_ContainerStack.Pop();
            }

            return(GUIUtility.ShouldRethrowException(exception));
        }
Esempio n. 6
0
        private static bool EndContainerGUIFromException(Exception exception)
        {
            bool result;

            foreach (IUIElementsUtility current in UIEventRegistration.s_Utilities)
            {
                bool flag = current.EndContainerGUIFromException(exception);
                if (flag)
                {
                    result = true;
                    return(result);
                }
            }
            result = GUIUtility.ShouldRethrowException(exception);
            return(result);
        }
        private VisualElement CreateIMGUIInspectorFromEditor(SerializedObject serializedObject, Editor editor,
                                                             bool reuseIMGUIContainer)
        {
            if ((mode & (Mode.IMGUICustom | Mode.IMGUIDefault)) == 0)
            {
                return(null);
            }

            if ((mode & Mode.IMGUICustom) > 0 && (mode & Mode.IMGUIDefault) == 0 && editor is GenericInspector)
            {
                return(null);
            }

            if ((mode & Mode.IMGUICustom) == 0 && (mode & Mode.IMGUIDefault) > 0 && !(editor is GenericInspector))
            {
                editor           = ScriptableObject.CreateInstance <GenericInspector>();
                editor.hideFlags = HideFlags.HideAndDontSave;
                editor.InternalSetTargets(new[] { serializedObject.targetObject });
            }

            if (editor is GenericInspector)
            {
                AddToClassList(iMGUIDefaultVariantUssClassName);
                if ((mode & Mode.DebugMod) > 0)
                {
                    AddToClassList(debugVariantUssClassName);
                    editor.inspectorMode = InspectorMode.Debug;
                }
                else if ((mode & Mode.DebugInternalMod) > 0)
                {
                    AddToClassList(debugInternalVariantUssClassName);
                    editor.inspectorMode = InspectorMode.DebugInternal;
                }
            }
            else
            {
                AddToClassList(iMGUICustomVariantUssClassName);
            }

            IMGUIContainer inspector;

            // Reusing the existing IMGUIContainer allows us to re-use the existing gui state, when we are drawing the same inspector this will let us keep the same control ids
            if (reuseIMGUIContainer && m_IMGUIContainer != null)
            {
                inspector = m_IMGUIContainer;
            }
            else
            {
                inspector = new IMGUIContainer();
            }

            m_IgnoreOnInspectorGUIErrors = false;
            inspector.onGUIHandler       = () =>
            {
                // It's possible to run 2-3 frames after the tracker of this inspector window has
                // been recreated, and with it the Editor and its SerializedObject. One example of
                // when this happens is when the Preview window is detached from a *second* instance
                // of an InspectorWindow and re-attached.
                //
                // This is only a problem for the *second* (or third, forth, etc) instance of
                // the InspectorWindow because only the first instance can use the
                // ActiveEditorTracker.sharedTracker in InspectorWindow.CreateTracker(). The
                // other instances have to create a new tracker...each time.
                //
                // Not an ideal solution, but basically we temporarily hold the printing to console
                // for errors for which GUIUtility.ShouldRethrowException(e) returns false.
                // The errors that may occur during this brief "bad state" are SerializedProperty
                // errors. If the custom Editor created and remembered references to some
                // SerializedProperties during its OnEnable(), those references will be invalid
                // when the tracker is refreshed, until this GUIHandler is reassigned. This fix
                // just ignores those errors.
                //
                // We don't simply early return here because that can break some tests that
                // rely heavily on yields and timing of UI redraws. Yes..
                //
                // case 1119612
                if (editor.m_SerializedObject == null)
                {
                    editor.Repaint();
                    m_IgnoreOnInspectorGUIErrors = true;
                }

                if ((editor.target == null && !GenericInspector.ObjectIsMonoBehaviourOrScriptableObject(editor.target)) ||
                    !editor.serializedObject.isValid)
                {
                    return;
                }

                EditorGUIUtility.ResetGUIState();
                using (new EditorGUI.DisabledScope(!editor.IsEnabled()))
                {
                    var genericEditor = editor as GenericInspector;
                    if (genericEditor != null)
                    {
                        switch (mode)
                        {
                        case Mode.Normal:
                            genericEditor.inspectorMode = InspectorMode.Normal;
                            break;

                        case Mode.Default:
                            genericEditor.inspectorMode = InspectorMode.Debug;
                            break;

                        case Mode.Custom:
                            genericEditor.inspectorMode = InspectorMode.DebugInternal;
                            break;

                        case Mode.IMGUI:
                            break;
                        }
                    }

                    //set the current PropertyHandlerCache to the current editor
                    ScriptAttributeUtility.propertyHandlerCache = editor.propertyHandlerCache;

                    var originalHierarchyMode = EditorGUIUtility.hierarchyMode;
                    EditorGUIUtility.hierarchyMode = true;

                    var originalWideMode = SetWideModeForWidth(inspector);

                    GUIStyle editorWrapper = (editor.UseDefaultMargins()
                        ? EditorStyles.inspectorDefaultMargins
                        : GUIStyle.none);
                    try
                    {
                        GUI.changed = false;

                        using (new InspectorWindowUtils.LayoutGroupChecker())
                        {
                            EditorGUILayout.BeginVertical(editorWrapper);
                            {
                                // we have no guarantees regarding what happens in the try/catch block below,
                                // so we need to save state here and restore it afterwards,
                                // the natural thing to do would be using SavedGUIState,
                                // but it implicitly resets keyboards bindings and it breaks functionality.
                                // We have identified issues with layout so we just save that for the time being.
                                var layoutCache = new GUILayoutUtility.LayoutCache(GUILayoutUtility.current);
                                try
                                {
                                    var rebuildOptimizedGUIBlocks = GetRebuildOptimizedGUIBlocks(editor.target);
                                    rebuildOptimizedGUIBlocks |= editor.isInspectorDirty;
                                    float height;
                                    if (editor.GetOptimizedGUIBlock(rebuildOptimizedGUIBlocks, visible, out height))
                                    {
                                        var contentRect = GUILayoutUtility.GetRect(0, visible ? height : 0);

                                        // Layout events are ignored in the optimized code path
                                        // The exception is when we are drawing a GenericInspector, they always use the optimized path and must therefore run at least one layout calculation in it
                                        if (Event.current.type == EventType.Layout && !(editor is GenericInspector))
                                        {
                                            return;
                                        }

                                        InspectorWindowUtils.DrawAddedComponentBackground(contentRect, editor.targets);

                                        // Draw content
                                        if (visible)
                                        {
                                            GUI.changed = false;
                                            editor.OnOptimizedInspectorGUI(contentRect);
                                        }
                                    }
                                    else
                                    {
                                        InspectorWindowUtils.DrawAddedComponentBackground(contentRect, editor.targets);
                                        editor.OnInspectorGUI();
                                    }
                                }
                                catch (Exception e)
                                {
                                    if (GUIUtility.ShouldRethrowException(e))
                                    {
                                        throw;
                                    }

                                    if (!m_IgnoreOnInspectorGUIErrors)
                                    {
                                        Debug.LogException(e);
                                    }
                                }
                                finally
                                {
                                    GUILayoutUtility.current = layoutCache;
                                }
                            }
                            EditorGUILayout.EndVertical();
                        }
                    }
                    finally
                    {
                        if (GUI.changed)
                        {
                            // This forces a relayout of all imguicontainers in this inspector window.
                            // fixes part of case 1148706
                            var element = inspector.GetFirstAncestorOfType <EditorElement>();
                            if (element != null)
                            {
                                EditorElement.InvalidateIMGUILayouts(element.parent);
                            }
                        }
                        EditorGUIUtility.wideMode      = originalWideMode;
                        EditorGUIUtility.hierarchyMode = originalHierarchyMode;
                    }
                }
            };

            inspector.style.overflow = Overflow.Visible;
            m_IMGUIContainer         = inspector;

            if (!(editor is GenericInspector))
            {
                inspector.AddToClassList(customInspectorUssClassName);
            }

            inspector.AddToClassList(iMGUIContainerUssClassName);

            AddToClassList(iMGUIInspectorVariantUssClassName);

            return(inspector);
        }