public static void Load(string path)
        {
            if (noiseLayers.Count > 0)
            {
                noiseLayers.Clear();
            }

            SaveHandler.Load(path, true);
            List <CTYPES.NOISE_LAYER> loadedObject = (List <CTYPES.NOISE_LAYER>)(SaveHandler.deserializedObject);

            foreach (CTYPES.NOISE_LAYER obj in loadedObject)
            {
                noiseLayers.Add(new NoiseLayer(obj.noiseData, new Vector2(obj.seed.x, obj.seed.y), obj.seedIgnore, obj.islandMode));
            }

            Next();
        }
        private void UpdatePresets()
        {
            presets = ResourceLoader.LoadAllFilesIn(Paths.NoisePresets);

            SaveHandler.Load(Paths.NoisePresets + presets[preset_selected].Name, false);
            presetData = (float[])(SaveHandler.deserializedObject);
            presetName = presets[preset_selected].Name;

            if (manager == null)
            {
                return;
            }

            noiseLayer.noiseData.type        = (eNoise)(presetData[0]);
            noiseLayer.noiseData.presetName  = presetName;
            noiseLayer.noiseData.octaves     = (int)(presetData[1]);
            noiseLayer.noiseData.persistence = presetData[2];
            noiseLayer.noiseData.lacunarity  = presetData[3];
            noiseLayer.noiseData.frequency   = presetData[4];
            noiseLayer.noiseData.size        = presetData[5];
        }
Exemplo n.º 3
0
        public static void Load(string path)
        {
            SaveHandler.Load(path, true);
            grassGenerators = (List <GrassGenerator>)SaveHandler.deserializedObject;

            foreach (GrassGenerator generator in grassGenerators)
            {
                foreach (GrassDataLayer layer in generator.grassLayers)
                {
                    layer.detailTexture    = (Texture2D)UnityEditor.AssetDatabase.LoadAssetAtPath(layer.detailTexturePath, typeof(Texture2D));
                    layer.detailMesh       = (GameObject)UnityEditor.AssetDatabase.LoadAssetAtPath(layer.detailMeshPath, typeof(GameObject));
                    layer.details.dryColor = new Color(layer.details.cdryColor.r,
                                                       layer.details.cdryColor.g,
                                                       layer.details.cdryColor.b,
                                                       layer.details.cdryColor.a);
                    layer.details.healthyColor = new Color(layer.details.chealthyColor.r,
                                                           layer.details.chealthyColor.g,
                                                           layer.details.chealthyColor.b,
                                                           layer.details.chealthyColor.a);
                }
            }
        }
        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));
        }