static MadLevelConfigurationWatcher()
    {
        EditorApplication.playmodeStateChanged += () => {
            if (GameObject.Find("/_mlm_ignore") != null)
            {
                return;
            }


            MadLevelConfiguration configuration;

            var layout = GameObject.FindObjectOfType(typeof(MadLevelAbstractLayout)) as MadLevelAbstractLayout;
            if (layout != null && layout.currentConfiguration != null)
            {
                configuration = layout.currentConfiguration;
            }
            else
            {
                configuration = MadLevel.activeConfiguration;
            }

            if (configuration != null &&
                EditorApplication.isPlayingOrWillChangePlaymode &&
                !EditorApplication.isPlaying)
            {
                if (!configuration.IsValid())
                {
                    if (!EditorUtility.DisplayDialog(
                            "Invalid Configuration",
                            "Your level configuration has errors. Do you want to continue anyway?",
                            "Yes", "No"))
                    {
                        EditorApplication.isPlaying = false;
                        Selection.activeObject      = configuration;
                        return;
                    }
                }

                if (configuration != MadLevel.activeConfiguration ||
                    !MadLevelConfigurationEditor.CheckBuildSynchronized(configuration) ||
                    !configuration.active)
                {
                    if (EditorUtility.DisplayDialog(
                            "Not Synchronized",
                            "Your level configuration is not active or synchronized "
                            + "(runtime errors may occur). Do it now?",
                            "Yes", "No"))
                    {
                        var active = MadLevelConfiguration.GetActive();
                        if (active != null)
                        {
                            active.active = false; // workaround
                        }
                        configuration.active = true;
                        MadLevelConfigurationEditor.SynchronizeBuild(configuration);
                    }
                }
            }
        };
    }
Ejemplo n.º 2
0
    int PageIndexForLevel(string levelName)
    {
        var configuration = MadLevelConfiguration.GetActive();
        int index         = configuration.FindLevelIndex(MadLevel.Type.Level, levelName);
        int levelsPerPage = gridWidth * gridHeight;
        int pageIndex     = index / levelsPerPage;

        return(pageIndex);
    }
    void OnGUI()
    {
        MadGUI.Info("To create a generator, implement IMadLevelGenerator interface and place your script in any Editor folder.");

        if (generators.Count == 0)
        {
            MadGUI.Error("I cannot found any generator in your project. Please implement at least one!");
            return;
        }

        chosenGeneratorIndex = EditorGUILayout.Popup("Generator", chosenGeneratorIndex, generators.ToArray());

        MadLevelConfiguration conf = MadLevelConfiguration.GetActive();

        chosenGroupIndex = EditorGUILayout.Popup("Group", chosenGroupIndex, GroupNames(conf));

        scene = EditorGUILayout.ObjectField("Scene", scene, typeof(Object), false);

        levelsCount = EditorGUILayout.IntField("Level Count", levelsCount);

        GUI.enabled = scene != null;
        if (MadGUI.Button("Create"))
        {
            string generatorName = generators[chosenGeneratorIndex];
            Type   generatorType = Type.GetType(generatorName + ", Assembly-CSharp-Editor");
            var    generator     = Activator.CreateInstance(generatorType) as IMadLevelGenerator;

            MadLevelConfiguration.Group group;
            if (chosenGroupIndex == 0)
            {
                group = conf.defaultGroup;
            }
            else
            {
                group = conf.groups[chosenGroupIndex - 1];
            }

            for (int i = 1; i <= levelsCount; ++i)
            {
                MadLevelConfiguration.Level level = conf.CreateLevel();
                level.sceneObject = scene;
                level.groupId     = group.id;
                level.type        = MadLevel.Type.Level;
                level.order       = int.MaxValue;
                level.name        = generator.GetLevelName(i);
                level.arguments   = generator.GetLevelArguments(i);
                conf.levels.Add(level);
                conf.SetDirty();
            }

            EditorUtility.SetDirty(conf);
        }
    }
Ejemplo n.º 4
0
    protected virtual void OnEnable()
    {
        if (configuration == null)
        {
            // not bound to any configuration. Bound it to active
            if (MadLevel.hasActiveConfiguration)
            {
                configuration = MadLevel.activeConfiguration;
            }
            else
            {
                Debug.LogWarning("There's no active level configuration. Please prepare one and activate it.");
            }
        }
        else if (configuration != MadLevel.activeConfiguration)
        {
            if (Application.isPlaying)
            {
                Debug.LogWarning("This layout was prepared for different level configuration than the active one. "
                                 + "http://goo.gl/AxZqW2", this);
            }
        }

        var panel = MadTransform.FindParent <MadPanel>(transform);

        panel.onFocusChanged += (MadSprite sprite) => {
            if (activeIcon != null && sprite != activeIcon)
            {
                DeactivateActiveIcon();
            }
        };

        onIconActivate += (icon, levelName) => {
            if (onIconActivateMessage && onIconActivateMessageReceiver != null)
            {
                onIconActivateMessageReceiver.SendMessage(onIconActivateMessageMethodName, icon);
            }

            if (onIconActivatePlayAudio && onIconActivatePlayAudioClip != null && cachedAudioListener != null)
            {
                AudioSource.PlayClipAtPoint(
                    onIconActivatePlayAudioClip,
                    cachedAudioListener.transform.position,
                    onIconActivatePlayAudioVolume);
            }
        };

        onIconDeactivate += (icon, levelName) => {
            if (onIconDeactivateMessage && onIconDeactivateMessageReceiver != null)
            {
                onIconDeactivateMessageReceiver.SendMessage(onIconDeactivateMessageMethodName, icon);
            }

            if (onIconDeactivatePlayAudio && onIconDeactivatePlayAudioClip != null && cachedAudioListener != null)
            {
                AudioSource.PlayClipAtPoint(
                    onIconDeactivatePlayAudioClip,
                    cachedAudioListener.transform.position,
                    onIconDeactivatePlayAudioVolume);
            }
        };

#if UNITY_EDITOR
        EditorApplication.playmodeStateChanged = () => {
            if (configuration != null &&
                EditorApplication.isPlayingOrWillChangePlaymode &&
                !EditorApplication.isPlaying)
            {
                if (!configuration.IsValid())
                {
                    if (!EditorUtility.DisplayDialog(
                            "Invalid Configuration",
                            "Your level configuration has errors. Do you want to continue anyway?",
                            "Yes", "No"))
                    {
                        EditorApplication.isPlaying = false;
                        Selection.activeObject      = configuration;
                        return;
                    }
                }

                if (configuration != MadLevel.activeConfiguration ||
                    !configuration.CheckBuildSynchronized() ||
                    !configuration.active)
                {
                    if (EditorUtility.DisplayDialog(
                            "Not Synchronized",
                            "Build configuration of choice is not activate/synchronized with this level select layout "
                            + "(errors will occur). Do it now?",
                            "Yes", "No"))
                    {
                        MadLevelConfiguration.GetActive().active = false; // workaround
                        configuration.active = true;
                        configuration.SynchronizeBuild();
                    }
                }
            }
        };
#endif
    }