Exemple #1
0
        /// <summary>
        /// Draws all properties in a given property tree; must be wrapped by a <see cref="BeginDrawPropertyTree(PropertyTree, bool)"/> and <see cref="EndDrawPropertyTree(PropertyTree)"/>.
        /// </summary>
        /// <param name="tree">The tree to be drawn.</param>
        public static void DrawPropertiesInTree(PropertyTree tree)
        {
            foreach (var property in tree.EnumerateTree(false))
            {
                try
                {
                    property.Draw(property.Label);
                }
                catch (Exception ex)
                {
                    if (ex is ExitGUIException || ex.InnerException is ExitGUIException)
                    {
                        throw ex;
                    }
                    else
                    {
                        var msg =
                            "This error occurred while being drawn by Odin. \n" +
                            "Odin Property Path: " + property.Path + "\n" +
                            "Odin Drawer Chain: " + string.Join(", ", property.GetActiveDrawerChain().BakedDrawerArray.Select(n => n.GetType().GetNiceName()).ToArray()) + ".";

                        Debug.LogException(new OdinPropertyException(msg, ex));
                    }
                }
            }
        }
        private void DrawTree()
        {
            if (this.targetType == null)
            {
                this.tree = null;
                return;
            }

            if (Event.current.type == EventType.Layout)
            {
                this.currMemberTypes     = this.memberTypes;
                this.currAccessModifiers = this.accessModifiers;
            }

            if (this.tree == null || this.tree.TargetType != this.targetType)
            {
                if (this.targetType.IsGenericType && !this.targetType.IsFullyConstructedGenericType())
                {
                    SirenixEditorGUI.ErrorMessageBox("Cannot statically inspect generic type definitions");
                    return;
                }

                this.tree = PropertyTree.CreateStatic(this.targetType);
            }

            var allowObsoleteMembers        = (this.currMemberTypes & MemberTypeFlags.Obsolete) == MemberTypeFlags.Obsolete;
            var allowObsoleteMembersContext = this.tree.SecretRootProperty.Context.GetGlobal("ALLOW_OBSOLETE_STATIC_MEMBERS", false);

            if (allowObsoleteMembersContext.Value != allowObsoleteMembers)
            {
                allowObsoleteMembersContext.Value = allowObsoleteMembers;
                this.tree.SecretRootProperty.RefreshSetup();
            }

            InspectorUtilities.BeginDrawPropertyTree(tree, false);

            foreach (var prop in tree.EnumerateTree(false))
            {
                if (this.DrawProperty(prop))
                {
                    if (prop.Info.PropertyType != PropertyType.Group && prop.Info.GetMemberInfo() != null && prop.Info.GetMemberInfo().DeclaringType != this.targetType)
                    {
                        prop.Draw(new GUIContent(prop.Info.GetMemberInfo().DeclaringType.GetNiceName() + " -> " + prop.NiceName));
                    }
                    else
                    {
                        prop.Draw();
                    }
                }
                else
                {
                    prop.Update();
                }
            }

            InspectorUtilities.EndDrawPropertyTree(tree);
        }
Exemple #3
0
 /// <summary>
 /// Draws all properties in a given property tree; must be wrapped by a <see cref="BeginDrawPropertyTree(PropertyTree, bool)"/> and <see cref="EndDrawPropertyTree(PropertyTree)"/>.
 /// </summary>
 /// <param name="tree">The tree to be drawn.</param>
 public static void DrawPropertiesInTree(PropertyTree tree)
 {
     foreach (var property in tree.EnumerateTree(false))
     {
         try
         {
             InspectorUtilities.DrawProperty(property);
         }
         catch (Exception ex)
         {
             if (ex is ExitGUIException || ex.InnerException is ExitGUIException)
             {
                 throw ex;
             }
             else
             {
                 Debug.Log("The following exception was thrown when drawing property " + property.Path + ".");
                 Debug.LogException(ex);
             }
         }
     }
 }
Exemple #4
0
        public override void OnInspectorGUI()
        {
            // If there are no custom editors for a parent type just draw the inspector as usual
            if (parentEditorType == null)
            {
                base.OnInspectorGUI();
            }
            else                 // If a parent type with a custom editor was found draw it
            {
                if (parentType != null)
                {
                    SirenixEditorGUI.Title(ObjectNames.NicifyVariableName(parentType.GetNiceName()), null, TextAlignment.Left, true);
                }

                // Draw the parent custom editor
                if (parentEditorType != null)
                {
                    CreateCachedEditor(target, parentEditorType, ref cachedParentEditor);
                    cachedParentEditor.OnInspectorGUI();
                }

                SirenixEditorGUI.Title(ObjectNames.NicifyVariableName(targetType.GetNiceName()), null, TextAlignment.Left, true);
                // Then draw the properties that the child class defined separately afterwards
                propertyTree ??= PropertyTree.Create(serializedObject);
                InspectorUtilities.BeginDrawPropertyTree(propertyTree, true);
                foreach (var inspectorProperty in propertyTree.EnumerateTree(false))
                {
                    // Don't draw properties that are covered by the parent editor type or any of its parents
                    if (inspectorProperty.Info.TypeOfOwner == parentType || parentBaseClasses.Contains(inspectorProperty.Info.TypeOfOwner))
                    {
                        continue;
                    }

                    inspectorProperty.Draw(inspectorProperty.Label);
                }

                InspectorUtilities.EndDrawPropertyTree(propertyTree);
            }
        }
Exemple #5
0
        protected static SettingsProvider CreateCustomSettingsProvider(string name)
        {
            _tree = PropertyTree.Create(GetInstance());
            // First parameter is the path in the Settings window.
            // Second parameter is the scope of this setting: it only appears in the Project Settings window.
            SettingsProvider provider = new SettingsProvider($"Project/RedOwl/{name}", SettingsScope.Project)
            {
                // Create the SettingsProvider and initialize its drawing (IMGUI) function in place:
                guiHandler = searchContext =>
                {
                    InspectorUtilities.BeginDrawPropertyTree(_tree, false);
                    foreach (InspectorProperty property in _tree.EnumerateTree(false))
                    {
                        property.Draw(property.Label);
                    }
                    InspectorUtilities.EndDrawPropertyTree(_tree);
                },

                // Populate the search keywords to enable smart search filtering and label highlighting:
                keywords = SettingsProvider.GetSearchKeywordsFromSerializedObject(new SerializedObject(GetInstance()))
            };

            return(provider);
        }