예제 #1
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyGroupLayout(InspectorProperty property, ToggleGroupAttribute attribute, GUIContent label)
        {
            var toggleProperty = property.Children.Get(attribute.ToggleMemberName);

            var context = property.Context.Get <ToggleGroupConfig>(this, "ToggleGroupConfig", (ToggleGroupConfig)null);

            if (context.Value == null)
            {
                context.Value           = new ToggleGroupConfig();
                context.Value.IsVisible = property.Context.GetPersistent <bool>(this, "IsVisible", false);
                if (toggleProperty == null)
                {
                    context.Value.ErrorMessage = "No property or field named " + attribute.ToggleMemberName + " found. Make sure the property is part of the inspector and the group.";
                }
                else
                {
                    context.Value.TitleHelper = new StringMemberHelper(property.ParentType, attribute.ToggleGroupTitle, ref context.Value.ErrorMessage);
                }
            }

            if (context.Value.ErrorMessage != null)
            {
                AllEditorGUI.ErrorMessageBox(context.Value.ErrorMessage);
            }
            else
            {
                PropertyContext <string> openGroup = null;

                if (attribute.CollapseOthersOnExpand)
                {
                    if (property.Parent == null)
                    {
                        //openGroup = GUIHelper.GetTemporaryContext<PropertyContext<string>>(property.Tree);
                        openGroup = property.Context.Get <string>(this, "OpenGroup", (string)null);
                    }
                    else
                    {
                        var parent = (property.Parent.ValueEntry == null || property.Parent.ValueEntry.ValueCategory == PropertyValueCategory.Member) ? property.Parent : property.Parent.Parent;
                        openGroup = parent.Context.GetGlobal <string>("OpenFoldoutToggleGroup", (string)null);
                    }

                    if (openGroup.Value != null && openGroup.Value != property.Path)
                    {
                        context.Value.IsVisible.Value = false;
                    }
                }

                bool isEnabled = (bool)toggleProperty.ValueEntry.WeakSmartValue;

                string title = context.Value.TitleHelper.GetString(property) ?? attribute.GroupName;

                bool prev          = context.Value.IsVisible.Value;
                bool visibleBuffer = context.Value.IsVisible.Value;
                if (AllEditorGUI.BeginToggleGroup(UniqueDrawerKey.Create(property, this), ref isEnabled, ref visibleBuffer, title))
                {
                    for (int i = 0; i < property.Children.Count; i++)
                    {
                        var child = property.Children[i];
                        if (child != toggleProperty)
                        {
                            InspectorUtilities.DrawProperty(child);
                        }
                    }
                }
                else
                {
                    // OnValueChanged is not fired if property is not drawn.
                    GUIHelper.BeginDrawToNothing();
                    InspectorUtilities.DrawProperty(toggleProperty);
                    GUIHelper.EndDrawToNothing();
                }
                AllEditorGUI.EndToggleGroup();

                context.Value.IsVisible.Value = visibleBuffer;
                if (openGroup != null && prev != context.Value.IsVisible.Value && context.Value.IsVisible.Value)
                {
                    openGroup.Value = property.Path;
                }

                toggleProperty.ValueEntry.WeakSmartValue = isEnabled;

                // Why is this here? Commenting this out for now
                //toggleProperty.ValueEntry.ApplyChanges();
            }
        }
예제 #2
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(InspectorProperty property, ToggleAttribute attribute, GUIContent label)
        {
            var toggleProperty = property.Children.Get(attribute.ToggleMemberName);

            if (toggleProperty == null)
            {
                AllEditorGUI.ErrorMessageBox(attribute.ToggleMemberName + " is not a member of " + property.Info.MemberInfo.GetNiceName() + ".");
            }
            else if (toggleProperty.ValueEntry.TypeOfValue != typeof(bool))
            {
                AllEditorGUI.ErrorMessageBox(attribute.ToggleMemberName + " on " + property.Info.MemberInfo.GetNiceName() + "  must be a boolean.");
            }
            else
            {
                bool isEnabled = (bool)toggleProperty.ValueEntry.WeakSmartValue;
                var  isVisible = property.Context.GetPersistent(this, "isVisible", false);

                PropertyContext <string> openGroup = null;

                if (attribute.CollapseOthersOnExpand)
                {
                    if (property.Parent == null)
                    {
                        //openGroup = GUIHelper.GetTemporaryContext<PropertyContext<string>>(property.Tree);
                        openGroup = property.Context.Get <string>(this, "OpenGroup", (string)null);
                    }
                    else
                    {
                        var parent = (property.Parent.ValueEntry == null || property.Parent.ValueEntry.ValueCategory == PropertyValueCategory.Member) ? property.Parent : property.Parent.Parent;
                        openGroup = parent.Context.GetGlobal <string>("OpenFoldoutToggleGroup", (string)null);
                    }

                    if (openGroup.Value != null && openGroup.Value != property.Path)
                    {
                        isVisible.Value = false;
                    }
                }

                bool prev          = isVisible.Value;
                bool visibleBuffer = isVisible.Value;
                if (AllEditorGUI.BeginToggleGroup(UniqueDrawerKey.Create(property, this), ref isEnabled, ref visibleBuffer, label != null ? label.text : property.Info.MemberInfo.GetNiceName()))
                {
                    for (int i = 0; i < property.Children.Count; i++)
                    {
                        var child = property.Children[i];
                        if (child != toggleProperty)
                        {
                            InspectorUtilities.DrawProperty(child);
                        }
                    }
                }
                AllEditorGUI.EndToggleGroup();

                isVisible.Value = visibleBuffer;
                if (openGroup != null && prev != isVisible.Value && isVisible.Value)
                {
                    openGroup.Value = property.Path;
                }

                toggleProperty.ValueEntry.WeakSmartValue = isEnabled;
            }
        }