Esempio n. 1
0
        /// <summary>
        /// Builds the grid.
        /// </summary>
        /// <param name="cube">The <see cref="Cube"/> that owns the grid</param>
        /// <returns>Self</returns>
        public CubeGrid Build(Cube cube)
        {
            if (Built)
            {
                throw new Exception("The grid has been built already");
            }

            // Configure Canvas
            RectTransform canvasRectTransform = canvas.GetComponent <RectTransform>();

            canvasRectTransform.sizeDelta  = Vector2.one * cube.Size;
            canvas.worldCamera             = Camera.main;
            canvas.transform.localPosition = relativePosition.Convert(Vector3Int.zero, max: cube.Size) - (Vector3.one / 2);

            // Configure layout
            gridLayout.constraintCount = cube.Size;

            // Create cells
            cells = new CubeGridCell[cube.Size, cube.Size];
            for (int x = 0; x < cube.Size; x++)
            {
                for (int y = 0; y < cube.Size; y++)
                {
                    Cubxel cubxel = new Cubxel(gridToWorld.Convert(new Vector3Int(x, y, 0), max: cube.Size - 1), Orientation);
                    cells[x, y] = Instantiate(cube.Settings.Theme.CellModel, gridLayout.transform).Build(cubxel);
                }
            }

            Built = true;

            return(this);
        }
Esempio n. 2
0
        public override bool Equals(object obj)
        {
            if (!(obj is Cubxel))
            {
                return(false);
            }
            Cubxel other = (Cubxel)obj;

            return(Position.Equals(other.position) && orientation.Equals(other.orientation));
        }
Esempio n. 3
0
        /// <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);
        }
Esempio n. 4
0
        public CubeGridCell Build(Cubxel cubxel)
        {
            if (Built)
            {
                throw new Exception("The cell has been built already");
            }

            Cubxel = cubxel;

            Built = true;

            return(this);
        }
Esempio n. 5
0
        /// <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);
        }
Esempio n. 6
0
 /// <summary>
 /// Gets the <see cref="CubeBlock"/> which is associated to provided <see cref="Cubxel"/>
 /// </summary>
 /// <param name="cubxel">The cube position of the desired block</param>
 /// <returns>A <see cref="CubeBlock"/> or null</returns>
 public CubeBlock GetBlock(Cubxel cubxel)
 {
     return(GetBlock(cubxel.Position));
 }
Esempio n. 7
0
 /// <summary>
 /// Gets the <see cref="CubeTile"/> which is associated to provided <see cref="Cubxel"/>
 /// </summary>
 /// <param name="cubxel">The cube position of the desired tile</param>
 /// <returns>A <see cref="CubeTile"/> or null</returns>
 public CubeTile GetTile(Cubxel cubxel)
 {
     return(GetBlock(cubxel)?.GetTile(cubxel.Orientation));
 }
Esempio n. 8
0
 public static void SetToCubxel(this Transform transform, Cubxel cubxel)
 {
     transform.position    = cubxel.GetWorldPosition();
     transform.eulerAngles = cubxel.GetWorldEulerAngles();
 }