public GameSavedData(GameManager_Master gameManagerMaster, Player_Inventory playerInventory, TorchBehavior torch) { //---Save current scene index---// savedSceneIndex = gameManagerMaster.currentBuildIndex; playerPosition = new float[3]; playerPosition[0] = playerInventory.transform.position.x; playerPosition[1] = playerInventory.transform.position.y; playerPosition[2] = playerInventory.transform.position.z; playerY_Rotation = playerInventory.transform.rotation.y; torchEnergy = torch.energy; if (playerInventory.items.Count > 0) { itemsName = new string[playerInventory.items.Count]; } else { itemsName = new string[1]; } int currentIndex = 0; foreach (Item item in playerInventory.items) { itemsName[currentIndex] = item.itemName; currentIndex++; } }
void Awake() { if (instance != null) { Debug.LogWarning("Two Inventories found"); } else { instance = this; } }
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(); }