public void InitTrunks() { trunks = new VoxelTrunk[worldDimension.x, worldDimension.y, worldDimension.z]; var childCount = transform.childCount; for (int i = 0; i < childCount; i++) { Destroy(transform.GetChild(0).gameObject); } Vector3 trunkSize = Vector3.Scale(trunkCellSize, trunkDimension.ToVector3()); for (int i = 0; i < worldDimension.x; i++) { for (int j = 0; j < worldDimension.y; j++) { for (int k = 0; k < worldDimension.z; k++) { var trunkObj = new GameObject("trunk_" + i + "_" + j + "_" + k); var coord = new Int3(i, j, k); trunkObj.transform.SetParent(transform); trunkObj.transform.localPosition = Vector3.Scale(trunkSize, coord.ToVector3()); var trunk = trunkObj.AddComponent <VoxelTrunk>(); trunk.ownerEntity = this; trunk.coordinate = coord; trunk.dimension = trunkDimension; trunk.cellSize = trunkCellSize; trunk.material = material; trunkObj.tag = "Voxel"; trunks[i, j, k] = trunk; } } } }
private Vector3 GetCellOriginPos(Int3 coord) { return(Vector3.Scale(data.cellSize, coord.ToVector3())); }