public void SaveFile() { //Saves File. string destination = Application.persistentDataPath + "/save.dat"; FileStream file; if (File.Exists(destination)) { file = File.OpenWrite(destination); } else { Debug.LogError("File not found"); return; } GameSelectionData data = new GameSelectionData(gameSceneNames, gameNames, gamesLeft, gameNumber, currentGames, gameHasBeenPlayed, day); BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(file, data); file.Close(); }
public void BootFile() { //Happens During string Boot Stage, Checks if file exist. If Yes, do nothing. If No, Create a new config. string destination = Application.persistentDataPath + "/save.dat"; FileStream file; if (File.Exists(destination)) { file = File.OpenWrite(destination); } else { file = File.Create(destination); GameSelectionData data = new GameSelectionData(gameSceneNames, gameNames, gameNumber, gameNumber, new int[0], new bool[3], 0); BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(file, data); } file.Close(); ToggleControlPanel(); ToggleControlPanel(); }
public void LoadFile() { //Loads File. string destination = Application.persistentDataPath + "/save.dat"; FileStream file; if (File.Exists(destination)) { file = File.OpenRead(destination); } else { Debug.LogError("File not found"); return; } BinaryFormatter bf = new BinaryFormatter(); GameSelectionData data = (GameSelectionData)bf.Deserialize(file); gameNames = data.gameNames; gameSceneNames = data.gameSceneNames; currentGames = data.currentGames; gamesLeft = data.gamesLeft; gameNumber = data.gameNumber; gameHasBeenPlayed = data.gameHasBeenPlayed; day = data.day; textBoxes[1].GetComponent <Text>().text = (currentGames.Length > 0 ? gameNames[currentGames[0]] : "No Game Selected"); textBoxes[2].GetComponent <Text>().text = (currentGames.Length > 1 ? gameNames[currentGames[1]] : "No Game Selected"); textBoxes[3].GetComponent <Text>().text = (currentGames.Length > 2 ? gameNames[currentGames[2]] : "No Game Selected"); textBoxes[0].GetComponent <Text>().text = ": " + day.ToString(); for (int i = 1; i <= currentGames.Length; i++) { if (gameHasBeenPlayed[i - 1] == true) { Button button = gameButtons[i].GetComponent <Button>(); ColorBlock color = button.colors; color.normalColor = new Color32(174, 255, 244, 255); color.highlightedColor = new Color32(37, 223, 255, 255); color.selectedColor = new Color32(11, 190, 211, 255); color.pressedColor = new Color32(0, 130, 212, 255); button.colors = color; } else { Button button = gameButtons[i].GetComponent <Button>(); ColorBlock color = button.colors; color.normalColor = new Color32(183, 255, 174, 255); color.highlightedColor = new Color32(100, 241, 0, 255); color.selectedColor = new Color32(42, 221, 0, 255); color.pressedColor = new Color32(72, 185, 0, 255); button.colors = color; } } file.Close(); gameButtons[0].GetComponent <Button>().interactable = false; switch (currentGames.Length) { default: Debug.Log("This should be impossible. This literally cant happen. Contact me immediately if this occurs - Nicholas"); break; case 0: gameButtons[0].GetComponent <Button>().interactable = true; break; case 1: if (!gameHasBeenPlayed[0]) { return; } gameButtons[0].GetComponent <Button>().interactable = true; break; case 2: if (!gameHasBeenPlayed[0]) { return; } if (!gameHasBeenPlayed[1]) { return; } gameButtons[0].GetComponent <Button>().interactable = true; break; case 3: if (!gameHasBeenPlayed[0]) { return; } if (!gameHasBeenPlayed[1]) { return; } if (!gameHasBeenPlayed[2]) { return; } gameButtons[0].GetComponent <Button>().interactable = true; break; } }