/// <summary> /// Builds the tile /// </summary> /// <param name="block">The block that holds the tile</param> /// <param name="cubxel">The cube position of the tile</param> /// <returns>Self</returns> public CubeTile Build(CubeBlock block, Cubxel cubxel) { Cubxel = cubxel; Block = block; transform.parent = block.transform; transform.localPosition = ((Vector3)cubxel.Orientation.GetCoefficient()) * 0.5f; transform.localEulerAngles = cubxel.Orientation.GetRotation(); name = string.Format("tile_o{0}_x{1}_y{2}_z{3}", cubxel.Orientation, cubxel.Position.x, cubxel.Position.y, cubxel.Position.z); return(this); }
/// <summary> /// Builds the cube from its <see cref="CubeSettings"/> /// </summary> /// <returns>Self</returns> public Cube Build() { if (Built) { throw new Exception("The Cube has been built already"); } name = Settings.Name; // Build Blocks blocks = new CubeBlock[Size, Size, Size]; for (int x = 0; x < Size; x++) { for (int y = 0; y < Size; y++) { for (int z = 0; z < Size; z++) { // Check if at least one is on the side if (x == 0 || y == 0 || z == 0 || x == Size - 1 || y == Size - 1 || z == Size - 1) { blocks[x, y, z] = CubeBlock.Create(this, new Vector3Int(x, y, z)); } } } } // Build Grids grids = GridsContainer.GetComponentsInChildren <CubeGrid>() .GroupBy(grid => grid.Orientation) .ToDictionary(group => group.Key, group => group.First()); if (grids.Count != 6) { throw new Exception(string.Format("Invalid amount of grid found: {0}/6", grids.Count)); } foreach (CubeGrid grid in grids.Values) { grid.Build(this); } Built = true; CubeEvents.OnCubeBuilt.Invoke(this); return(this); }
/// <summary> /// Creates a block for the provided <see cref="Cube"/> at the provided /// 3D grid position. /// </summary> /// <param name="cube">The parent cube</param> /// <param name="position">The 3D grid position</param> /// <returns>Self</returns> public static CubeBlock Create(Cube cube, Vector3Int position) { // Create Object GameObject obj = new GameObject(); CubeBlock cubeBlock = obj.AddComponent <CubeBlock>(); cubeBlock.Position = position; cubeBlock.name = string.Format("block_x{0}_y{1}_z{2}", position.x, position.y, position.z); cubeBlock.transform.parent = cube.BlocksContainer; cubeBlock.transform.localPosition = position; // Create Tiles cubeBlock.tiles = new Dictionary <Orientation, CubeTile>(); Cubxel.GetPossibleCubxels(position, cube.Size) .ForEach(cubxel => { CubeTile tile = Instantiate(cube.Settings.Theme.GetRandomTile(), cubeBlock.transform) .Build(cubeBlock, cubxel); cubeBlock.tiles.Add(cubxel.Orientation, tile); }); return(cubeBlock); }