Exemplo n.º 1
0
 public static MagicCubeSaveData LoadGameSave()
 {
     if (System.IO.File.Exists(SAVE_GAME_LOCATION))
     {
         System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
         System.IO.FileStream file     = System.IO.File.Open(SAVE_GAME_LOCATION, System.IO.FileMode.Open);
         MagicCubeSaveData    savedata = (MagicCubeSaveData)bf.Deserialize(file);
         file.Close();
         return(savedata);
     }
     throw new UnityException();
 }
Exemplo n.º 2
0
    public void Save()
    {
        if (bGameIsFinished)
        {
            return;
        }
        MagicCubeSaveData saveData = MagicCubeSaveData.CreateSaveData(this);

        System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
        System.IO.FileStream file = System.IO.File.Create(MainGameLogic.SAVE_GAME_LOCATION);
        bf.Serialize(file, saveData);
        file.Close();

        Debug.Log("File written to: " + MainGameLogic.SAVE_GAME_LOCATION);
    }
Exemplo n.º 3
0
    public void LoadGame()
    {
        try
        {
            MagicCubeSaveData savedata = MainGameLogic.LoadGameSave();

            MainGameLogic.GetMainCamera().GetComponent <CubeControl>().CreateMagicCube(savedata.magicCubeSize);
            MainGameLogic.SetCurrentActiveElement(MainGameLogic.CurrentActiveElement.MAIN_GAME);
            MainGameLogic.LinkMagicCubeManagerAndUI(MainGameLogic.GetMainCamera().GetComponent <CubeControl>().GetMagicCubeManager(), MainGameLogic.GetMainCamera().GetComponent <UIManager>().GetMainGameUI());
            MainGameLogic.LinkMagicCubeManagerAndFinish(MainGameLogic.GetMainCamera().GetComponent <CubeControl>().GetMagicCubeManager(), MainGameLogic.GetMainCamera().GetComponent <UIManager>().GetFinishCanvas());
            MainGameLogic.GetMainCamera().GetComponent <CubeControl>().GetMagicCubeManager().LoadGame(savedata);

            MainGameLogic.GetMainCamera().GetComponent <UIManager>().MainMenuToGame();
        }
        catch (Exception e)
        {
            StartGame();
        }
    }
Exemplo n.º 4
0
    public static MagicCubeSaveData CreateSaveData(MagicCubeManager manager)
    {
        MagicCubeSaveData savedata = new MagicCubeSaveData();

        //deep copies to be safe.
        foreach (var cubeTile in manager.GetCubeTileListReference())
        {
            savedata.positions.Add(Vector3Serializable.CreateVector3Serializable(cubeTile.transform.position));
            savedata.rotations.Add(QuaternionSerializable.CreateQuaternionSerializable(cubeTile.transform.rotation));
            savedata.cubeTileIDs.Add(cubeTile.GetComponent <CubeTileInfo>().GetID());
        }
        foreach (var action in manager.GetUndoListReference())
        {
            savedata.undoActions.Add(ActionSaveData.CreateSaveData(action));
        }

        savedata.magicCubeSize = manager.GetMagicCubeSize();
        savedata.time          = manager.GetTimePassed();

        return(savedata);
    }
Exemplo n.º 5
0
    internal void LoadGame(MagicCubeSaveData savedata)
    {
        bIsLoading = true;
        foreach (var item in cubeTiles)
        {
            UnityEngine.Object.Destroy(item);
        }

        cubeTiles.Clear();
        collectionHelper = new CubeCollectionHelper(0);

        for (int i = 0; i < savedata.positions.Count; i++)
        {
            var temp = GameObject.Instantiate(cubeTileRef,
                                              savedata.positions[i].ToVector3()
                                              , savedata.rotations[i].ToQuaternion());
            collectionHelper.ProcessCubeTile(temp, temp.transform.position);
            temp.transform.SetParent(ownHolder.transform);
            cubeTiles.Add(temp);
            temp.GetComponent <CubeTileInfo>().SetID(savedata.cubeTileIDs[i]);
        }

        actionList.Clear();
        for (int i = 0; i < savedata.undoActions.Count; i++)
        {
            CubeAction        action             = null;
            List <GameObject> cubeTilesForAction = new List <GameObject>();
            foreach (var cubeID in savedata.undoActions[i].cubeCollection)
            {
                cubeTilesForAction.Add(cubeTiles.Find(ct => ct.GetComponent <CubeTileInfo>().GetID() == cubeID));
            }
            switch (savedata.undoActions[i].action)
            {
            case (int)ActionSaveData.ActionType.ZXClock:
                action = new ActionRotateZXClockWise(ownHolder, this, cubeTilesForAction, true);
                break;

            case (int)ActionSaveData.ActionType.ZXCounterClock:
                action = new ActionRotateZXCounterClockWise(ownHolder, this, cubeTilesForAction, true);
                break;

            case (int)ActionSaveData.ActionType.YXClock:
                action = new ActionRotateYXClockWise(ownHolder, this, cubeTilesForAction, true);
                break;

            case (int)ActionSaveData.ActionType.YXCounterClock:
                action = new ActionRotateYXCounterClockWise(ownHolder, this, cubeTilesForAction, true);
                break;

            case (int)ActionSaveData.ActionType.ZYClock:
                action = new ActionRotateZYClockWise(ownHolder, this, cubeTilesForAction, true);
                break;

            case (int)ActionSaveData.ActionType.ZYCounterClock:
                action = new ActionRotateZYCounterClockWise(ownHolder, this, cubeTilesForAction, true);
                break;
            }
            if (action == null)
            {
                actionList.Clear();
                break;
            }
            action.CompleteActionNoAnimation();
            actionList.Add(action);
        }

        timePassed = savedata.time;
        seconds    = savedata.time;
        updateTime(seconds);
        processUndoRedoPossible(actionList.Count > 0);
        bIsLoading = false;
    }