public void LoadSubworldChunks(Subworld sub) { UnloadAllChunks(); InSubworld = true; foreach (ChunkData c in sub.SubworldChunks) { int x = c.X; int z = c.Z; GameObject chunkObject = Instantiate(ResourceManager.ChunkPrefab);; //We create a new empty gameobject for the chunk chunkObject.transform.parent = transform; chunkObject.name = "sw" + sub.SubworldID + "_" + c.X + "_" + c.Z; LoadedChunk loadedChunk = chunkObject.AddComponent <LoadedChunk>(); ChunkData[] neigh = { sub.GetChunkSafe(x, z + 1), sub.GetChunkSafe(x + 1, z + 1), sub.GetChunkSafe(x + 1, z) }; loadedChunk.SetChunkData(c, neigh); SubworldChunks.Add(new Vec2i(x, z), loadedChunk); } }
/// <summary> /// Returns the 3 neighbors for this chunk as an array /// <list type="bullet"> /// <item>ChunkData[0] = Chunk[x , z + 1]</item> /// <item>ChunkData[1] = Chunk[x + 1, z + 1]</item> /// <item>ChunkData[2] = Chunk[x + 1, z ]</item> /// </list> /// Checks if a subworld is currently loaded. If it is, then we /// find chunks by accessing <see cref="CurrentSubworld.GetChunkSafe"/> /// </summary> /// <param name="c">Position at which to find neigbors</param> /// <returns></returns> public ChunkData[] GetNeighbors(Vec2i c) { if (InSubworld) { return(new ChunkData[] { CurrentSubworld.GetChunkSafe(c.x, c.z + 1), CurrentSubworld.GetChunkSafe(c.x + 1, c.z + 1), CurrentSubworld.GetChunkSafe(c.x + 1, c.z), }); } else if (c.x > 0 && c.x < World.WorldSize - 2 && c.z > 0 && c.z < World.WorldSize - 2) { //TODO - get this data from the CR manager return(new ChunkData[] { GetChunk(c.x, c.z + 1, true), GetChunk(c.x + 1, c.z + 1, true), GetChunk(c.x + 1, c.z, true), /* GetChunk(c.x+1, c.z - 1, false), * GetChunk(c.x, c.z-1, false), GetChunk(c.x-1, c.z-1, false) , * GetChunk(c.x-1,c.z, false), GetChunk(c.x-1, c.z+1 , false)*/}); } else { return(null); } }