/// <summary>
        /// Sets the BlockStructure for the Block, recalculated the Groove and Taps and Collider
        /// of the walls
        /// </summary>
        /// <param name="structure">The BlockStructure to set</param>
        public void SetStructure(BlockStructure structure)
        {
            //Reset the BlockStructre in case it wasn't done to ensure no BlockPart is marked visited
            structure.ResetBlockParts();

            //Set the new BlockStructure
            this.blockStructure = structure;

            //Delete the WallCollider in case they were already set, walls need to be recalculated
            RemoveWallCollider();

            //List of BlockParts which make up a wall in the Structure, which are collected inside
            //a list.
            List <List <BlockPart> > allWallsInStrucure = new List <List <BlockPart> >();

            //Search the blockStructure for walls and add them the the list. Search is carried out
            //for all four directions
            SearchWallsInStructure(DIRECTION.UP).ForEach(wall => allWallsInStrucure.Add(wall));
            SearchWallsInStructure(DIRECTION.DOWN).ForEach(wall => allWallsInStrucure.Add(wall));
            SearchWallsInStructure(DIRECTION.LEFT).ForEach(wall => allWallsInStrucure.Add(wall));
            SearchWallsInStructure(DIRECTION.RIGHT).ForEach(wall => allWallsInStrucure.Add(wall));

            //Convert the found walls to a Collider and add them to the block GameObject
            AddWallCollider(allWallsInStrucure);

            //Add the collider in the Top of the Brick
            AddTopCollider();

            //Add the new Tap and Groove Collider to the Block, as the changed as well with the
            //new structure
            AddPinTriggerColliderByStructure(BRICK_PIN_HEIGHT_HALF, TapContainer, "Tap");
            AddPinTriggerColliderByStructure(-BRICK_HEIGHT / 1.1f, GroovesContainer, "Groove");
        }
示例#2
0
        /// <summary>
        /// Generates a new Block from a BlockStructure, places it at (0,2,0)
        /// </summary>
        /// <param name="structure">The Structure to generatoe</param>
        /// <returns>A new Block</returns>
        public GameObject GenerateBlock(BlockStructure structure)
        {
            Material blockMaterial = new Material(material);

            blockMaterial.color = structure.BlockColor;
            GameObject container = new GameObject();

            structure.GetCroppedMatrix();
            float rowMiddlePoint = (float)(structure.RowsCropped - 1) / 2;
            float colMiddlePoint = (float)(structure.ColsCropped - 1) / 2;

            for (int row = 0; row < structure.RowsCropped; row++)
            {
                for (int col = 0; col < structure.ColsCropped; col++)
                {
                    if (structure[row, col] != null)
                    {
                        Vector3    partPosition = new Vector3((rowMiddlePoint - row) * length, 0, (colMiddlePoint - col) * length);
                        GameObject blockPart    = Instantiate(partSizes[structure.BlockSize], partPosition, Quaternion.identity, container.transform);
                        blockPart.SetActive(true);
                    }
                }
            }
            GameObject newBlock = CombineTileMeshes(container);

            newBlock.AddComponent <BlockGeometryScript>().SetStructure(structure);
            newBlock.GetComponent <MeshRenderer>().material = blockMaterial;
            newBlock.transform.position = new Vector3(0, 2, 0);
            newBlock.tag = "Block";
            AddPrecurserComponents(newBlock);
            return(newBlock);
        }
示例#3
0
        public void SetStructure(BlockStructure structure)
        {
            ClearMatrix();
            BlockPart[,] croppedMatrix = structure.GetCroppedMatrix();
            if (structure.RowsCropped > Rows)
            {
                for (; structure.RowsCropped > Rows;)
                {
                    AddRow();
                    handler.UpdateHandlerPosition(Rows, Columns);
                }
            }

            if (structure.ColsCropped > Columns)
            {
                for (; structure.ColsCropped > Columns;)
                {
                    AddCol();
                    handler.UpdateHandlerPosition(Rows, Columns);
                }
            }
            for (int row = 0; row < structure.RowsCropped; row++)
            {
                for (int col = 0; col < structure.ColsCropped; col++)
                {
                    if (croppedMatrix[row, col] != null)
                    {
                        matrix[row][col].GetComponent <Toggle>().isOn = true;
                    }
                }
            }
        }
示例#4
0
        public List <BlockStructure> GetStructures()
        {
            List <BlockStructure> blockStructures = new List <BlockStructure>();

            if (!wasInitalized)
            {
                return(blockStructures);
            }

            for (int row = 0; row < Rows; row++)
            {
                for (int col = 0; col < Columns; col++)
                {
                    Toggle toggle = matrix[row][col].GetComponent <Toggle>();
                    if (toggle.isOn && !matrix[row][col].tag.Equals("Visited"))
                    {
                        BlockStructure structure = new BlockStructure(Rows, Columns);
                        FindAdjacentNodes(structure, row, col);
                        blockStructures.Add(structure);
                    }
                }
            }
            ResetMatrix();
            return(blockStructures);
        }
        public void SpawnBlock()
        {
            List <BlockStructure> blockStructures = matrixController.GetStructures();

            if (blockStructures.Count == 0)
            {
                return;
            }
            BlockStructure blockStructure = blockStructures[0];

            blockStructure.BlockColor = currentBlockColor;
            blockStructure.BlockSize  = currentBlocksize;
            GameObject spawnedBlock = blockGenerator.GenerateBlock(blockStructure);

            blockGenerator.AttachNewBlockToHand(spawnedBlock, hand);
        }
示例#6
0
        private void FindAdjacentNodes(BlockStructure structure, int row, int column)
        {
            if (row >= matrix.Count || column >= matrix[0].Count || row < 0 || column < 0 || matrix[row][column].tag.Equals("Visited"))
            {
                return;
            }

            matrix[row][column].tag = "Visited";

            if (matrix[row][column].GetComponent <Toggle>().isOn)
            {
                structure.AddNode(new BlockPart(row, column), row, column);
                FindAdjacentNodes(structure, row, column - 1);
                FindAdjacentNodes(structure, row, column + 1);
                FindAdjacentNodes(structure, row - 1, column);
                FindAdjacentNodes(structure, row + 1, column);
            }
        }
示例#7
0
 private bool[,] ConvertToBoolMatrix(BlockStructure blockStructure)
 {
     bool[,] convertedMatrix = new bool[blockStructure.RowsCropped, blockStructure.ColsCropped];
     for (int row = 0; row < blockStructure.RowsCropped; row++)
     {
         for (int col = 0; col < blockStructure.ColsCropped; col++)
         {
             if (blockStructure[row, col] == null)
             {
                 convertedMatrix[row, col] = false;
             }
             else
             {
                 convertedMatrix[row, col] = true;
             }
         }
     }
     return(convertedMatrix);
 }
 private void BlockOnChange(BlockStructure structure)
 {
     matrixController.SetStructure(structure);
 }
示例#9
0
        public BlockStructure GetBlockStructure()
        {
            BlockStructure structure = new BlockStructure(Rows, Cols, blockSize, color, matrix);

            return(structure);
        }