private void AddToChunkMap(GrowDecoration decoration) { List <GrowDecoration> list; _mapInChunk.TryGetValue(decoration.ChunkPos, out list); if (list == null) { list = new List <GrowDecoration>(); _mapInChunk.Add(decoration.ChunkPos, list); } list.Add(decoration); }
private void RemoveFromChunkMap(GrowDecoration decoration) { List <GrowDecoration> list; _mapInChunk.TryGetValue(decoration.ChunkPos, out list); if (list != null) { list.Remove(decoration); if (list.Count <= 0) { _mapInChunk.Remove(decoration.ChunkPos); } } }
////把植物种植到场景中 public void buildPlant(Vector3 position, DecorationType type = DecorationType.FaceTree, int aoId = 0, float growTime = 0) { MTBPlantData data = MTBPlantDataManager.Instance.getData((int)type); GrowDecorationParam paras = new GrowDecorationParam(data); if (aoId == 0) { paras.aoId = AoIdManager.instance.getAoId(); } else { paras.aoId = aoId; } paras.growedTime = 0; paras.pos = position; paras.random = _random; int x = ((int)position.x); int z = ((int)position.z); int localx = x % Chunk.chunkWidth; int localz = z % Chunk.chunkDepth; localx = localx < 0 ? localx + Chunk.chunkWidth : localx; localz = localz < 0 ? localz + Chunk.chunkDepth : localz; Chunk chunk = World.world.GetChunk(x, (int)position.y, z); for (int y = (int)position.y + 5; y >= (int)position.y - 5; y--) { BlockType curType = chunk.GetBlock(localx, y, localz).BlockType; if (curType != BlockType.Air && curType != BlockType.StillWater) { paras.loacalPos = new Vector3(localx, y + 1, localz); GrowDecoration decoration = new GrowDecoration(paras); World.world.CheckAndRecalculateMesh(x, y, z, World.world.GetBlock(x, y, z)); _plantMap.Add(paras.aoId, decoration); AddToChunkMap(decoration); return; } } }