internal static void InitializeSettings(string assetGuid)
        {
            settingsGuid = assetGuid;
            settingsPath = AssetDatabase.GUIDToAssetPath(assetGuid);
            //try to get proper settings asset from provided guid
            var settings = AssetDatabase.LoadAssetAtPath <ToolboxEditorSettings>(settingsPath);

            if (settings == null)
            {
                ToolboxEditorLog.KitInitializationWarning(settingsType);
                return;
            }

            Settings = settings;
            Settings.AddOnSettingsUpdatedListener(() =>
            {
                //perform separated data models update
                ToolboxDrawerUtility.PerformData();
                ToolboxProjectUtility.PerformData();
                ToolboxHierarchyUtility.PerformData();

                //perform additional repaint to update GUI
                ToolboxEditorProject.RepaintProjectOverlay();
                ToolboxEditorHierarchy.RepaintHierarchyOverlay();
            });

            //initialize core functionalities
            ToolboxDrawerUtility.PerformData(Settings);
            ToolboxProjectUtility.PerformData(Settings);
            ToolboxHierarchyUtility.PerformData(Settings);
        }
Exemple #2
0
        public void SetAllPossibleTargetTypeDrawers()
        {
            targetTypeDrawerHandlers?.Clear();

            var types = ToolboxDrawerUtility.GetAllPossibleTargetTypeDrawers();

            for (var i = 0; i < types.Count; i++)
            {
                AddTargetTypeDrawerHandler(new SerializedTypeReference(types[i]));
            }
        }
Exemple #3
0
        public void SetAllPossibleConditionDrawers()
        {
            conditionDrawerHandlers?.Clear();

            var types = ToolboxDrawerUtility.GetAllPossibleConditionDrawers();

            for (var i = 0; i < types.Count; i++)
            {
                AddConditionDrawerHandler(new SerializedType(types[i]));
            }
        }
Exemple #4
0
        internal static void InitializeSettings(string assetGuid)
        {
            settingsGuid = assetGuid;
            settingsPath = AssetDatabase.GUIDToAssetPath(assetGuid);
            //try to get proper settings asset from provided guid
            var settings = AssetDatabase.LoadAssetAtPath <ToolboxEditorSettings>(settingsPath);

            if (settings == null)
            {
                ToolboxEditorLog.KitInitializationWarning(settingsType);
                return;
            }

            Settings = settings;

            //initialize core functionalities
            ToolboxDrawerUtility.InitializeDrawers(Settings);
            ToolboxFolderUtility.InitializeProject(Settings);
        }
Exemple #5
0
        internal static void InitializeSettings(string assetGuid)
        {
            const string warningMessage = settingsType +
                                          " asset file not found. Cannot initialize Toolbox core functionalities. " +
                                          "You can create new settings file using CreateAsset menu -> Create -> Toolbox Editor -> Settings.";

            settingsGuid = assetGuid;
            settingsPath = AssetDatabase.GUIDToAssetPath(assetGuid);
            //try to get proper settings asset from provided guid
            var settings = AssetDatabase.LoadAssetAtPath <ToolboxEditorSettings>(settingsPath);

            if (settings == null)
            {
                Debug.LogWarning(warningMessage);
                return;
            }

            Settings = settings;

            //initialize core functionalities
            ToolboxDrawerUtility.InitializeDrawers(Settings);
            ToolboxFolderUtility.InitializeProject(Settings);
        }
        /// <summary>
        /// Constructor prepares all property-related data for custom drawing.
        /// </summary>
        /// <param name="property"></param>
        public ToolboxPropertyHandler(SerializedProperty property)
        {
            this.property = property;

            //here starts preparation of all needed data for this handler
            //first of all we have to retrieve native data like field info, custom native drawer, etc.
            //after this we have to retrieve (if possible) all Toolbox-related data - ToolboxAttributes

            //get field info associated with this property, this property is needed for custom attributes
            propertyFieldInfo = property.GetFieldInfo(out propertyType);

            if (propertyFieldInfo == null)
            {
                return;
            }

            //set basic content for handled property
            propertyLabel = new GUIContent(property.displayName);

            //check if this property has built-in property drawer
            if (!(hasNativePropertyDrawer = property.HasCustomDrawer(propertyType)))
            {
                var propertyAttributes = propertyFieldInfo.GetCustomAttributes <PropertyAttribute>();
                foreach (var attribute in propertyAttributes)
                {
                    if (hasNativePropertyDrawer = property.HasCustomDrawer(attribute.GetType()))
                    {
                        break;
                    }
                }
            }

            hasToolboxTargetTypeDrawer = ToolboxDrawerUtility.HasTargetTypeDrawer(propertyType);

            //specify drawer attribute
            if (property.isArray)
            {
                //get collection drawer associated to this array field
                propertyArrayAttribute = propertyFieldInfo.GetCustomAttribute <ToolboxCollectionAttribute>();
            }
            else
            {
                //get property drawer associated to this property
                propertySingleAttribute = propertyFieldInfo.GetCustomAttribute <ToolboxPropertyAttribute>();
            }

            hasToolboxPropertyDrawer = hasToolboxTargetTypeDrawer || propertySingleAttribute != null || propertyArrayAttribute != null;

            //validate child property using associated field info
            if (propertyFieldInfo == null || propertyFieldInfo.Name != property.name)
            {
                return;
            }

            //get only one condition attribute to valdiate state of this property
            conditionAttribute = propertyFieldInfo.GetCustomAttribute <ToolboxConditionAttribute>();
            //get all available decorator attributes
            decoratorAttributes = propertyFieldInfo.GetCustomAttributes <ToolboxDecoratorAttribute>()
                                  .ToArray();
            //keep decorator attributes in proper order
            Array.Sort(decoratorAttributes, (a1, a2) => a1.Order.CompareTo(a2.Order));
        }
        /// <summary>
        /// Draw property using Unity's layouting system and cached <see cref="ToolboxAttributeDrawer"/>s.
        /// </summary>
        public void OnGuiLayout()
        {
            //depending on previously gained data we can provide more action
            //using custom attributes and information about native drawers
            //we can use associated ToolboxDrawers or/and draw property in the default way

            //begin all needed decorator drawers in proper order
            if (decoratorAttributes != null)
            {
                for (var i = 0; i < decoratorAttributes.Length; i++)
                {
                    ToolboxDrawerUtility.GetDecoratorDrawer(decoratorAttributes[i])?.OnGuiBegin(decoratorAttributes[i]);
                }
            }

            //handle condition attribute(only one allowed)
            var conditionState = PropertyCondition.Valid;

            if (conditionAttribute != null)
            {
                conditionState = ToolboxDrawerUtility.GetConditionDrawer(conditionAttribute)?.OnGuiValidate(property, conditionAttribute) ?? conditionState;
            }

            if (conditionState == PropertyCondition.NonValid)
            {
                // :)
                goto Finish;
            }

            //disable property field if it is needed
            if (conditionState == PropertyCondition.Disabled)
            {
                EditorGUI.BeginDisabledGroup(true);
            }

            //get property drawer for single property or draw it in default way
            if (hasToolboxPropertyDrawer)
            {
                if (hasToolboxTargetTypeDrawer)
                {
                    //draw property based on associated type drawer
                    ToolboxDrawerUtility.GetTargetTypeDrawer(propertyType).OnGui(property, propertyLabel);
                }
                else if (property.isArray)
                {
                    //draw array property by its collection drawer
                    ToolboxDrawerUtility.GetCollectionDrawer(propertyArrayAttribute)?.OnGui(property, propertyLabel, propertyArrayAttribute);
                }
                else
                {
                    //draw single property by its property drawer
                    ToolboxDrawerUtility.GetPropertyDrawer(propertySingleAttribute)?.OnGui(property, propertyLabel, propertySingleAttribute);
                }
            }
            else
            {
                OnGuiDefault();
            }

            //end disabled state check
            if (conditionState == PropertyCondition.Disabled)
            {
                EditorGUI.EndDisabledGroup();
            }

Finish:
            //end all needed decorator drawers in proper order
            if (decoratorAttributes != null)
            {
                for (var i = decoratorAttributes.Length - 1; i >= 0; i--)
                {
                    ToolboxDrawerUtility.GetDecoratorDrawer(decoratorAttributes[i])?.OnGuiEnd(decoratorAttributes[i]);
                }
            }
        }