コード例 #1
0
        public static string Serialize(AllowedMenuItemsSettings deserialized)
        {
            JObject jObject = JObject.FromObject(deserialized, JsonSerializer.Create(SerializerSettings));

            jObject.Add("$serializerVersion", version);
            return(jObject.ToString());
        }
コード例 #2
0
        private void OnGUI()
        {
            // Magic number.
            minSize      = new Vector2(420f, 720f);
            titleContent = new GUIContent("Menu Items");

            GUIStyle labelStyle = new GUIStyle(EditorStyles.label);

            labelStyle.richText = true;
            labelStyle.wordWrap = true;

            if (behaviorList == null || conditionList == null)
            {
                InitializeLists();
            }

            EditorIcon logo = new EditorIcon("logo_creator");
            Rect       rect = GUILayoutUtility.GetRect(position.width, 150, GUI.skin.box);

            GUI.DrawTexture(rect, logo.Texture, ScaleMode.ScaleToFit);

            GUILayout.Space(20f);

            EditorGUILayout.HelpBox("This window provides editor configuration settings for the Innoactive Creator. "
                                    + "It is supposed to be changed only by a software developer. "
                                    + "Modification of these values may lead to various issues.", MessageType.Warning);

            GUILayout.BeginHorizontal();
            {
                GUILayout.FlexibleSpace();
                if (isEditUnlocked == false)
                {
                    if (GUILayout.Button("I understand the risks. Let me edit it."))
                    {
                        isEditUnlocked = true;
                    }
                }

                GUILayout.FlexibleSpace();
            }
            GUILayout.EndHorizontal();

            GUILayout.Space(20f);

            if (string.IsNullOrEmpty(EditorConfigurator.Instance.AllowedMenuItemsSettingsAssetPath))
            {
                EditorGUILayout.LabelField("The property <i>AllowedMenuItemsSettingsAssetPath</i> of the current editor configuration returns <i>null</i> or an empty string. " +
                                           "For this reason, this feature is disabled.\n\n" +
                                           "If you want to configure what menu items should be displayed in the <i>Training Step Inspector</i>, " +
                                           "override the <i>DefaultEditorConfiguration</i> (if you have not already done so) " +
                                           "and let this property return a valid asset path.\n\n" +
                                           "Example of a valid asset path:\n<i>Assets/Editor/Innoactive/allowed_menu_items_config.json</i>\n\n" +
                                           "Note: The file will then be created at this location and is used to save the configurations made in this window.", labelStyle);

                return;
            }

            scrollPosition = GUILayout.BeginScrollView(scrollPosition, true, true);
            {
                EditorGUI.BeginDisabledGroup(isEditUnlocked == false);
                {
                    EditorGUILayout.LabelField("<b>Here you can change whether a behavior or a condition menu item is selectable in the <i>Training Step Inspector</i></b>.\n\n" +
                                               "Non-editable entries are behavior or condition menu items that had been deleted from the project at some point.\n\n" +
                                               "<i>Available Behaviors:</i>\n", labelStyle);

                    IDictionary <string, bool> behaviors = EditorConfigurator.Instance.AllowedMenuItemsSettings.SerializedBehaviorSelections;

                    // ReSharper disable once PossibleNullReferenceException
                    if (behaviorList.Count == 0)
                    {
                        EditorGUILayout.LabelField("<i>None</i>", labelStyle);
                    }
                    else
                    {
                        // ReSharper disable once PossibleNullReferenceException
                        foreach (EntityEntry entry in behaviorList)
                        {
                            EditorGUI.BeginDisabledGroup(entry.IsTypeValid == false);
                            {
                                if (EditorGUILayout.ToggleLeft(entry.DisplayedName, behaviors[entry.AssemblyQualifiedName]) != behaviors[entry.AssemblyQualifiedName])
                                {
                                    // Toggle was clicked.
                                    behaviors[entry.AssemblyQualifiedName] = behaviors[entry.AssemblyQualifiedName] == false;
                                    AllowedMenuItemsSettings.Save(EditorConfigurator.Instance.AllowedMenuItemsSettings);
                                }
                            }
                            EditorGUI.EndDisabledGroup();
                        }
                    }

                    EditorGUILayout.LabelField("\n<i>Available Conditions:</i>\n", labelStyle);

                    IDictionary <string, bool> conditions = EditorConfigurator.Instance.AllowedMenuItemsSettings.SerializedConditionSelections;

                    // ReSharper disable once PossibleNullReferenceException
                    if (conditionList.Count == 0)
                    {
                        EditorGUILayout.LabelField("<i>None</i>", labelStyle);
                    }
                    else
                    {
                        // ReSharper disable once PossibleNullReferenceException
                        foreach (EntityEntry entry in conditionList)
                        {
                            EditorGUI.BeginDisabledGroup(entry.IsTypeValid == false);
                            {
                                if (EditorGUILayout.ToggleLeft(entry.DisplayedName, conditions[entry.AssemblyQualifiedName]) != conditions[entry.AssemblyQualifiedName])
                                {
                                    // Toggle was clicked.
                                    conditions[entry.AssemblyQualifiedName] = conditions[entry.AssemblyQualifiedName] == false;
                                    AllowedMenuItemsSettings.Save(EditorConfigurator.Instance.AllowedMenuItemsSettings);
                                }
                            }
                            EditorGUI.EndDisabledGroup();
                        }
                    }
                }
                EditorGUI.EndDisabledGroup();
            }
            GUILayout.EndScrollView();
        }