コード例 #1
0
        public static void LoadMapFromJson(this MapGrid mapGrid, string fileName, Dictionary <Deployable.DeployableType, Deployable> deployableDictionary)
        {
            String path = MapEditorMain.Instance.FileDirectory + fileName + ".json";

            if (!File.Exists(path))
            {
                Debug.LogError("File Not Exist:" + path);
                return;
            }

            mapGrid.ClearEntireGrid();

            string jsonString;

            using (StreamReader sr = new StreamReader(path))
            {
                jsonString = sr.ReadToEnd();
            }
            Dictionary <string, object> json = MiniJSON.Json.Deserialize(jsonString) as Dictionary <string, object>;

            // walkable data
            List <object> walkable = (List <object>)json ["walkable"];

            for (int i = 0; i < walkable.Count; i++)
            {
                List <object> point = (List <object>)walkable [i];
                IntVector2    index = new IntVector2(Convert.ToInt32(point [0]), Convert.ToInt32(point [1]));
                mapGrid.DeployIfPossible(index, deployableDictionary[Deployable.DeployableType._Walkable]);
            }

            // buildable data
            List <object> buildable = (List <object>)json ["buildable"];

            for (int i = 0; i < buildable.Count; i++)
            {
                List <object> point = (List <object>)buildable [i];
                IntVector2    index = new IntVector2(Convert.ToInt32(point [0]), Convert.ToInt32(point [1]));
                mapGrid.DeployIfPossible(index, deployableDictionary[Deployable.DeployableType._Buildable]);
            }

            // monster start point
            List <object> monster = (List <object>)json ["monster"];

            for (int i = 0; i < monster.Count; i++)
            {
                List <object> point = (List <object>)monster [i];
                IntVector2    index = new IntVector2(Convert.ToInt32(point [0]), Convert.ToInt32(point [1]));
                mapGrid.DeployIfPossible(index, deployableDictionary[Deployable.DeployableType._Monster]);
            }

            // player start point
            List <object> player = (List <object>)json ["player"];

            for (int i = 0; i < player.Count; i++)
            {
                List <object> point = (List <object>)player [i];
                IntVector2    index = new IntVector2(Convert.ToInt32(point [0]), Convert.ToInt32(point [1]));
                mapGrid.DeployIfPossible(index, deployableDictionary[Deployable.DeployableType._Player]);
            }
        }
コード例 #2
0
        private void DragCheck()
        {
            // If click over a UI element, return
            if (EventSystem.current.IsPointerOverGameObject())
            {
                return;
            }

            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            GameMapGrid.DeployIfPossible(ray, objectToDeploy);
        }