Esempio n. 1
0
        /// <summary>
        /// Loaded a Block from an BlockSave, but with a new Guid. Block can be loaded with an offset. Used for loading prefabs
        /// </summary>
        /// <param name="blockSave">The BlockSave to load</param>
        /// <param name="offset">Optional offset</param>
        /// <returns></returns>
        public GameObject LoadBlockWithNewGuid(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 <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
            restoredBlock.GetComponentInChildren <TapHandler>().AcceptCollisionsAsConnected(true);
            restoredBlock.GetComponentInChildren <GrooveHandler>().AcceptCollisionsAsConnected(true);
            return(restoredBlock);
        }
Esempio n. 2
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. 3
0
        /// <summary>
        /// Connect all Blocks together, information for which Block to connect is in BlockSave, also resets AcceptCollisionsAsConnected
        /// to false again, as the physical connection makeing is finshed.
        /// </summary>
        /// <param name="blockSave">Holds the connections</param>
        /// <param name="saveGame">Holds guids</param>
        public void ConnectBlocks(BlockSave blockSave, SaveGame saveGame = null)
        {
            GameObject block = BlockManager.GetBlockByGuid(blockSave.guid);

            //Reset the Groove- and Tap Handler
            block.GetComponentInChildren <TapHandler>().AcceptCollisionsAsConnected(false);
            block.GetComponentInChildren <GrooveHandler>().AcceptCollisionsAsConnected(false);

            foreach (ConnectedBlockSerialized connection in blockSave.connectedBlocks)
            {
                //Only connect the Block if no SaveGame was provided or if the other Block to connect to is found in the SaveGame.
                //This is to prevent Prefabs from connecting to non-Prefab Blocks when loaded
                //Floorplates are not included in the Savegame, so they are check manually by the Guid
                if (saveGame == null || saveGame.GetBlockSaveByGuid(connection.guid) != null || connection.guid.ToString().StartsWith("aaaaaaaa"))
                {
                    block.GetComponent <BlockCommunication>().ConnectBlocks(block, BlockManager.GetBlockByGuid(connection.guid), connection.connectedPins, connection.connectedOn);
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Loads a BlockSave from a given HistoryObject and SaveGame
        /// </summary>
        /// <param name="save">The SaveGame containing the BlockSave</param>
        /// <param name="historyObject">The HistoryObject to load</param>
        public void LoadBlock(SaveGame save, HistoryObject historyObject)
        {
            BlockSave blockSave = save.GetBlockSaveByGuid(historyObject.guid);

            LoadBlock(blockSave);
        }