예제 #1
0
        //
        public void setLevelData(LevelStruct level)
        {
            _levelId = level.id;

            GameObject levelChunk = _assetFactory.createVoxelChunkClone();

            levelChunk.transform.parent        = _trfmPlaceholder;
            levelChunk.transform.localScale    = new Vector3(Globals.LEVEL_WIDTH, Globals.LEVEL_HEIGHT, Globals.LEVEL_DEPTH);
            levelChunk.transform.localPosition = new Vector3(Globals.LEVEL_WIDTH / 2, Globals.LEVEL_HEIGHT / 2, Globals.LEVEL_DEPTH / 2);

            _chunkBounds = levelChunk.GetComponent <BoxCollider>().bounds;
            Debug.Log("bounds for level id " + _levelId + ": " + _chunkBounds);

            int       i;
            Transform txt;
            TextMesh  textMesh;

            for (i = 1; i <= 6; ++i)
            {
                txt = levelChunk.transform.Find("txt" + i.ToString());
                if (txt != null)
                {
                    textMesh = txt.GetComponent <TextMesh> ();
                    if (textMesh != null)
                    {
                        textMesh.text = "Level id: " + _levelId.ToString() + "\n" + "'" + level.name + "'";
                    }
                }
            }
        }
        public void init(string json)
        {
            _numLevels = 0;

            if (LevelEditor.Instance.levelListJson == null)
            {
                return;
            }

            JSONNode data = JSON.Parse(json);             //LevelEditor.Instance.levelListJson.text);

            if (data == null || data ["levels"] == null)
            {
                return;
            }

            JSONArray levels = (JSONArray)data ["levels"];

            _numLevels    = levels.Count;
            _levelByIndex = new LevelStruct[_numLevels];

            int i;

            for (i = 0; i < _numLevels; ++i)
            {
                JSONNode    level = levels [i];
                LevelStruct ls    = new LevelStruct(int.Parse(level["id"]), level["name"], level["filename"], int.Parse(level["x"]), int.Parse(level["y"]), int.Parse(level["z"]));
                _levelByIndex [i] = ls;
                saveLevelInfo(ls);
                MainMenu.Instance.addLevelToMenu(level ["filename"]);
            }
        }
        //
        public Dictionary <int, LevelChunk> createLevelChunks()
        {
            Dictionary <int, LevelChunk> chunks = new Dictionary <int, LevelChunk> ();

            int i;

            for (i = 0; i < _numLevels; ++i)
            {
                LevelStruct level = _levelByIndex [i];

                GameObject gameObject = AssetFactory.Instance.createVoxelsLevelContainer();
                gameObject.name = "LevelChunk_" + level.id.ToString();

                Vector3 chunkPos = new Vector3(level.x * Globals.LEVEL_WIDTH, -level.y * Globals.LEVEL_HEIGHT, level.z * Globals.LEVEL_DEPTH);
                gameObject.transform.position = chunkPos;

                LevelChunk chunk = gameObject.AddComponent <LevelChunk> ();
                chunk.init(chunkPos);
                chunk.setLevelData(level);

                chunks.Add(level.id, chunk);
            }

            return(chunks);
        }
        //
        public void loadLevelByIndex(int index)
        {
            if (index < 0 || index >= _levelByIndex.Length)
            {
                AppController.Instance.showPopup(PopupMode.Notification, "Error", Globals.errorLevelFileInvalidIndex);
            }

            LevelStruct ls = _levelByIndex [index];

            /*if (ls.jsonData == null || ls.jsonData == "") {
             *      TextAsset levelAsset = Resources.Load<TextAsset>("Data/Levels/"+ls.filename);
             *      if (levelAsset != null) {
             *              string json = levelAsset.text;
             *              ls.jsonData = json;
             *              _levelByIndex [index] = ls;
             *      }
             * }*/

            if (ls.jsonData == null || ls.jsonData == "")
            {
                AppController.Instance.showPopup(PopupMode.Notification, "Error", Globals.warningInvalidFileFormat.Replace("%1", ls.filename));
            }
            else
            {
                LevelData.Instance.loadLevelFromJson(ls.jsonData);
            }
        }
 private void saveLevelInfo(LevelStruct ls)
 {
     /*if (ls.id != -1) {
      *      if (!_levelMapById.ContainsKey (ls.id)) {
      *              _levelMapById.Add (ls.id, ls);
      *      }
      * }
      *
      * if (!_levelMapByPos.ContainsKey (ls.x)) {
      *      _levelMapByPos.Add(ls.x, new Dictionary<int, Dictionary<int, LevelStruct>> ());
      * }
      *
      * if (!_levelMapByPos[ls.x].ContainsKey (ls.y)) {
      *      _levelMapByPos[ls.x].Add(ls.y, new Dictionary<int, LevelStruct> ());
      * }
      *
      * if (!_levelMapByPos[ls.x][ls.y].ContainsKey (ls.z)) {
      *      _levelMapByPos[ls.x][ls.y].Add(ls.z, ls);
      * }*/
 }
        //
        public void setLevelJson(int id, string json)
        {
            int i;

            for (i = 0; i < _numLevels; ++i)
            {
                if (_levelByIndex [i].id == id)
                {
                    LevelStruct level = _levelByIndex [i];
                    level.jsonData    = json;
                    _levelByIndex [i] = level;
                    break;
                }
            }

            /*if (_levelMapById.ContainsKey (id)) {
             *      LevelStruct level = _levelMapById [id];
             *      level.jsonData = json;
             *      _levelMapById [id] = level;
             * }*/
        }