protected void GUIEvent(string name, SerializedProperty property)
    {
        int  playCount, stopCount;
        bool stopAll;

        AnalyzeAction(property, out playCount, out stopCount, out stopAll);

        bool colorize = playCount > 0 || stopCount > 0 || stopAll;

        if (colorize)
        {
            GUI.color = Color.yellow;
        }

        if (MadGUI.Foldout(name, false))
        {
            GUI.color = Color.white;

            using (MadGUI.Indent()) {
                GUIAction(property);
            }
        }

        GUI.color = Color.white;
    }
Example #2
0
    public override void OnInspectorGUI()
    {
        serializedObject.UpdateIfDirtyOrScript();

        GUI.color = Color.yellow;
        if (GUILayout.Button("<< Back To Layer Listing"))
        {
            Selection.activeGameObject = layer.parent.gameObject;
        }
        GUI.color = Color.white;
        GUILayout.Space(16);

        MadGUI.PropertyField(texture, "Texture");
        MadGUI.PropertyField(tint, "Tint");

        EditorGUILayout.Space();

        MadGUI.PropertyField(scaleMode, "Scale Mode");

        MadGUI.PropertyField(repeatX, "Repeat X");
        MadGUI.PropertyField(repeatY, "Repeat Y");

        MadGUI.ConditionallyEnabled(layer.scaleMode == MadLevelBackgroundLayer.ScaleMode.Fill && !layer.repeatX && !layer.repeatY, () => {
            if (MadGUI.Foldout("Margin", false))
            {
                MadGUI.Indent(() => {
                    MadGUI.PropertyField(fillMarginLeft, "Left");
                    MadGUI.PropertyField(fillMarginTop, "Top");
                    MadGUI.PropertyField(fillMarginRight, "Right");
                    MadGUI.PropertyField(fillMarginBottom, "Bottom");
                });
            }
        });

        MadGUI.ConditionallyEnabled(!layer.repeatX && !layer.repeatY, () => {
            MadGUI.PropertyField(dontStretch, "Don't Stretch");
        });

        if (scaleMode.enumValueIndex == (int)MadLevelBackgroundLayer.ScaleMode.Manual)
        {
            MadGUI.PropertyField(align, "Align");
            EditorGUILayout.Space();
            MadGUI.PropertyFieldVector2Compact(position, "Position", 70);
            MadGUI.PropertyFieldVector2Compact(scale, "Scale", 70);
        }
        else
        {
            MadGUI.PropertyFieldVector2Compact(position, "Position", 70);
        }

        EditorGUILayout.Space();

        MadGUI.PropertyField(followSpeed, "Follow Speed");
        MadGUI.PropertyFieldVector2Compact(scrollSpeed, "Auto Scroll", 70);

        if (serializedObject.ApplyModifiedProperties())
        {
            layer.SetDirty();
        }
    }
    protected void TwoStepActivation()
    {
        MadGUI.PropertyFieldEnumPopup(twoStepActivationType, "Two Step Activation");
        MadGUI.ConditionallyEnabled(
            twoStepActivationType.enumValueIndex != (int)MadLevelAbstractLayout.TwoStepActivationType.Disabled, () => {
            MadGUI.Indent(() => {
                if (MadGUI.Foldout("On Activate", false))
                {
                    MadGUI.Indent(() => {
                        ActivateAction(
                            onIconActivatePlayAudio,
                            onIconActivatePlayAudioClip,
                            onIconActivatePlayAudioVolume,
                            onIconActivateMessage,
                            onIconActivateMessageReceiver,
                            onIconActivateMessageMethodName,
                            onIconActivateMessageIncludeChildren
                            );
                    });
                }

                if (MadGUI.Foldout("On Deactivate", false))
                {
                    MadGUI.Indent(() => {
                        ActivateAction(
                            onIconDeactivatePlayAudio,
                            onIconDeactivatePlayAudioClip,
                            onIconDeactivatePlayAudioVolume,
                            onIconDeactivateMessage,
                            onIconDeactivateMessageReceiver,
                            onIconDeactivateMessageMethodName,
                            onIconDeactivateMessageIncludeChildren
                            );
                    });
                }
            });
        });
    }
    public override void OnInspectorGUI()
    {
        if (MadTrialEditor.isTrialVersion && MadTrialEditor.expired)
        {
            MadTrialEditor.OnEditorGUIExpired("Mad Level Manager");
            return;
        }

        LoadTextures(); // loading textures with delay to prevent editor errors
        CheckAssetLocation();
        ActiveInfo();

        GUIGroupPopup();

        LoadItems();

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.BeginVertical(GUILayout.Width(1));
        GUILayout.Space(200);
        EditorGUILayout.EndVertical();
        list.Draw();
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        GUI.backgroundColor = Color.green;
        if (GUILayout.Button("Add"))
        {
            AddLevel();
        }
        GUI.backgroundColor = Color.white;

        GUI.enabled         = list.selectedItem != null;
        GUI.backgroundColor = Color.red;
        if (GUILayout.Button("Remove") || GUI.enabled && Event.current.keyCode == KeyCode.Delete)
        {
            RemoveLevel();
        }
        GUI.backgroundColor = Color.white;

        GUILayout.FlexibleSpace();

        GUILayout.Label("Move");

        if (GUILayout.Button("Down"))
        {
            MoveDown();
            configuration.SetDirty();
        }

        if (GUILayout.Button("Up"))
        {
            MoveUp();
            configuration.SetDirty();
        }

        GUILayout.Space(10);

        if (GUILayout.Button("Bottom"))
        {
            MoveToBottom();
            configuration.SetDirty();
        }

        if (GUILayout.Button("Top"))
        {
            MoveToTop();
            configuration.SetDirty();
        }

        GUI.enabled = true;

        EditorGUILayout.EndHorizontal();

        MadGUI.IndentBox("Level Properties", () => {
            var item  = list.selectedItem;
            var items = list.selectedItems;

            if (item == null)
            {
                item        = new LevelItem(configuration);
                GUI.enabled = false;
            }

            MadUndo.RecordObject(configuration, "Edit '" + item.level.name + "'");
            EditorGUI.BeginChangeCheck();

            EditorGUILayout.BeginHorizontal();

            EditorGUI.BeginChangeCheck();
            UnityEngine.Object sceneValue = null;
            if (!multiSelection)
            {
                MadGUI.Validate(() => item.level.sceneObject != null, () => {
                    sceneValue =
                        EditorGUILayout.ObjectField("Scene", item.level.sceneObject, typeof(UnityEngine.Object), false);
                });
            }
            else
            {
                bool unified = (from i in items select i.level.sceneObject).Distinct().Count() == 1;
                if (unified)
                {
                    sceneValue =
                        EditorGUILayout.ObjectField("Scene", item.level.sceneObject, typeof(UnityEngine.Object), false);
                }
                else
                {
                    sceneValue = EditorGUILayout.ObjectField("Scene", null, typeof(UnityEngine.Object), false);
                }
            }

            if (EditorGUI.EndChangeCheck())
            {
                MadUndo.RecordObject2(target, "Changed Level Scene");
                foreach (var levelItem in items)
                {
                    levelItem.level.sceneObject = sceneValue;
                }
            }


            GUI.backgroundColor = Color.yellow;
            if (GUILayout.Button("Set Current", GUILayout.Width(85)))
            {
                MadUndo.RecordObject2(target, "Change Scene");
#if UNITY_5 && !(UNITY_5_0 || UNITY_5_1 || UNITY_5_2)
                Scene activeScene = SceneManager.GetActiveScene();
                var obj           = AssetDatabase.LoadAssetAtPath(activeScene.name, typeof(UnityEngine.Object));
#else
                var obj = AssetDatabase.LoadAssetAtPath(EditorApplication.currentScene, typeof(UnityEngine.Object));
#endif

                if (obj != null)
                {
                    foreach (var levelItem in items)
                    {
                        levelItem.level.sceneObject = obj;
                    }
                }
                else
                {
                    EditorUtility.DisplayDialog("Scene not saved", "Current scene is not saved. Please save it first (CTRL+S).", "OK");
                }
            }
            GUI.backgroundColor = Color.white;

            EditorGUILayout.EndHorizontal();
            if (!CheckAssetIsScene(item.level.sceneObject))
            {
                item.level.sceneObject = null;
            }

            MadGUI.Validate(() => !string.IsNullOrEmpty(item.level.name), () => {
                GUI.SetNextControlName("level name"); // needs names to unfocus
                using (MadGUI.EnabledIf(!multiSelection)) {
                    if (!multiSelection)
                    {
                        EditorGUI.BeginChangeCheck();
                        var value = EditorGUILayout.TextField("Level Name", item.level.name);
                        if (EditorGUI.EndChangeCheck())
                        {
                            MadUndo.RecordObject2(target, "Changed Level Name");
                            item.level.name = value;
                        }
                    }
                    else
                    {
                        EditorGUILayout.TextField("Level Name", "-");
                    }
                }
            });


            // level type
            MadLevel.Type typeValue = default(MadLevel.Type);
            EditorGUI.BeginChangeCheck();
            if (!multiSelection)
            {
                typeValue = (MadLevel.Type)EditorGUILayout.EnumPopup("Type", item.level.type);
            }
            else
            {
                bool unified = (from i in items select i.level.type).Distinct().Count() == 1;
                if (unified)
                {
                    typeValue = (MadLevel.Type)EditorGUILayout.EnumPopup("Type", item.level.type);
                }
                else
                {
                    int val = EditorGUILayout.Popup("Type", -1, Enum.GetNames(typeof(MadLevel.Type)));
                    if (val != -1)
                    {
                        typeValue = (MadLevel.Type)val;
                    }
                }
            }

            if (EditorGUI.EndChangeCheck())
            {
                MadUndo.RecordObject2(target, "Changed Level Type");
                foreach (var levelItem in items)
                {
                    levelItem.level.type = typeValue;
                }
            }


            GUI.SetNextControlName("arguments"); // needs names to unfocus
            if (!multiSelection)
            {
                EditorGUI.BeginChangeCheck();
                var value = EditorGUILayout.TextField("Arguments", item.level.arguments);
                if (EditorGUI.EndChangeCheck())
                {
                    MadUndo.RecordObject2(target, "Changed Level Arguments");
                    item.level.arguments = value;
                }
            }
            else
            {
                bool unified = (from i in items select i.level.arguments).Distinct().Count() == 1;
                EditorGUI.BeginChangeCheck();
                string value = "";
                if (unified)
                {
                    value = EditorGUILayout.TextField("Arguments", item.level.arguments);
                }
                else
                {
                    value = EditorGUILayout.TextField("Arguments", "-");
                }
                if (EditorGUI.EndChangeCheck())
                {
                    MadUndo.RecordObject2(target, "Changed Level Arguments");
                    foreach (var levelItem in items)
                    {
                        levelItem.level.arguments = value;
                    }
                }
            }

            if (MadGUI.Foldout("Locking", false))
            {
                using (MadGUI.Indent()) {
                    bool lockedByDefultState = false;
                    if (multiSelection)
                    {
                        bool unified = (from i in items select i.level.lockedByDefault).Distinct().Count() == 1;
                        if (unified && (item.level.lockedByDefault))
                        {
                            lockedByDefultState = true;
                        }
                    }
                    else
                    {
                        lockedByDefultState = item.level.lockedByDefault;
                    }

                    EditorGUI.BeginChangeCheck();
                    GUI.SetNextControlName("locked by default"); // needs names to unfocus
                    bool lockedByDefaultValue = EditorGUILayout.Toggle("Locked By Default", lockedByDefultState);
                    if (EditorGUI.EndChangeCheck())
                    {
                        MadUndo.RecordObject2(target, "Changed Locked By Default");
                        foreach (var levelItem in items)
                        {
                            levelItem.level.lockedByDefault = lockedByDefaultValue;
                        }
                    }
                }
                EditorGUILayout.Space();
            }

            if (MadGUI.Foldout("Extensions", false))
            {
                using (MadGUI.Indent()) {
                    EditorGUI.BeginChangeCheck();
                    int extensionIndex = -1;

                    if (!multiSelection)
                    {
                        extensionIndex = configuration.extensions.FindIndex((e) => e == item.level.extension) + 1;
                    }
                    else
                    {
                        bool unified = (from i in items select i.level.extension).Distinct().Count() == 1;
                        if (unified)
                        {
                            extensionIndex = configuration.extensions.FindIndex((e) => e == item.level.extension) + 1;
                        }
                    }

                    extensionIndex = MadGUI.DynamicPopup(extensionIndex, "Extension", configuration.extensions.Count + 1,
                                                         (index) => {
                        if (index == 0)
                        {
                            return("(none)");
                        }
                        else
                        {
                            return(configuration.extensions[index - 1].name);
                        }
                    });
                    if (EditorGUI.EndChangeCheck())
                    {
                        MadUndo.RecordObject2(target, "Changed Extension For Level");

                        foreach (var levelItem in items)
                        {
                            if (extensionIndex == 0)
                            {
                                levelItem.level.extension = null;
                            }
                            else
                            {
                                levelItem.level.extension = configuration.extensions[extensionIndex - 1];
                            }
                        }

                        configuration.SetDirty();
                    }

                    bool enabledState = GUI.enabled;
                    GUI.enabled       = true;
                    if (MadGUI.Button("Open Extension Editor", Color.magenta))
                    {
                        MadLevelExtensionEditor.Show(configuration);
                    }
                    GUI.enabled = enabledState;

                    EditorGUILayout.Space();
                }
            }

            EditorGUI.BeginChangeCheck();
            int groupIndex = GroupToIndex(item.level.group);
            groupIndex     = EditorGUILayout.Popup("Move To Group:", groupIndex, GroupNames());
            if (EditorGUI.EndChangeCheck())
            {
                var @group = IndexToGroup(groupIndex);
                MadUndo.RecordObject2(target, "Move Levels To Group " + @group.name);
                foreach (var levelItem in items)
                {
                    levelItem.level.group = @group;
                }
            }


            if (EditorGUI.EndChangeCheck())
            {
                configuration.SetDirty();
            }

            if (inspectorAddons.Count > 0)
            {
                EditorGUILayout.Space();
            }

            foreach (var addon in inspectorAddons)
            {
                addon.OnInspectorGUI(item.level);
            }

            GUI.enabled = true;
        });

        EditorGUILayout.Space();
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Help"))
        {
            Help.BrowseURL(MadLevelHelp.LevelConfigurationHelp);
        }
        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();

        if (!configuration.IsValid())
        {
            MadGUI.Error("Configuration is invalid. Please make sure that:\n"
                         + "- There's no levels with \"!!!\" icon. These levels may have duplicated name or missing scene.\n"
                         + "- All your extensions have no missing scenes (in Extension Editor)"
                         );
        }

        if (configuration.active && !MadLevelConfigurationEditor.CheckBuildSynchronized(configuration))
        {
            if (MadGUI.ErrorFix(
                    "Build configuration is not in synch with level configuration.",
                    "Synchronize Now"))
            {
                MadLevelConfigurationEditor.SynchronizeBuild(configuration);
            }
        }

        ExecuteDelayed();
    }
Example #5
0
    public override void OnInspectorGUI()
    {
        if (levelIcon.generated && SetupMethodGenerate())
        {
            if (MadGUI.WarningFix("This icon instance has been generated. If you want to modify this icon, "
                                  + "please switch your Setup Method to Manual or change the template.", "Help"))
            {
                Application.OpenURL(MadLevelHelp.IconGenerated);
            }

            GUI.enabled = false;
        }

        if (MadGameObject.IsActive(levelIcon.gameObject))
        {
            Properties();
        }
        else
        {
            MadGUI.Warning("Not all functions are available if this object is disabled! Before editing please enable this game object!");
        }

        MadGUI.BeginBox("Visibility");

        MadGUI.Indent(() => {
            EditorGUILayout.Space();

            CheckPropertyError(levelIcon.showWhenLevelLocked);
            GUILayout.Label("Show when level is locked");
            ArrayFor(levelIcon.showWhenLevelLocked);

            CheckPropertyError(levelIcon.showWhenLevelUnlocked);
            GUILayout.Label("Show when level is unlocked");
            ArrayFor(levelIcon.showWhenLevelUnlocked);

            CheckPropertyError(levelIcon.showWhenLevelCompleted);
            GUILayout.Label("Show when level is completed");
            ArrayFor(levelIcon.showWhenLevelCompleted);

            CheckPropertyError(levelIcon.showWhenLevelNotCompleted);
            GUILayout.Label("Show when level is not completed");
            ArrayFor(levelIcon.showWhenLevelNotCompleted);

            CheckConflictError();

            serializedObject.UpdateIfDirtyOrScript();
            MadGUI.PropertyField(canFocusIfLocked, "Can Focus If Locked");

            serializedObject.ApplyModifiedProperties();

            if (levelIcon.generated)
            {
                serializedObject.UpdateIfDirtyOrScript();
                if (MadGUI.Foldout("Unlock On Complete", false))
                {
                    var arrayList = new MadGUI.ArrayList <MadLevelIcon>(
                        unlockOnComplete, (p) => { MadGUI.PropertyField(p, ""); });
                    arrayList.Draw();
                }
                serializedObject.ApplyModifiedProperties();
            }
        });
        MadGUI.EndBox();

        if (levelIcon.completedProperty != null || levelIcon.lockedProperty != null)
        {
            SectionSecialProperties();
        }

        MadGUI.BeginBox("Sprite");
        MadGUI.Indent(() => {
            SectionSprite();
        });
        MadGUI.EndBox();
    }
Example #6
0
    public override void OnInspectorGUI()
    {
        var levelIcon = target as MadLevelIcon;

        MadGUI.BeginBox("Properties");
        MadGUI.Indent(() => {
            var properties = PropertyList();
            foreach (MadLevelProperty property in properties)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(property.name, GUILayout.Width(170));

                GUI.enabled = !property.propertyEnabled;
                if (GUILayout.Button("Enable"))
                {
                    property.propertyEnabled = true;
                    EditorUtility.SetDirty(property);
                }
                GUI.enabled = property.propertyEnabled;
                if (GUILayout.Button("Disable"))
                {
                    property.propertyEnabled = false;
                    EditorUtility.SetDirty(property);
                }
                GUI.enabled = true;
                GUI.color   = Color.white;

                GUILayout.EndHorizontal();
            }
        });
        MadGUI.EndBox();

        MadGUI.BeginBox("Level Icon");
        MadGUI.Indent(() => {
            if (levelIcon.hasLevelConfiguration)
            {
                int levelCount = levelIcon.configuration.LevelCount(MadLevel.Type.Level);
                if (levelCount > levelIcon.levelIndex)
                {
                    var level = levelIcon.level;
                    MadGUI.Disabled(() => {
                        EditorGUILayout.TextField("Level Name", level.name);
                        EditorGUILayout.TextField("Level Arguments", level.arguments);
                    });
                }
                if (MadGUI.InfoFix("These values are set and managed by level configuration.",
                                   "Configuration"))
                {
                    Selection.objects = new Object[] { levelIcon.configuration };
                }
            }
            else
            {
                serializedObject.Update();
                MadGUI.PropertyField(levelSceneName, "Level Scene Name");
                serializedObject.ApplyModifiedProperties();
            }

            //
            // Completed property select popup
            //
            MadGUI.PropertyFieldObjectsPopup <MadLevelProperty>(
                target,
                "\"Completed\" Property",
                ref levelIcon.completedProperty,
                PropertyList(),
                false
                );

            MadGUI.PropertyFieldObjectsPopup <MadLevelProperty>(
                target,
                "\"Locked\" Property",
                ref levelIcon.lockedProperty,
                PropertyList(),
                false
                );

            MadGUI.PropertyFieldObjectsPopup <MadText>(
                target,
                "Level Number Text",
                ref levelIcon.levelNumber,
                TextList(),
                false
                );

            serializedObject.Update();
            if (MadGUI.Foldout("Unlock On Complete", false))
            {
                var arrayList = new MadGUI.ArrayList <MadLevelIcon>(
                    unlockOnComplete, (p) => { MadGUI.PropertyField(p, ""); });
                arrayList.Draw();
            }
            serializedObject.ApplyModifiedProperties();
        });
        MadGUI.EndBox();

        MadGUI.BeginBox("Sprite");
        MadGUI.Indent(() => {
            SectionSprite();
        });
        MadGUI.EndBox();
    }