public void LoadGameState() { //loading the sheet is done in sheet manager no need to move it here atm //can switch between vector3 and the serializable one with the implicit operator thing SavedStateOther tempState = SaveLoad.LoadGameStateOther(); if (tempState == null) { return; } //if a saved game has been found, proceed: DiceParent.instance.throwsUsed = tempState.throwsUsed; DiceParent.instance.SetThrowsLeftText(); SheetManager.instance.yatzyZeroPoints = tempState.yatzyPlayedZero; SheetManager.instance.yatzyPlayed = tempState.yatzyPlayed; if (!tempState.dicesCollected) //if the dices are collected, their positions and rotations dont need to be updated { StartCoroutine(DiceParent.instance.DicesLoaded(tempState.dicePositions, tempState.diceRotations)); } if (tempState.throwsUsed == throwsPerRound) //if all throws have been used dont set throw button interactable //DiceParent.instance.ThrowButton.interactable = false; { DiceParent.instance.throwBut.enabled = false; DiceParent.instance.throwButtonAnimator.Play("ColorDisabled"); } }
public static SavedStateOther LoadGameStateOther() { if (File.Exists(Application.persistentDataPath + "/gameStateOther.gd")) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/gameStateOther.gd", FileMode.Open); SaveLoad.gameState = (SavedStateOther)bf.Deserialize(file); file.Close(); return(gameState); } return(null); }
public static void SaveGameState(List <SavedSheetLine> lines, int throws, bool yatzy, bool yatzyZero, bool collected, SerializableVector3[] positions, SerializableVector3[] rotations) { savedLines.Clear(); savedLines = lines; BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Create(Application.persistentDataPath + "/gameStateSheet.gd"); bf.Serialize(file, SaveLoad.savedLines); file.Close(); Debug.Log("sheet saved"); SavedStateOther stateTemp = new SavedStateOther() { throwsUsed = throws, yatzyPlayed = yatzy, yatzyPlayedZero = yatzyZero, dicesCollected = collected, dicePositions = positions, diceRotations = rotations }; gameState = stateTemp; bf = new BinaryFormatter(); file = File.Create(Application.persistentDataPath + "/gameStateOther.gd"); bf.Serialize(file, SaveLoad.gameState); file.Close(); Debug.Log("state Saved"); }