Пример #1
0
    // ===========================================================
    // Methods for/from SuperClass/Interfaces
    // ===========================================================

    // ===========================================================
    // Methods
    // ===========================================================

    void OnEnable()
    {
        configuration = target as MadLevelConfiguration;

        items = new List <LevelItem>();

        list                  = new MadGUI.ScrollableList <LevelItem>(items);
        list.height           = 0; // expand
        list.spaceAfter       = 150;
        list.label            = "Level List";
        list.selectionEnabled = true;

        list.selectionCallback = (item) => ItemSelected(item);
        list.acceptDropTypes.Add(typeof(UnityEngine.Object));
        list.dropCallback += (index, obj) => {
            if (CheckAssetIsScene(obj))
            {
                executionQueue.Add(() => {
                    var item = AddLevel();
                    item.level.sceneObject = obj;
                    item.level.type        = MadLevel.Type.Other;

                    item.level.name = "";
                    item.level.name = UniqueLevelName(obj.name);

                    configuration.SetDirty();
                });
            }
        };
    }
    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);
        }
    }
    // ===========================================================
    // Methods for/from SuperClass/Interfaces
    // ===========================================================

    // ===========================================================
    // Methods
    // ===========================================================
    
    void OnEnable() {
        configuration = target as MadLevelConfiguration;
    
        items = new List<LevelItem>();
    
        list = new MadGUI.ScrollableList<LevelItem>(items);
        list.height = 0; // expand
        list.spaceAfter = 150;
        list.label = "Level List";
        list.selectionEnabled = true;
        
        list.selectionCallback = (item) => ItemSelected(item);
        list.acceptDropTypes.Add(typeof(UnityEngine.Object));
        list.dropCallback += (index, obj) => {
            if (CheckAssetIsScene(obj)) {
                executionQueue.Add(() => {
                    var item = AddLevel();
                    item.level.sceneObject = obj;
                    item.level.type = MadLevel.Type.Other;

                    item.level.name = "";
                    item.level.name = UniqueLevelName(obj.name);

                    configuration.SetDirty();
                });
            }
        };
    }