private void ShowMapSelectMenu()
    {
        EditorGUILayout.Space();

        if (selectedCreateType == MapDataType.Map)
        {
            EditorGUILayout.LabelField("Create New Map");

            newMapName = EditorGUILayout.TextField(newMapName);

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Create"))
            {
                var newMap = CreateInstance(typeof(MapDatabaseObject)) as MapDatabaseObject;
                newMap.name = newMapName;

                mapDatabase.mapDatabaseDictionary.Add(newMap.name, newMap);
                mapDatabase.Save();

                AssetDatabase.AddObjectToAsset(newMap, mapDatabase);
                EditorUtility.SetDirty(mapDatabase);

                currentMap = newMap;

                selectedCreateType = MapDataType.None;
            }

            if (GUILayout.Button("Cancel"))
            {
                selectedCreateType = MapDataType.None;
            }
            GUILayout.EndHorizontal();

            return;
        }

        if (GUILayout.Button("Create New Map"))
        {
            selectedCreateType = MapDataType.Map;
        }

        EditorGUILayout.Space();

        EditorGUILayout.LabelField("Map List");
        EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);

        foreach (var map in mapDatabase.mapDatabaseObjects.OrderBy(m => m.name))
        {
            if (GUILayout.Button(map.name))
            {
                map.InitDictionary();
                currentMap = map;

                RefreshMap();
            }
        }
    }
Exemple #2
0
    private void Awake()
    {
        InitializeObjectDictionary();
        InitializePrefabDictionary();

        mapDatabase.InitDictionary();

        currentMap = mapDatabase.mapDatabaseObjects[0];
        currentMap.InitDictionary();
    }
Exemple #3
0
    public bool ChangeMap(string mapName)
    {
        MapDatabaseObject map;

        if (mapDatabase.mapDatabaseDictionary.TryGetValue(mapName, out map))
        {
            currentMap = map;
            currentMap.InitDictionary();

            return(true);
        }

        return(false);
    }
    void OnGUI()
    {
        if (!initSuccessful)
        {
            EditorGUILayout.LabelField("Initialization failed.", EditorStyles.boldLabel);
            return;
        }

        if (!Application.isEditor || Application.isPlaying)
        {
            EditorGUILayout.LabelField("GameMapEditor only works during edit mode.", EditorStyles.boldLabel);
            return;
        }

        if (currentScene.name != "MapScene")
        {
            EditorGUILayout.LabelField("GameMapEditor only works in MapScene.", EditorStyles.boldLabel);
            return;
        }

        if (currentMap == null)
        {
            ShowMapSelectMenu();
            return;
        }

        GUILayout.BeginHorizontal();
        EditorGUILayout.LabelField(currentMap.name);

        if (GUILayout.Button("Map Menu"))
        {
            currentMap = null;

            RefreshMap();
        }
        GUILayout.EndHorizontal();

        EditorGUILayout.Vector3IntField("Position: ", lastClickedTilePosition);
        EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);

        if (selectedCountry != null)
        {
        }

        if (selectedTile != null)
        {
            if (selectedTile is CastleSpawnTile)
            {
                ShowCountry();
            }
            else if (selectedTile is InteractableSpawnTile)
            {
                ShowInteractable();
            }
            else if (selectedTile is AnimalSpawnTile)
            {
                ShowAnimal();
            }

            return;
        }

        if (selectedCreateType != MapDataType.None)
        {
            if (GUILayout.Button("Back"))
            {
                selectedCreateType = MapDataType.None;
            }

            if (selectedCreateType == MapDataType.Country)
            {
                ShowCreateCastleMenu();
            }
            else if (selectedCreateType == MapDataType.Interactable)
            {
                ShowCreateInteractableMenu();
            }
            else if (selectedCreateType == MapDataType.Animal)
            {
                ShowCreateAnimalMenu();
            }

            return;
        }

        if (GUILayout.Button("Create Castle"))
        {
            selectionGridIndex = 0;
            selectedCreateType = MapDataType.Country;
        }

        if (GUILayout.Button("Create Animal"))
        {
            selectionGridIndex = 0;
            selectedCreateType = MapDataType.Animal;
        }

        if (GUILayout.Button("Create Interactable"))
        {
            selectionGridIndex = 0;
            selectedCreateType = MapDataType.Interactable;
        }

        GUILayout.Space(25);

        if (GUILayout.Button("Refresh Database"))
        {
            RefreshDatabase();
        }

        if (GUILayout.Button("Refresh Map"))
        {
            RefreshMap();
        }

        if (!removeMapConfirmation && GUILayout.Button("Remove Map"))
        {
            removeMapConfirmation = true;
        }

        if (removeMapConfirmation)
        {
            GUILayout.BeginHorizontal();

            if (GUILayout.Button("Confirm"))
            {
                removeMapConfirmation = false;

                mapDatabase.mapDatabaseDictionary.Remove(currentMap.name);
                mapDatabase.Save();

                DestroyImmediate(currentMap, true);

                EditorUtility.SetDirty(mapDatabase);

                RefreshMap();
            }

            if (GUILayout.Button("Cancel"))
            {
                removeMapConfirmation = false;
            }

            GUILayout.EndHorizontal();
        }
    }