コード例 #1
0
ファイル: Database.cs プロジェクト: marinedzl/MOBADemo
        public void LoadMap(int id, Game game)
        {
            string path = string.Format("mapdata/{0}.json", id.ToString());

            byte[]   bytes     = m_context.LoadBytesFromFile(path);
            string   jsonText  = System.Text.Encoding.Default.GetString(bytes);
            JSONNode root      = JSON.Parse(jsonText);
            JSONNode campsNode = root["Camps"];

            Camp[] camps = new Camp[campsNode.Count];
            for (int i = 0; i < campsNode.Count; i++)
            {
                Camp camp = new Camp();
                camps[i] = camp;
                JSONNode campNode = campsNode[i];
                camp.born = JsonToPosition(campNode["Born"]);
                JSONNode spawnersNode = campNode["Spawners"];
                if (spawnersNode != null)
                {
                    camp.spawners = new Camp.Spawner[spawnersNode.Count];
                    for (int j = 0; j < spawnersNode.Count; j++)
                    {
                        Position position = JsonToPosition(spawnersNode[j]);
                        int      unit     = 10101;
                        float    interval = 30;
                        camp.spawners[j] = new Camp.Spawner(position, unit, interval);
                    }
                }
                JSONNode towersNode = campNode["Towers"];
                if (towersNode != null)
                {
                    camp.towers = new Camp.Tower[towersNode.Count];
                    for (int j = 0; j < towersNode.Count; j++)
                    {
                        Camp.Tower tower = new Camp.Tower();
                        camp.towers[j] = tower;
                        tower.position = JsonToPosition(towersNode[j]);
                    }
                }
            }
            game.InitCamps(camps);
        }