Beispiel #1
0
        public static void Deserialize(byte[] data)
        {
            //Clear scene
            MegaMeshManager.ClearReferences();
            BehaviorManager.ClearAllLists();
            foreach (ObjectInfo objectInfo in GameObject.FindObjectsOfType <ObjectInfo>())
            {
                GameObject.Destroy(objectInfo.gameObject);
            }

            SavedWorld world;

            //Deserialize the data into a SavedWorld
            using (MemoryStream mem = new MemoryStream(Compressor.Decompress(data)))
            {
                world = (SavedWorld) new BinaryFormatter().Deserialize(mem);
            }

            //Run on Unity thread
            MulTUNG.SynchronizationContext.Send(_ =>
            {
                //Load all the objects from the save
                foreach (var item in world.TopLevelObjects)
                {
                    SavedObjectUtilities.LoadSavedObject(item);
                }

                SaveManager.RecalculateAllClustersEverywhereWithDelay();
            }, null);
        }
    public static void LoadAll()
    {
        MegaMeshManager.ClearReferences();
        BehaviorManager.AllowedToUpdate = false; // don't let circuitry updates f**k us up while we're loading the game
        BehaviorManager.ClearAllLists();

        // remove all existing stuff in the world before loading the new stuff
        ObjectInfo[] saveobjects = UnityEngine.Object.FindObjectsOfType <ObjectInfo>(); // all active instances of SaveObject
        foreach (ObjectInfo save in saveobjects)
        {
            UnityEngine.Object.Destroy(save.gameObject);
        }

        List <SavedObjectV2> TopLevelObjects = (List <SavedObjectV2>)FileUtilities.LoadFromFile(RegionsPath, "world.tung");

        if (TopLevelObjects != null)
        {
            foreach (SavedObjectV2 save in TopLevelObjects)
            {
                SavedObjectUtilities.LoadSavedObject(save);
            }
        }

        RecalculateAllClustersEverywhereWithDelay();

        try
        {
            LoadPlayerPosition();
        }
        catch
        {
            ES3.DeleteFile(PlayersPath + "/player");
        }
        GameplayUIManager.UIState = UIState.None;
    }
    public static void RestoreMostRecentlyDeletedBoard()
    {
        string[] BoardBackups = Directory.GetFiles(Application.persistentDataPath + "/backups/_____deletedboards");
        System.Array.Sort(BoardBackups);

        SavedObjectV2 save        = (SavedObjectV2)FileUtilities.LoadFromFile(BoardBackups[BoardBackups.Length - 1]);
        GameObject    LoadedBoard = SavedObjectUtilities.LoadSavedObject(save);

        LoadedBoard.transform.position = new Vector3(0, -2000, 0);
        RecalculateClustersOfBoard(LoadedBoard);

        BoardPlacer.NewBoardBeingPlaced(LoadedBoard);
        GameplayUIManager.UIState = UIState.BoardBeingPlaced;
    }
Beispiel #4
0
        public override void Do()
        {
            var parentBoard = NetObject.GetByNetId(Packet.ParentBoardID);

            var component = SavedObjectUtilities.LoadSavedObject(Packet.SavedObject, parentBoard?.transform);

            component.AddComponent <NetObject>().NetID = Packet.NetID;

            if (Network.IsServer)
            {
                foreach (var item in component.GetComponentsInChildren <CircuitOutput>())
                {
                    CircuitStatePacket.SetOutputState(item, item.On, true);
                }
            }
        }
Beispiel #5
0
        public override void Undo()
        {
            IGConsole.Log("Component SavedObject is null: " + (SavedObject == null));

            SavedObjectUtilities.LoadSavedObject(SavedObject, Parent);

            //foreach (var item in Wires)
            //{
            //    if (item is InputInputConnection ii)
            //    {
            //        StuffConnector.LinkInputs(ii);
            //    }
            //    else if (item is InputOutputConnection io)
            //    {
            //        StuffConnector.LinkInputOutput(io);
            //    }
            //}
        }
    public void Load()
    {
        if (SelectedBoard == null)
        {
            return;
        }

        SavedObjectV2 save        = (SavedObjectV2)FileUtilities.LoadFromFile(SelectedBoard.FilePath);
        GameObject    LoadedBoard = SavedObjectUtilities.LoadSavedObject(save);

        HideAll();

        LoadedBoard.transform.position = new Vector3(0, -2000, 0);
        BoardFunctions.RecalculateClustersOfBoard(LoadedBoard);

        BoardPlacer.NewBoardBeingPlaced(LoadedBoard);
        GameplayUIManager.UIState = UIState.BoardBeingPlaced;
    }
Beispiel #7
0
        public override void Do()
        {
            NetObject         parentBoard = NetObject.GetByNetId(Packet.ParentBoardID);
            SavedCircuitBoard savedBoard;

            using (var mem = new MemoryStream(Packet.SavedBoard))
            {
                savedBoard = (SavedCircuitBoard)BinFormatter.Deserialize(mem);
            }

            var boardObj = SavedObjectUtilities.LoadSavedObject(savedBoard, parentBoard?.transform);

            boardObj.transform.position    = Packet.Position;
            boardObj.transform.eulerAngles = Packet.EulerAngles;

            foreach (var item in boardObj.GetComponentsInChildren <CircuitOutput>())
            {
                item.On = item.On; //It works 100% of the times most of the time
            }

            BoardFunctions.RecalculateClustersOfBoard(boardObj);
            SnappingPeg.TryToSnapIn(boardObj);
        }