/// <summary>
 /// Adds an entity to this chunk structure.
 /// The entities position should be defined locally, as global modification is done here
 /// </summary>
 /// <param name="entity"></param>
 public void AddEntity(Entity entity)
 {
     if (Entities == null)
     {
         Entities = new List <Entity>();
     }
     entity.MoveEntity(entity.Position + BaseTile.AsVector3());
     Entities.Add(entity);
 }
예제 #2
0
    public List <ChunkData> ToChunkData()
    {
        List <ChunkData> chunks = new List <ChunkData>(ChunkSize.x * ChunkSize.z);

        foreach (List <WorldObjectData> map in ObjectMaps)
        {
            if (map != null)
            {
                foreach (WorldObjectData obj in map)
                {
                    if (obj != null)
                    {
                        obj.SetPosition(obj.Position + BaseTile.AsVector3());
                    }
                }
            }
        }
        for (int x = 0; x < ChunkSize.x; x++)
        {
            for (int z = 0; z < ChunkSize.z; z++)
            {
                float     height   = ChunkBases == null ? 0 : ChunkBases[x, z].Height;
                ChunkData chunk_xz = new ChunkData(BaseChunk.x + x, BaseChunk.z + z, TileMaps[x, z], true, height, HeightMaps[x, z], ObjectMaps[x, z]);
                ChunkVoxels[x, z].HasBoundryVoxels = true;
                chunk_xz.SetVoxelData(ChunkVoxels[x, z]);
                chunks.Add(chunk_xz);
                if (DEBUG)
                {
                    int count = ObjectMaps[x, z] == null ? 0 : ObjectMaps[x, z].Count;
                    if (count != 0)
                    {
                        Debug.Log("Chunk " + (x + BaseChunk.x) + "," + (z + BaseChunk.z) + " generated, has " + count + " objects");
                    }
                }
            }
        }
        OnCreate();
        return(chunks);
    }