Esempio n. 1
0
        public void UpdateOdinEditors()
        {
            CustomEditorUtility.ResetCustomEditors();

            if (this.enableOdinInInspector)
            {
                foreach (var typeDrawerPair in InspectorTypeDrawingConfigDrawer.GetEditors())
                {
                    var drawnType  = TwoWaySerializationBinder.Default.BindToType(typeDrawerPair.DrawnTypeName);
                    var editorType = TwoWaySerializationBinder.Default.BindToType(typeDrawerPair.EditorTypeName);

                    if (drawnType == null || editorType == null)
                    {
                        continue;
                    }

                    CustomEditorUtility.SetCustomEditor(drawnType, editorType, isFallbackEditor: false, isEditorForChildClasses: false);
                }
            }

            Type inspectorWindowType     = typeof(EditorWindow).Assembly.GetType("UnityEditor.InspectorWindow");
            Type activeEditorTrackerType = typeof(EditorWindow).Assembly.GetType("UnityEditor.ActiveEditorTracker");

            if (inspectorWindowType != null && activeEditorTrackerType != null)
            {
                var createTrackerMethod = inspectorWindowType.GetMethod("CreateTracker", Flags.InstanceAnyVisibility);
                var trackerField        = inspectorWindowType.GetField("m_Tracker", Flags.InstanceAnyVisibility);
                var forceRebuild        = activeEditorTrackerType.GetMethod("ForceRebuild", Flags.InstanceAnyVisibility);

                if (createTrackerMethod != null && trackerField != null && forceRebuild != null)
                {
                    var windows = Resources.FindObjectsOfTypeAll(inspectorWindowType);

                    foreach (var window in windows)
                    {
                        createTrackerMethod.Invoke(window, null);
                        object tracker = trackerField.GetValue(window);
                        forceRebuild.Invoke(tracker, null);
                    }
                }
            }

            hasUpdatedEditorsOnce = true;
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the default editor that this type would have, if no custom editor was set for this type in particular. This is calculated using the value of <see cref="InspectorConfig.DefaultEditorBehaviour"/>.
        /// </summary>
        /// <param name="drawnType">The drawn type to get the default editor for.</param>
        /// <returns>The editor that would draw this type by default, or null, if there is no default ODIN-defined editor for the drawn type.</returns>
        /// <exception cref="System.ArgumentNullException">drawnType is null</exception>
        public static Type GetDefaultEditorType(Type drawnType)
        {
            if (drawnType == null)
            {
                throw new ArgumentNullException("drawnType");
            }

            if (!InspectorTypeDrawingConfigDrawer.OdinCanCreateEditorFor(drawnType))
            {
                return(null);
            }

            Type editorType;

            if (!HardCodedDefaultEditors.TryGetValue(drawnType, out editorType))
            {
                if (InspectorConfig.Instance.DefaultEditorBehaviour == InspectorDefaultEditors.None)
                {
                    return(null);
                }

                var assemblyTypeFlag = AssemblyUtilities.GetAssemblyTypeFlag(drawnType.Assembly);

                bool useSirenixInspector;

                switch (assemblyTypeFlag)
                {
                case AssemblyTypeFlags.UserTypes:
                case AssemblyTypeFlags.UserEditorTypes:
                    useSirenixInspector = (InspectorConfig.Instance.DefaultEditorBehaviour & InspectorDefaultEditors.UserTypes) == InspectorDefaultEditors.UserTypes;
                    break;

                case AssemblyTypeFlags.PluginTypes:
                case AssemblyTypeFlags.PluginEditorTypes:
                    useSirenixInspector = (InspectorConfig.Instance.DefaultEditorBehaviour & InspectorDefaultEditors.PluginTypes) == InspectorDefaultEditors.PluginTypes;
                    break;

                case AssemblyTypeFlags.UnityTypes:
                case AssemblyTypeFlags.UnityEditorTypes:
                    useSirenixInspector = (InspectorConfig.Instance.DefaultEditorBehaviour & InspectorDefaultEditors.UnityTypes) == InspectorDefaultEditors.UnityTypes;
                    break;

                case AssemblyTypeFlags.OtherTypes:
                // If we hit one of the below flags, or the default case, something actually went wrong.
                // We don't care, though - just shove it into the other types category.
                case AssemblyTypeFlags.All:
                case AssemblyTypeFlags.GameTypes:
                case AssemblyTypeFlags.EditorTypes:
                case AssemblyTypeFlags.CustomTypes:
                case AssemblyTypeFlags.None:
                default:
                    useSirenixInspector = (InspectorConfig.Instance.DefaultEditorBehaviour & InspectorDefaultEditors.OtherTypes) == InspectorDefaultEditors.OtherTypes;
                    break;
                }

                if (useSirenixInspector)
                {
                    editorType = OdinEditorType;
                }
            }

            return(editorType);
        }