void LoadLastSavedProgress() { GameSavedData data = SystemSaveAndLoad.LoadGame(SystemSaveAndLoad.savedFileName); //---If save file exist---// if (data != null) { gameManagerMaster.currentBuildIndex = data.savedSceneIndex; Vector3 position; position.x = data.playerPosition[0]; position.y = data.playerPosition[1]; position.z = data.playerPosition[2]; Player_Master.instance.transform.position = position; //Debug.Log(position); //Player_Master.instance.transform.SetPositionAndRotation(position, Quaternion.EulerAngles(0, data.playerY_Rotation, 0)); Player_Master.instance.gameObject.GetComponent <TorchBehavior>().energy = data.torchEnergy; for (int i = 0; i < data.itemsName.Length; i++) { itemInThisScene = false; foreach (GameObject gameObject in itemsInScene) { pickupScriptOnItem = gameObject.GetComponent <Pickup>(); if (pickupScriptOnItem != null) { if (pickupScriptOnItem.item.itemName == data.itemsName[i]) { itemInThisScene = true; Player_Inventory.instance.AddItem(pickupScriptOnItem.item); gameObject.SetActive(false); break; } } } if (!itemInThisScene) { foreach (Item item in itemsInGame) { if (item.itemName == data.itemsName[i]) { Player_Inventory.instance.AddItem(item); } } } } } }
public static void SaveGame(GameManager_Master gameManagerMaster, Player_Inventory playerInventory) { BinaryFormatter formatter = new BinaryFormatter(); string filePath = string.Concat(Application.persistentDataPath, "/", savedFileName); FileStream file = new FileStream(filePath, FileMode.Create); TorchBehavior torch = playerInventory.gameObject.GetComponent <TorchBehavior>(); GameSavedData data = new GameSavedData(gameManagerMaster, playerInventory, torch); formatter.Serialize(file, data); file.Close(); }
public void RestartFromSavedPoint() { GameSavedData data = SystemSaveAndLoad.LoadGame(SystemSaveAndLoad.savedFileName); if (data != null) { SystemSaveAndLoad.sceneLoadType = SystemSaveAndLoad.LoadType.loadSaved; SceneManager.LoadScene(GameManager_GlobalVariables.instance.scenesName[data.savedSceneIndex]); } else { SystemSaveAndLoad.sceneLoadType = SystemSaveAndLoad.LoadType.newGame; SceneManager.LoadScene(GameManager_GlobalVariables.instance.scenesName[1]); } }
void CheckLoadFile() { GameSavedData data = SystemSaveAndLoad.LoadGame(SystemSaveAndLoad.savedFileName); if (data != null) { loadableSceneIndex = data.savedSceneIndex; loadable = true; loadButton.interactable = true; } else { loadableSceneIndex = 1; loadable = false; loadButton.interactable = false; } }
public static GameSavedData LoadGame(string savedName) { string filePath = string.Concat(Application.persistentDataPath, "/", savedName); if (File.Exists(filePath)) { BinaryFormatter formatter = new BinaryFormatter(); FileStream file = new FileStream(filePath, FileMode.Open); GameSavedData data = formatter.Deserialize(file) as GameSavedData; file.Close(); return(data); } else { Debug.Log("File not found"); return(null); } }
void LoadSceneChangedProgress() { GameSavedData data = SystemSaveAndLoad.LoadGame(SystemSaveAndLoad.savedFileName); if (data != null) { Player_Master.instance.gameObject.GetComponent <TorchBehavior>().energy = data.torchEnergy; for (int i = 0; i < data.itemsName.Length; i++) { itemInThisScene = false; foreach (GameObject gameObject in itemsInScene) { pickupScriptOnItem = gameObject.GetComponent <Pickup>(); if (pickupScriptOnItem != null) { if (pickupScriptOnItem.item.itemName == data.itemsName[i]) { itemInThisScene = true; Player_Inventory.instance.AddItem(pickupScriptOnItem.item); gameObject.SetActive(false); break; } } } if (!itemInThisScene) { foreach (Item item in itemsInGame) { if (item.itemName == data.itemsName[i]) { Player_Inventory.instance.AddItem(item); } } } } } }