Пример #1
0
        public void LoadSavedMaps()
        {
            FileInfo f = new FileInfo(Application.persistentDataPath + TAG_MAP_SAVE_FILENAME);

            if (f.Exists)
            {
                try
                {
                    //Read the data here
                    StreamReader sr          = f.OpenText();
                    string       fileContent = sr.ReadToEnd();
                    sr.Close();
                    var savedMapList = Json.Deserialize(fileContent) as List <object>;
                    savedMaps.Clear();
                    for (int i = 0; i < savedMapList.Count; i++)
                    {
                        Dictionary <string, object> rawData = savedMapList[i] as Dictionary <string, object>;
                        MapEditorSaveData           data    = new MapEditorSaveData(rawData);
                        savedMaps.Add(data);
                    }
                }
                catch (System.Exception e)
                {
                    Debug.Log("Message " + e.Message);
                }
            }
        }
Пример #2
0
        public void DrawAllGridLine(MapEditorSaveData data)
        {
            GL.Clear(true, true, Color.blue);

            // each (wi & he) is +1 line
            lineMat.SetPass(0);

            int mapWidth  = data.width;
            int mapHeight = data.height;

            GL.PushMatrix();

            GL.Begin(GL.LINES);
            GL.Color(new Color(lineMat.color.r, lineMat.color.g, lineMat.color.b, lineMat.color.a));

            for (int x = 0; x <= mapWidth; x++)
            {
                GL.Vertex3(x * gridSize, 0, 0);
                GL.Vertex3(x * gridSize, mapHeight * gridSize, 0);
            }

            for (int y = 0; y <= mapHeight; y++)
            {
                GL.Vertex3(0, y * gridSize, 0);
                GL.Vertex3(mapWidth * gridSize, y * gridSize, 0);
            }

            GL.End();
            GL.PopMatrix();
        }
Пример #3
0
        public void Init(MapEditorSaveData data)
        {
            storedData = data;

            mapName.text      = data.mapName;
            mapWH.text        = data.width + " x " + data.height;
            craetedDate.text  = "Created : " + data.createdDate;
            modifiedDate.text = "Modified : " + data.modifiedDate;
        }
Пример #4
0
        public void UpdateSavedMap(MapEditorSaveData saveData)
        {
            string currentTime = DateTime.Now.ToString("yyyyMMddHHmmss");
            int    index       = savedMaps.FindIndex(x => x.saveName == saveData.saveName);

            if (index >= 0)
            {
                //Map existed, proceed to change the modified time
                savedMaps[index].modifiedDate      = DateTime.Now.ToString("yyyy-MM-dd");
                savedMaps[index].modifiedTimeStamp = currentTime;
            }

            SaveMaps();
        }
Пример #5
0
        public void LoadAndDisplayMap(MapEditorSaveData saveData)
        {
            string saveName = saveData.saveName;

            try
            {
                EditorMapData mapData = MapEditorUtility.LoadMap(saveName);
                tileManager.GenerateMap(mapData);
                mapWidth  = mapData.width;
                mapHeight = mapData.height;
                creatorManager.gameObject.SetActive(false);
                mapEditorMenu.ShowMainMenu(mapData.mapName);
                editedMapName     = saveName;
                referenceSaveData = saveData;
                isMapLoaded       = true;
            }
            catch (System.Exception e)
            {
                Debug.Log("Unable to load map " + e.StackTrace);
            }
        }
Пример #6
0
        public void CreateMap(string name, int width, int height)
        {
            MapEditorSaveData data = new MapEditorSaveData();

            data.mapName = name;
            data.width   = width;
            data.height  = height;
            string currentTime = DateTime.Now.ToString("yyyyMMddHHmmss");

            data.saveName          = name + "_" + currentTime + ".json";
            data.modifiedTimeStamp = currentTime;
            data.createdDate       = DateTime.Now.ToString("yyyy-MM-dd");
            data.modifiedDate      = data.createdDate;
            savedMaps.Add(data);
            SaveMaps();
            //Create default map and save it with the save name
            EditorMapData basicMap = MapEditorUtility.CreateDefaultMap(data);

            MapEditorUtility.SaveMap(data.saveName, basicMap);

            DisplaySavedMaps();
        }
Пример #7
0
        public static EditorMapData CreateDefaultMap(MapEditorSaveData data)
        {
            EditorMapData basicMap = new EditorMapData();

            basicMap.mapName = data.mapName;
            basicMap.width   = data.width;
            basicMap.height  = data.height;
            //Create the default width x height tile with 0 angle
            //Also create it with the default asset for empty tile
            for (int x = 0; x < data.width; x++)
            {
                for (int y = 0; y < data.height; y++)
                {
                    EditorTileData tileData = new EditorTileData();
                    tileData.angle     = 0;
                    tileData.assetCode = DEFAULT_TILE;                                  //HARDCODED This is empty tile
                    tileData.mapXPos   = x + TILE_RADIUS;
                    tileData.mapYPos   = y + TILE_RADIUS;
                    basicMap.listTile.Add(tileData);
                }
            }
            //Create the border for maps
            //Create TOP Border
            for (int x = 0; x < data.width; x++)
            {
                EditorTileData tileData = new EditorTileData();
                tileData.angle     = 0;
                tileData.assetCode = DEFAULT_TILE_BORDER;
                tileData.mapXPos   = x + TILE_RADIUS;
                tileData.mapYPos   = data.height + TILE_RADIUS;
                basicMap.listTile.Add(tileData);
            }

            //Create Bottom Border
            for (int x = 0; x < data.width; x++)
            {
                EditorTileData tileData = new EditorTileData();
                tileData.angle     = 180;
                tileData.assetCode = DEFAULT_TILE_BORDER;
                tileData.mapXPos   = x + TILE_RADIUS;
                tileData.mapYPos   = -TILE_RADIUS;
                basicMap.listTile.Add(tileData);
            }

            //Create Left Border
            for (int y = 0; y < data.height; y++)
            {
                EditorTileData tileData = new EditorTileData();
                tileData.angle     = 90;
                tileData.assetCode = DEFAULT_TILE_BORDER;
                tileData.mapXPos   = -TILE_RADIUS;
                tileData.mapYPos   = y + TILE_RADIUS;
                basicMap.listTile.Add(tileData);
            }

            //Create Right Border
            for (int y = 0; y < data.height; y++)
            {
                EditorTileData tileData = new EditorTileData();
                tileData.angle     = 270;
                tileData.assetCode = DEFAULT_TILE_BORDER;
                tileData.mapXPos   = data.width + TILE_RADIUS;
                tileData.mapYPos   = y + TILE_RADIUS;
                basicMap.listTile.Add(tileData);
            }

            //Create corner border for the map
            for (int x = 0; x < 2; x++)
            {
                for (int y = 0; y < 2; y++)
                {
                    EditorTileData tileData = new EditorTileData();
                    tileData.assetCode = DEFAULT_TILE_CORNER;
                    if (x == 0 && y == 0)                               //LEFT BOTTOM CORNER
                    {
                        tileData.angle   = 90;
                        tileData.mapXPos = -TILE_RADIUS;
                        tileData.mapYPos = -TILE_RADIUS;
                    }
                    else if (x == 0 && y == 1)                          //LEFT TOP CORNER
                    {
                        tileData.angle   = 0;
                        tileData.mapXPos = -TILE_RADIUS;
                        tileData.mapYPos = data.height + TILE_RADIUS;
                    }
                    else if (x == 1 && y == 0)                          //RIGHT BOTTOM CORNER
                    {
                        tileData.angle   = 180;
                        tileData.mapXPos = data.width + TILE_RADIUS;
                        tileData.mapYPos = -TILE_RADIUS;
                    }
                    else
                    {
                        tileData.angle   = 270;                         //RIGHT TOP CORNER
                        tileData.mapXPos = data.width + TILE_RADIUS;
                        tileData.mapYPos = data.height + TILE_RADIUS;
                    }

                    basicMap.listTile.Add(tileData);
                }
            }

            //Basic map doesn't have map feature nor spawners
            return(basicMap);
        }
Пример #8
0
 public void EditMap(MapEditorSaveData saveData)
 {
     MapEditorManager.Instance.LoadAndDisplayMap(saveData);
 }