Esempio n. 1
0
        /// <summary>
        /// Loads a Block from a BlockSave and freezes the Block, Block can be loaded with offset
        /// </summary>
        /// <param name="blockSave">The BlockSave to load</param>
        /// <param name="offset">Optionak offset</param>
        /// <returns></returns>
        public GameObject LoadBlock(BlockSave blockSave, Vector3 offset = new Vector3())
        {
            GameObject restoredBlock = BlockGenerator.GenerateBlock(blockSave.GetBlockStructure());

            restoredBlock.transform.position = blockSave.position + offset;
            restoredBlock.transform.rotation = blockSave.rotation;
            restoredBlock.GetComponent <BlockCommunication>().Guid = blockSave.guid;
            restoredBlock.GetComponent <BlockGeometryScript>().TopColliderContainer.layer = 8;
            restoredBlock.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
            restoredBlock.GetComponentInChildren <TapHandler>().AcceptCollisionsAsConnected(true);
            restoredBlock.GetComponentInChildren <GrooveHandler>().AcceptCollisionsAsConnected(true);
            return(restoredBlock);
        }
Esempio n. 2
0
        /// <summary>
        /// Reconstructs the marked Blocks when a marked Block is grabbed by a Hand
        /// </summary>
        /// <param name="grabbedBlock">Which of the marked Block was grabbed</param>
        /// <returns>Return a copy of the grabbed Block</returns>
        public GameObject RebuildMarkedStructure(GameObject grabbedBlock)
        {
            //Remove duplicate GameObjects
            List <GameObject> distinctBlocks = markedBlocks.Distinct().ToList();

            //List to cache copied Blocks
            List <GameObject> copiedBlocks = new List <GameObject>();

            //Dicts to get from original Block Guid to the copied Block Guid and other direction
            Dictionary <Guid, Guid> dictionaryCopyByOriginal = new Dictionary <Guid, Guid>();
            Dictionary <Guid, Guid> dictionaryOriginalByCopy = new Dictionary <Guid, Guid>();

            //Generate a copy of the marked Blocks, but only if a connection from the grabbed Block to the
            //other markedBlock is available. This makes sure that only a coherent Structure is grabbed
            foreach (GameObject block in distinctBlocks)
            {
                if (grabbedBlock.GetComponent <BlockCommunication>().IsIndirectlyAttachedToBlockMarked(block))
                {
                    GameObject copiedBlock = BlockGenerator.GenerateBlock(block.GetComponent <BlockGeometryScript>().blockStructure);
                    copiedBlock.transform.rotation = block.transform.rotation;
                    copiedBlock.transform.position = block.transform.position;
                    copiedBlock.GetComponent <BlockGeometryScript>().SetWallColliderTrigger(true);
                    copiedBlock.GetComponent <BlockGeometryScript>().TapContainer.SetActive(false);
                    copiedBlock.GetComponent <BlockGeometryScript>().GroovesContainer.SetActive(false);
                    dictionaryCopyByOriginal.Add(block.GetComponent <BlockCommunication>().Guid, copiedBlock.GetComponent <BlockCommunication>().Guid);
                    dictionaryOriginalByCopy.Add(copiedBlock.GetComponent <BlockCommunication>().Guid, block.GetComponent <BlockCommunication>().Guid);
                    copiedBlocks.Add(copiedBlock);
                }
            }

            //Connect the copied Blocks, connections are made based on which connections the original Blocks had
            foreach (GameObject copiedBlock in copiedBlocks)
            {
                GameObject originalBlock = BlockManager.GetBlockByGuid(dictionaryOriginalByCopy[copiedBlock.GetComponent <BlockCommunication>().Guid]);

                foreach (BlockContainer blockContainer in originalBlock.GetComponent <BlockCommunication>().ConnectedBlocks)
                {
                    if (distinctBlocks.Exists(tempBlock => blockContainer.BlockRootObject.GetHashCode() == tempBlock.GetHashCode()))
                    {
                        Guid copiedBlockGuid = dictionaryCopyByOriginal[blockContainer.Guid];
                        copiedBlock.GetComponent <BlockCommunication>().ConnectBlocks(copiedBlock, BlockManager.GetBlockByGuid(copiedBlockGuid), blockContainer.ConnectedPinCount, blockContainer.ConnectedOn);
                    }
                }
            }

            Guid grabbedBlockGuidCopy = dictionaryCopyByOriginal[grabbedBlock.GetComponent <BlockCommunication>().Guid];

            //Wait before activate the Groove- and Tap handler until a certain distance is reached from the original Blocks
            StartCoroutine(CheckDistance(copiedBlocks[0], grabbedBlock, copiedBlocks));

            //Return the copy of the original grabbed Block
            return(BlockManager.GetBlockByGuid(grabbedBlockGuidCopy));
        }
        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);
        }