/* */ public InstancedMeshInfo MeshChunkItems(Vector3Int chunkIndex, ChunkLayer <Block> chunkLayer) { InstancedMeshInfo instancedMeshInfo = new InstancedMeshInfo(modelTypeCount); Chunk <Block> chunk = chunkLayer.GetChunk(chunkIndex); Vector3 chunkStart = chunkIndex.Multiply(chunkSettings.ChunkWorldLen); for (int x = 0; x < chunkSL; x++) { for (int y = 0; y < chunkSL; y++) { for (int z = 0; z < chunkSL; z++) { Vector3Int indexInChunk = new Vector3Int(x, y, z); Vector3 position = new Vector3(x, y, z) * chunkSettings.VoxelSize + chunkStart; Block block = chunk.GetVoxel(indexInChunk); int blockType = block.blockType; TechnicalBlock technicalBlock = block.technicalBlock; if (technicalBlock != null) { TechnicalBlock.ModelInfo[] itemMeshes = technicalBlock.GetDynamicMesh(); for (int i = 0; i < itemMeshes.Length; i++) { if (itemMeshes[i].modelType != 0) { Matrix4x4 transform = itemMeshes[i].transform; transform = Matrix4x4.Translate(position) * transform; instancedMeshInfo.AddInstance(transform, itemMeshes[i].modelType); } } } } } } return(instancedMeshInfo); }
public InstancedMeshInfo MeshChunkBlocks(Vector3Int chunkIndex, ChunkLayer <Block> chunkLayer) { InstancedMeshInfo instancedMeshInfo = new InstancedMeshInfo(modelTypeCount); Chunk <Block> chunk = chunkLayer.GetChunk(chunkIndex); Vector3 chunkStart = chunkIndex.Multiply(chunkSettings.ChunkWorldLen); for (int x = 0; x < chunkSL; x++) { for (int y = 0; y < chunkSL; y++) { for (int z = 0; z < chunkSL; z++) { Vector3Int indexInChunk = new Vector3Int(x, y, z); Vector3 position = new Vector3(x, y, z) * chunkSettings.VoxelSize + chunkStart; Block block = chunk.GetVoxel(indexInChunk); TechnicalBlock technicalBlock = block.technicalBlock; if (technicalBlock != null) { instancedMeshInfo.AddModelInfos(technicalBlock.GetStaticMesh(), Matrix4x4.Translate(position) * technicalBlock.localTransform * Matrix4x4.Scale(Vector3.one * 0.5f)); } } } } return(instancedMeshInfo); }
private void FixedUpdate() { a = !a; if (Time.time > 1.31f) { //MeshItems(); if (true) { Block block = techWorldMono.GetElement(Vector3.one * 1.5f + Vector3.up * 0); if (block.technicalBlock is Pipe) { TechnicalBlock spawner = block.technicalBlock; if (spawner.CanTake(1, spawner.ForwardDirection)) { if (a) { spawner.Take(1, spawner.ForwardDirection); //if (first) a = !a; } else { spawner.Take(2, spawner.ForwardDirection); //if (first) a = !a; } a = !a; } } } } }
void OutputToNeighbourPipes(TechnicalBlock[] neighbours) { if (storage.Count == 0) { return; } int nextNeighbourPriorityIndex = 0; for (int i = 0; i < 6; i++) { int neighbourIndex = (neighbourPriorityIndex + i) % 6; TechnicalBlock technicalBlock = neighbours[neighbourIndex]; if (technicalBlock is Pipe) { Pipe pipe = (Pipe)technicalBlock; Vector3Int direction = requestedNeighbours[neighbourIndex]; if (CanOutput(direction) != 0 && pipe.CanTake(CanOutput(direction), direction)) { pipe.Take(Output(direction), direction); nextNeighbourPriorityIndex = (neighbourIndex + 1) % 6; } } } neighbourPriorityIndex = nextNeighbourPriorityIndex; }
public override void UpdateNeighbour(float deltaTime, TechnicalBlock[] neighbours) { if (neighbours.Length > 0) { TechnicalBlock target = neighbours[0]; TryTransfer(this, target, ForwardDirection); if (neighbours[1] is Pipe == false) // behaves like output pipe in condition { TryTransfer(neighbours[1], this, ForwardDirection); } } }
public static void TryTransfer(TechnicalBlock source, TechnicalBlock destination, Vector3Int entryDirection) { if (source != null && destination != null) { int output = source.CanOutput(entryDirection); if (output != 0) { if (destination != null && destination.CanTake(output, entryDirection)) { source.Output(entryDirection); destination.Take(output, entryDirection); } } } }