private void ProcessWorldData(WorldManager worldManager)
    {
        // stores the random generated number for Perlin Noise offset for both X and Z value
        worldData.chunkPerlinOffsetX = worldManager.chunkPerlinOffsets.chunkOffsetX;
        worldData.chunkPerlinOffsetZ = worldManager.chunkPerlinOffsets.chunkOffsetZ;

        // stores which chunk was the central one for player
        worldData.centralChunkX = worldManager.currentCenterChunkPos.x;
        worldData.centralChunkZ = worldManager.currentCenterChunkPos.z;

        // stores all information about all chunks and their cubes
        foreach (KeyValuePair <Vector3, ChunkGenerator> chunk in worldManager.chunkTable)
        {
            WorldData.ChunkData chunkData = new WorldData.ChunkData();
            chunkData.chunkXPosition = chunk.Key.x;
            chunkData.chunkZPosition = chunk.Key.z;
            foreach (KeyValuePair <Vector3, CubeEditor> cube in chunk.Value.cubeEditorTable)
            {
                chunkData.cubePositionsX.Add(cube.Key.x);
                chunkData.cubePositionsY.Add(cube.Key.y);
                chunkData.cubePositionsZ.Add(cube.Key.z);
                chunkData.cubeTypeNames.Add(cube.Value.currentCubeType.cubeTypeName);
            }
            worldData.chunkData.Add(chunkData);
        }

        // stores information about all destroyed chunks
        foreach (KeyValuePair <Vector3, WorldData.ChunkData> chunk in worldManager.destroyedChunkData)
        {
            worldData.destroyedChunkData.Add(chunk.Value);
        }
    }
Exemple #2
0
    // Destroys chunk, then adds it's data into destroyed chunk List variable
    private IEnumerator DestroyChunk(Vector3 chunkPos)
    {
        WorldData.ChunkData destroyedChunk = new WorldData.ChunkData();

        destroyedChunk.chunkXPosition = chunkPos.x;
        destroyedChunk.chunkZPosition = chunkPos.z;

        foreach (KeyValuePair <Vector3, CubeEditor> cubeData in chunkTable[chunkPos].cubeEditorTable)
        {
            destroyedChunk.cubePositionsX.Add(cubeData.Key.x);
            destroyedChunk.cubePositionsY.Add(cubeData.Key.y);
            destroyedChunk.cubePositionsZ.Add(cubeData.Key.z);
            string cubeTypeName = chunkTable[chunkPos].ProcessCubeByName(cubeData.Value.GetCubeType().cubeTypeName).cubeTypeName;
            destroyedChunk.cubeTypeNames.Add(cubeTypeName);
        }

        if (!destroyedChunkData.ContainsKey(chunkPos))
        {
            destroyedChunkData.Add(chunkPos, destroyedChunk);
        }

        Destroy(chunkTable[chunkPos].gameObject);
        yield return(null);

        chunkTable.Remove(chunkPos);
    }
Exemple #3
0
 // Gets called whenever there is stored data for the chunk
 public IEnumerator GenerateLoadedChunk(WorldData.ChunkData chunkData)
 {
     for (int i = 0; i < chunkData.cubePositionsX.Count; i++)
     {
         Vector3  cubePos  = new Vector3(chunkData.cubePositionsX[i], chunkData.cubePositionsY[i], chunkData.cubePositionsZ[i]);
         CubeType cubeType = ProcessCubeByName(chunkData.cubeTypeNames[i]);
         CreateCube(basicCubePrefab, cubePos, cubeType);
         yield return(new WaitForSeconds(generationSeconds));
     }
     isLoaded = true;
 }
Exemple #4
0
    // Creates chunk from save file data
    public IEnumerator CreateChunkByData(Vector3 chunkPos, WorldData.ChunkData chunkData)
    {
        ChunkGenerator newChunk = new ChunkGenerator();

        newChunk = Instantiate(chunkGeneratorPrefab, chunkPos, Quaternion.identity, transform);
        newChunk.UpdateName();

        if (!chunkTable.ContainsKey(chunkPos))
        {
            chunkTable.Add(chunkPos, newChunk);
            newChunk.SetChunkSetup();
            newChunk.SetBoxCollider();
            yield return(newChunk.GenerateLoadedChunk(chunkData));

            yield return(null);
        }
    }