Exemplo n.º 1
0
        public void PlaceTile(int x, int y)
        {
            List <VoxelTile> aviableTiles = new List <VoxelTile>();

            foreach (VoxelTile tile in TilePrefabs)
            {
                if (CandAppendTile(spawnedTiles[x - 1, y], tile, Direction.Forward) &&
                    CandAppendTile(spawnedTiles[x + 1, y], tile, Direction.Back) &&
                    CandAppendTile(spawnedTiles[x, y + 1], tile, Direction.Right) &&
                    CandAppendTile(spawnedTiles[x, y - 1], tile, Direction.Left))
                {
                    aviableTiles.Add(tile);
                }
            }

            if (aviableTiles.Count == 0)
            {
                // Debug.Log("no aviable");
                return;
            }
            VoxelTile selectedTile = GetRandomTile(aviableTiles);
            // Debug.Log(aviableTiles);
            Vector3 position = transform.position + selectedTile.Voxels * selectedTile.VoxelSize * new Vector3(x, 0, y);

            spawnedTiles[x, y] = Instantiate(selectedTile, position, selectedTile.transform.rotation, this.transform);
        }
Exemplo n.º 2
0
        private bool CandAppendTile(VoxelTile existingTile, VoxelTile tileToAppend, Direction direction)
        {
            if (existingTile == null)
            {
                return(true);
            }
            // Debug.Log("not null");


            if (direction == Direction.Right)
            {
                // Debug.Log("right direction");
                return(Enumerable.SequenceEqual(existingTile.ColorsRight, tileToAppend.ColorsLeft));
            }

            else if (direction == Direction.Left)
            {
                // Debug.Log("left direction");
                return(Enumerable.SequenceEqual(existingTile.ColorsLeft, tileToAppend.ColorsRight));
            }

            else if (direction == Direction.Forward)
            {
                // Debug.Log("forward direction");
                return(Enumerable.SequenceEqual(existingTile.ColorsForward, tileToAppend.ColorsBack));
            }

            else if (direction == Direction.Back)
            {
                // Debug.Log("back direction");
                return(Enumerable.SequenceEqual(existingTile.ColorsBack, tileToAppend.ColorsForward));
            }

            else
            {
                throw new System.ArgumentException("wrong dirrection value, only Vector3.forwad/back/right/left ");
            }
        }