public override void OnInspectorGUI()
        {
            //base.OnInspectorGUI();
            var        taskListConfigObject = target as TaskListConfigObject;
            TaskConfig remove = null;

            foreach (var taskConfig in taskListConfigObject.TaskConfigs)
            {
                EditorGUILayout.BeginHorizontal();

                EditorGUILayout.BeginVertical();

                var visible  = EditorPrefs.GetBool($"{taskConfig.GetHashCode().ToString()}", false);
                var toggeled = SirenixEditorGUI.BeginToggleGroup(taskConfig, ref taskConfig.Enabled, ref visible, taskConfig.Title, 0.3f);
                if (toggeled)
                {
                    taskConfig.Title       = EditorGUILayout.TextField(taskConfig.Title);
                    taskConfig.Description = EditorGUILayout.TextArea(taskConfig.Description);
                }
                EditorPrefs.SetBool($"{taskConfig.GetHashCode()}", visible);
                SirenixEditorGUI.EndToggleGroup();

                EditorGUILayout.EndVertical();

                if (GUILayout.Button("-", GUILayout.Width(20)))
                {
                    remove = taskConfig;
                }

                EditorGUILayout.EndHorizontal();
            }
            if (remove != null)
            {
                taskListConfigObject.TaskConfigs.Remove(remove);
                EditorUtility.SetDirty(taskListConfigObject);
            }
            if (GUILayout.Button("+ 添加任务"))
            {
                taskListConfigObject.TaskConfigs.Add(new TaskConfig());
                EditorUtility.SetDirty(taskListConfigObject);
            }
            serializedObject.ApplyModifiedProperties();
            serializedObject.UpdateIfRequiredOrScript();
        }
Exemple #2
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(GUIContent label)
        {
            var property  = this.Property;
            var attribute = this.Attribute;

            var toggleProperty = property.Children.Get(attribute.ToggleMemberName);

            if (toggleProperty == null)
            {
                SirenixEditorGUI.ErrorMessageBox(attribute.ToggleMemberName + " is not a member of " + property.NiceName + ".");
            }
            else if (toggleProperty.ValueEntry.TypeOfValue != typeof(bool))
            {
                SirenixEditorGUI.ErrorMessageBox(attribute.ToggleMemberName + " on " + property.NiceName + "  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.Info.HasSingleBackingMember) ? 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 (SirenixEditorGUI.BeginToggleGroup(UniqueDrawerKey.Create(property, this), ref isEnabled, ref visibleBuffer, label != null ? label.text : property.NiceName))
                {
                    for (int i = 0; i < property.Children.Count; i++)
                    {
                        var child = property.Children[i];
                        if (child != toggleProperty)
                        {
                            child.Draw(child.Label);
                        }
                    }
                }
                SirenixEditorGUI.EndToggleGroup();

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

                toggleProperty.ValueEntry.WeakSmartValue = isEnabled;
            }
        }
    public override void OnInspectorGUI()
    {
        //base.OnInspectorGUI();
        var mapCallHelperObject = target as MapCallHelperObject;

        if (mapCallHelperObject.MessageClasses == null)
        {
            return;
        }

        MessageClass removeItem = null;

        for (int i = 0; i < mapCallHelperObject.MessageClasses.Count; i++)
        {
            EditorGUILayout.BeginHorizontal();
            {
                var item    = mapCallHelperObject.MessageClasses[i];
                var visible = EditorPrefs.GetBool($"{item.GetHashCode()}");
                EditorGUILayout.BeginVertical();

                {
                    var isToggled = SirenixEditorGUI.BeginToggleGroup(item, ref item.Enabled, ref visible, item.TagName);
                    if (isToggled)
                    {
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.LabelField("类名", GUILayout.Width(100));
                        item.ClassName = EditorGUILayout.TextField(item.ClassName);
                        EditorGUILayout.EndHorizontal();

                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.LabelField("别名", GUILayout.Width(100));
                        item.TagName = EditorGUILayout.TextField(item.TagName);
                        EditorGUILayout.EndHorizontal();

                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.LabelField("消息类型", GUILayout.Width(100));
                        item.MessageType = (ETMessageType)EditorGUILayout.EnumPopup(item.MessageType);
                        EditorGUILayout.EndHorizontal();

                        MessageParamConfig removeParam = null;
                        foreach (var item2 in item.MessageParamConfigs)
                        {
                            EditorGUILayout.BeginHorizontal();
                            {
                                item2.ParamName = EditorGUILayout.TextField(item2.ParamName, GUILayout.Width(100));
                                item2.ParamType = (Proto3Type)EditorGUILayout.EnumPopup(item2.ParamType);
                                if (GUILayout.Button("-", GUILayout.Width(20)))
                                {
                                    removeParam = item2;
                                }
                            }
                            EditorGUILayout.EndHorizontal();
                        }
                        if (removeParam != null)
                        {
                            item.MessageParamConfigs.Remove(removeParam);
                        }

                        EditorGUILayout.BeginHorizontal();
                        {
                            SirenixEditorGUI.IndentSpace();
                            if (GUILayout.Button("+"))
                            {
                                item.MessageParamConfigs.Add(new MessageParamConfig());
                            }
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                    EditorPrefs.SetBool($"{item.GetHashCode()}", visible);
                    SirenixEditorGUI.EndToggleGroup();
                }

                EditorGUILayout.EndVertical();

                if (GUILayout.Button("-", GUILayout.Width(20)))
                {
                    removeItem = item;
                }
            }
            EditorGUILayout.EndHorizontal();
        }

        if (removeItem != null)
        {
            mapCallHelperObject.MessageClasses.Remove(removeItem);
        }

        if (GUILayout.Button("+"))
        {
            mapCallHelperObject.MessageClasses.Add(new MessageClass());
        }

        serializedObject.ApplyModifiedProperties();
    }
Exemple #4
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(GUIContent label)
        {
            var property  = this.Property;
            var attribute = this.Attribute;

            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, attribute.ToggleGroupTitle, ref context.Value.ErrorMessage);
                }
            }

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

                if (attribute.CollapseOthersOnExpand)
                {
                    if (property.Parent == null)
                    {
                        openGroup = property.Context.Get <string>(this, "OpenGroup", (string)null);
                    }
                    else
                    {
                        var parent = (property.Parent.ValueEntry == null || property.Parent.Info.HasSingleBackingMember) ? 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 (SirenixEditorGUI.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)
                        {
                            child.Draw(child.Label);
                        }
                    }
                }
                else
                {
                    // OnValueChanged is not fired if property is not drawn.
                    GUIHelper.BeginDrawToNothing();
                    toggleProperty.Draw(toggleProperty.Label);
                    GUIHelper.EndDrawToNothing();
                }
                SirenixEditorGUI.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();
            }
        }