コード例 #1
0
        public override void Load(string _path)
        {
            DestroyChilds();

            SaveHandler.Load(_path, true);

            CTYPES.WORLD_DATA   worldData   = (CTYPES.WORLD_DATA)SaveHandler.deserializedObject;
            CTYPES.WORLD_STATE  state       = (CTYPES.WORLD_STATE)worldData.state;
            CTYPES.TERRAIN_DATA terrainData = worldData.terrainData;

            _chunks = new Chunk[terrainData.nGridsX, terrainData.nGridsY];

            builded      = state.builded;
            texturized   = state.texturized;
            noised       = state.noised;
            stitched     = state.stitched;
            transitioned = state.transitioned;

            Transitioner.Instance.firstTransition = false;

            int i = 0;

            chunksX = terrainData.nGridsX;
            chunksY = terrainData.nGridsY;


            // Load all terrain grid
            for (int x = 0; x < terrainData.nGridsX; ++x)
            {
                for (int y = 0; y < terrainData.nGridsY; ++y)
                {
                    _chunks[x, y] = new Chunk();

                    CTYPES.CHUNK_DATA chunkData = worldData._chunks[i];

                    TerrainData newTerrainData = new TerrainData();
                    UnityEditor.AssetDatabase.CreateAsset(newTerrainData, Paths.SavedWorlds + "Terrains/" + chunkData.name);
                    _chunks[x, y].chunkTerrain      = Terrain.CreateTerrainGameObject(newTerrainData).GetComponent <Terrain>();
                    _chunks[x, y].chunkTerrain.name = chunkData.name;
                    _chunks[x, y].chunkTerrain.transform.position = new Vector3(chunkData.pos.x, chunkData.pos.y, chunkData.pos.z);
                    _chunks[x, y].chunkTerrain.transform.parent   = gameObject.transform;

                    _chunks[x, y].chunkTerrain.terrainData.heightmapResolution = terrainData.resolution.heightMapResolution;
                    _chunks[x, y].chunkTerrain.terrainData.size = new Vector3(terrainData.resolution.terrainSize, terrainData.resolution.terrainHeight, terrainData.resolution.terrainSize);
                    _chunks[x, y].chunkTerrain.terrainData.SetDetailResolution(terrainData.resolution.detailResolution, terrainData.resolution.resolutionPerPatch);
                    _chunks[x, y].chunkTerrain.detailObjectDensity  = terrainData.resolution.detailObjectDensity;
                    _chunks[x, y].chunkTerrain.detailObjectDistance = terrainData.resolution.detailObjectDistance;

                    _chunks[x, y].chunkTerrain.terrainData.SetHeights(0, 0, chunkData.heights);
                    _chunks[x, y].chunkTerrain.gameObject.AddComponent <TerrainManager>().chunk = _chunks[x, y];
                    ++i;
                }
            }

            // Load data like biome, premade and neighbors; for each chunck

            foreach (Chunk chunk in _chunks)
            {
                CTYPES.CHUNK_DATA chunkData = worldData._chunks[0];

                chunk.chunkTerrain.GetComponent <TerrainManager>().Load(chunkData);

                worldData._chunks.RemoveAt(0);
            }

            DestroyImmediate(GameObject.Find(TerrainName));
        }