using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Rendering.HighDefinition; using TRInventoryUpdatable; using InfallibleCode; using System; using System.IO; using NUnit.Framework; public class LoadController : MonoBehaviour { public GameObject gameSystems; private SaveTrigger[] saveTriggers; // Specify the layer you want to search for public LayerMask whiteLedgesTargetLayer; public List whiteLedges = new List(); private static LoadController _instance; public static LoadController GetInstance() { return _instance; } //public event Action AfterLoadingDone = delegate { }; private void Awake() { if (!_instance) { _instance = this; } saveTriggers = FindObjectsOfType(); // Find all objects with DecalProjector components DecalProjector[] allDecalProjectors = GameObject.FindObjectsOfType(); // Add the found DecalProjector components to the list foreach (DecalProjector decalProjector in allDecalProjectors) { whiteLedges.Add(decalProjector); } } //public void LoadGameData() //{ // #region Set chosen SaveSlot // SaveSlotManager.GetInstance().selectedSaveSlotID = SaveSlotManager.GetInstance().GetChosenSaveSlot(); // #endregion // if ((GameplayController.GetInstance().currentGameState != GameplayController.State.GameLaunched) || (GameplayController.GetInstance().currentGameState != GameplayController.State.MainMenu)) // { // if (LoadManager.GetInstance().LoadingGame) // { // gameSystems.SetActive(true); // GameSaveData loadedData = SaveSlotManager.LoadPlayerData(SaveSlotManager.GetInstance().selectedSaveSlotID/*Change later to take the ID of the currently selected Save slot*/); // if (loadedData != null) // { // // Use the loaded data to set the player's state // PlayerManager.GetInstance().playerGameObj.transform.position = loadedData.playerData.playerPosition; // //// Activate the saved active Cinemachine camera // //ActivateCinemachineCameraByName(loadedData.playerData.activeCameraName); // Implement this function // //Save triggers that need to be deactivated: // DeactivateSaveTriggersThatPlayerPassed(loadedData.playerData); // //White ledges load: // LedgesUpdate(loadedData); // //Update UI for options. // UpdateOptionsMenuWhiteLedgesHighlightUI(loadedData); // ////Update secret items: // //SecretsLoadUpdate(loadedData); // //Game progress load: // // Update the initial cutscene flag // GameProgressManager.GetInstance().initialCutscenePlayed = loadedData.gameProgressData.initialCutscenePlayed; // GameProgressManager.GetInstance().firefliesAreDead = loadedData.gameProgressData.firefliesAreDead; // GameProgressManager.GetInstance().UpdateGameProgress(); // //Load the state of the storyline // GameProgressManager.GetInstance().currentStorylineState = loadedData.gameProgressData.currentStorylineState; // //Change state to Gameplay: // GameplayController.GetInstance().GoToGameplayState(); // LoadingUIClose(); // print("Game loaded"); // LoadManager.GetInstance().LoadingGame = false; // } // } // if (LoadManager.GetInstance().IsEnteringNewGame) // { // GameSaveData loadedData = SaveSlotManager.LoadPlayerData(SaveSlotManager.GetInstance().selectedSaveSlotID/*Change later to take the ID of the currently selected Save slot*/); // if (loadedData != null) // { // //White ledges load: // LedgesUpdate(loadedData); // GameProgressManager.GetInstance().UpdateGameProgress(); //In order to play the first cutscene when entering the new game. // //Change state to Gameplay: // GameplayController.GetInstance().GoToGameplayState(); // LoadingUIClose(); // print("New game entered"); // LoadManager.GetInstance().IsEnteringNewGame = false; // } // } // } // #region Main Menu related // if (GameplayController.GetInstance().IsOnState(GameplayController.State.GameLaunched) || GameplayController.GetInstance().IsOnState(GameplayController.State.MainMenu)) // { // GameSaveData loadedData = SaveSlotManager.LoadPlayerData(SaveSlotManager.GetInstance().selectedSaveSlotID /*Change later to take the ID of the currently selected Save slot*/); // if (loadedData != null) // { // UpdateOptionsMenuWhiteLedgesHighlightUI(loadedData); // if (loadedData.playerData.continueButtonEnabled) // { // MainMenu.GetInstance().continueButtonIsInteractable(); // } // else // { // MainMenu.GetInstance().continueButtonIsNotInteractable(); // } // } // UpdateSaveAndLoadSlotsUI(); // UpdateCurrentlySelectedSaveSlotText(loadedData); // LoadingUIClose(); // } // #endregion //} private void Start() { // Subscribe to the OnScenesLoaded event LoadManager.GetInstance().OnScenesLoaded += OnScenesLoadingDone; } private void OnScenesLoadingDone() { HandleLoading(); PlayerManager.GetInstance().PlayerMainCamera.GetComponent().enabled = true; LoadingUIClose(); //if (GameplayController.GetInstance().demoMode == false) //{ // GameManager.GetInstance().currentStoryState = GameManager.StoryState.Prologue; // GameManager.GetInstance().HandleStoryState(GameManager.GetInstance().currentStoryState); //} print("FUCK YOUUUUUU"); //HandleLoading(); print("Loading handled"); } private void OnDestroy() { // Unsubscribe from the event to avoid memory leaks LoadManager.GetInstance().OnScenesLoaded -= OnScenesLoadingDone; } void OnEnable() { #region OLD IMPLEMENTATION //if ((GameplayController.GetInstance().currentGameState != GameplayController.State.GameLaunched) || (GameplayController.GetInstance().currentGameState != GameplayController.State.MainMenu)) //{ // if (LoadManager.GetInstance().LoadingGame || LoadManager.GetInstance().IsEnteringNewGame) // { // GameplayController.GetInstance().InstantiatePlayerRelatedSystem(); // } //} //#region Set chosen SaveSlot //SaveSlotManager.GetInstance().selectedSaveSlotID = SaveSlotManager.GetInstance().GetChosenSaveSlot(); //#endregion //if ((GameplayController.GetInstance().currentGameState != GameplayController.State.GameLaunched) || (GameplayController.GetInstance().currentGameState != GameplayController.State.MainMenu)) //{ // if (LoadManager.GetInstance().LoadingGame) // { // //Maybe instantiate systems or load // // game systems = GameSystemsManager.GetInstance().Systems; // //I ADDED TO SEE IF IT WORKS!!!!!!!! // //GameplayController.GetInstance().loadAdditiveSceneForGameSystemsAndPlayer.LoadAdditiveScene(); // Instantiate(GameplayController.GetInstance().GameSystemsAndPlayer); // //--------------------------------------------------------------------------------------------- // gameSystems = GameSystemsManager.GetInstance().Systems; // gameSystems.SetActive(true); // GameSaveData loadedData = SaveSlotManager.LoadPlayerData(SaveSlotManager.GetInstance().selectedSaveSlotID/*Change later to take the ID of the currently selected Save slot*/); // if (loadedData != null) // { // // Use the loaded data to set the player's state // PlayerManager.GetInstance().playerGameObj.transform.position = loadedData.playerData.playerPosition; // PlayerManager.GetInstance().playerGameObj.transform.rotation = loadedData.playerData.playerRotation; // //Player related: // //Sanity Reset // Sanity.GetInstance()._sanity = Sanity.GetInstance()._sanityMaxValue; // //Player Controllers: // PlayerManager.GetInstance()._PlayerMovement.enabled = loadedData.playerData.playerControllerShouldBeEnabledOnGameLoad; // PlayerManager.GetInstance()._cameraMovement.enabled = loadedData.playerData.playerCameraControllerShouldBeEnabledOnGameLoad; // //Sanity.GetInstance().ClearAllSanityUnityActionListeners(); // //// Activate the saved active Cinemachine camera // //ActivateCinemachineCameraByName(loadedData.playerData.activeCameraName); // Implement this function // //Save triggers that need to be deactivated: // DeactivateSaveTriggersThatPlayerPassed(loadedData.playerData); // //White ledges load: // LedgesUpdate(loadedData); // //Update UI for options. // UpdateOptionsMenuWhiteLedgesHighlightUI(loadedData); // //Initialisation of inventory before adding items into it. // RingInventory.GetInstance().InventoryInitialisationForKeysAndItemsAndCollectables(); // //Update InventoryItems: // if (loadedData.inventoryData.KeyPickupInventoryItems.Count > 0) //If there are key pickups // { // foreach (var keyPickupInventoryItem in loadedData.inventoryData.KeyPickupInventoryItems) // { // KeysManager.GetInstance().AddKeyNameID(keyPickupInventoryItem.KeyNameID); // //First instantiate the key model you want: // GameObject key = Instantiate(InventoryManager.GetInstance().AccessFieldInInventoryManager(keyPickupInventoryItem.KeyModelNameInInventoryManager).gameObject, // InventoryManager.GetInstance().TransformWithPosRotForItemsToAdd.position, // InventoryManager.GetInstance().TransformWithPosRotForItemsToAdd.rotation, // InventoryManager.GetInstance().itemsToAddTransform); // //Set the key name that's going to show up when the player is in the selection of the key's slot. // KeyInventoryItem keyInventoryItem = key.GetComponent(); // keyInventoryItem.keyNameInInventory = keyPickupInventoryItem.keyNameInInventory; // GameObject keyGameObject = GameObject.Find(keyPickupInventoryItem.obtainedKeyItemName); // if(keyGameObject != null) // { // keyGameObject.SetActive(false); // } // #region KeyModelForKeyHole RELATED // keyInventoryItem.keyNameID = keyPickupInventoryItem.KeyNameID; // //if (keyPickupInventoryItem.KeyModelForKeyHole != null) // //{ // // keyInventoryItem.keyModelForKeyHole = keyPickupInventoryItem.KeyModelForKeyHole; // // GameObject prefab = AssetDatabase.LoadAssetAtPath("Assets/Prefabs/YourPrefab.prefab"); // // if (prefab != null) // // { // // keyInventoryItem.keyModelForKeyHole = PrefabUtility.LoadPrefabContents(prefab); // // // Additional logic for the instantiated object // // } // // else // // { // // Debug.LogError("Prefab not found!"); // // } // //} // #endregion // //keyInventoryItem.keyTypeString = keyType.ToString(); // //Add the new instantiated item into the keysAndItemsInventory // RingInventory.GetInstance().AddItemToKeysAndItemsInventory(key.transform); // //key.GetComponentInChildren().gameObject.layer = 5; //Added today 11/08/24 Yiannis // ChangeLayerRecursively(key.transform, 5); // } // } // //Update Environment obtained items // if (loadedData.inventoryData.ObtainedItems.Count > 0) // { // foreach (var obtainedItem in loadedData.inventoryData.ObtainedItems) // { // GameObject gameObject = GameObject.Find(obtainedItem.obtainedItemName); // if (gameObject != null) // { // gameObject.SetActive(false); // or perform other operations // } // //if (gameObject != null && !gameObject.activeInHierarchy) // //{ // // // The object is found, and it's currently disabled // // gameObject.SetActive(false); // or perform other operations // //} // } // } // //Update Flashlight Batteries in InventoryManager // BatteryManager.GetInstance().batteriesCollected = loadedData.inventoryData.BatteriesPickup.BatteriesCollected; // if (BatteryManager.GetInstance().batteriesCollected > 0) // { // if (InventoryManager.GetInstance().batteryOnRingInventory.activeSelf == false) // { // RingInventory.GetInstance().AddItemToKeysAndItemsInventory(InventoryManager.GetInstance().batteryOnRingInventory.transform); // print("Is reconstructing inventory for batteries"); // InventoryManager.GetInstance().batteryOnRingInventory.SetActive(true); // } // } // if (loadedData.inventoryData.BatteriesPickup.BatteriesCollected > 0) // { // foreach (var obtainedItem in loadedData.inventoryData.IndividualBatteriesPickup) // { // GameObject gameObject = GameObject.Find(obtainedItem.obtainedBatteryItemName); // if (gameObject != null) // { // if (gameObject.GetComponent().uniqueID == obtainedItem.obtainedBatteryItemUniqueID) // { // gameObject.SetActive(false); // or perform other operations // } // } // //if (gameObject != null && !gameObject.activeInHierarchy) // //{ // // // The object is found, and it's currently disabled // // gameObject.SetActive(false); // or perform other operations // //} // } // } // //Update Pills in InventoryManager // PlayerHealthManager.GetInstance().pillsCollected = loadedData.inventoryData.PillsPickup.PillsCollected; // if (PlayerHealthManager.GetInstance().pillsCollected > 0) // { // if (InventoryManager.GetInstance().pillsOnRingInventory.activeSelf == false) // { // RingInventory.GetInstance().AddItemToKeysAndItemsInventory(InventoryManager.GetInstance().pillsOnRingInventory.transform); // print("Is reconstructing inventory for pills"); // InventoryManager.GetInstance().pillsOnRingInventory.SetActive(true); // } // } // if (loadedData.inventoryData.PillsPickup.PillsCollected > 0) // { // foreach (var obtainedItem in loadedData.inventoryData.IndividualPillsPickup) // { // GameObject gameObject = GameObject.Find(obtainedItem.obtainedPillsItemName); // if (gameObject != null) // { // if (gameObject.GetComponent().uniqueID == obtainedItem.obtainedPillsItemUniqueID) // { // gameObject.SetActive(false); // or perform other operations // } // } // } // } // //Pocket Watch Update: // if(loadedData.inventoryData.pocketWatchInventoryItem.pocketWatchCollected == true) // { // RingInventory.GetInstance().AddItemToKeysAndItemsInventory(InventoryManager.GetInstance().pocketWatchOnRingInventory.transform); // print("Is reconstructing inventory for pocket watch"); // InventoryManager.GetInstance().pocketWatchOnRingInventory.SetActive(true); // GameProgressManager.GetInstance().PocketWatchIsObtained = true; // } // //Diary Entry Update: // if (loadedData.collectablesData.DiaryEntryItem.Count > 0) // { // foreach (var obtainedDiaryEntryItem in loadedData.collectablesData.DiaryEntryItem) // { // RingInventory.GetInstance().AddItemToCollectablesInventory(InventoryManager.GetInstance().medeaDiary.transform); // InventoryManager.GetInstance().medeaDiary.SetActive(true); // print("Is reconstructing inventory for Medea diary"); // GameObject DiaryEntryGameObject = GameObject.Find(obtainedDiaryEntryItem.obtainedDiaryEntryItemName); // if (DiaryEntryGameObject != null) // { // DiaryEntryGameObject.SetActive(false); // } // } // } // //Flashlight battery life: // FlashlightController.GetInstance()._flashlightLife = loadedData.inventoryData.Flashlight.flashlightBatteryLife; // ////Update secret items: // //SecretsLoadUpdate(loadedData); // //Game progress load: // // Update the initial cutscene flag // GameProgressManager.GetInstance().initialCutscenePlayed = loadedData.gameProgressData.initialCutscenePlayed; // GameProgressManager.GetInstance().firefliesAreDead = loadedData.gameProgressData.firefliesAreDead; // GameProgressManager.GetInstance().UpdateGameProgress(); // //Load the state of the storyline // GameProgressManager.GetInstance().currentStorylineState = loadedData.gameProgressData.currentStorylineState; // GameProgressManager.GetInstance().loadCurrentStorylineState = true; //In order for the current storyline manager to go to the correct state. // //Save the state of the global storyline // GameProgressManager.GetInstance().currentGlobalStorylineState = loadedData.gameProgressData.currentGlobalStorylineState; // GameProgressManager.GetInstance().loadCurrentGlobalStorylineState = true; //In order for the current storyline manager to go to the correct state. // //Change state to Gameplay: // GameplayController.GetInstance().GoToGameplayState(); // //Fade out black screen: // CutscenesManager.GetInstance().FindGameLoadedFadeOutPlayableDirector(); // CutscenesManager.GetInstance().gameLoadedFadeOutPlayableDirector.Play(); // //LoadingUIClose(); // print("Game loaded"); // LoadManager.GetInstance().LoadingGame = false; // } // } // if (LoadManager.GetInstance().IsEnteringNewGame) // { // //I ADDED TO SEE IF IT WORKS!!!!!!!! // //GameplayController.GetInstance().loadAdditiveSceneForGameSystemsAndPlayer.LoadAdditiveScene(); // Instantiate(GameplayController.GetInstance().GameSystemsAndPlayer); // //--------------------------------------------------------------------------------------------- // gameSystems = GameSystemsManager.GetInstance().Systems; // gameSystems.SetActive(true); // //Initialisation of inventory before adding items into it. // RingInventory.GetInstance().InventoryInitialisationForKeysAndItemsAndCollectables(); // if(GameplayController.GetInstance().demoMode == false) // { // GameManager.GetInstance().currentStoryState = GameManager.StoryState.Prologue; // GameManager.GetInstance().HandleStoryState(GameManager.GetInstance().currentStoryState); // } // GameSaveData loadedData = SaveSlotManager.LoadPlayerData(SaveSlotManager.GetInstance().selectedSaveSlotID/*Change later to take the ID of the currently selected Save slot*/); // if (loadedData != null) // { // //White ledges load: // LedgesUpdate(loadedData); // GameProgressManager.GetInstance().UpdateGameProgress(); //In order to play the first cutscene when entering the new game. // //Change state to Gameplay: // GameplayController.GetInstance().GoToGameplayState(); // //LoadingUIClose(); // print("New game entered"); // LoadManager.GetInstance().IsEnteringNewGame = false; // } // } //} #endregion #region Main Menu related if (GameplayController.GetInstance().IsOnState(GameplayController.State.GameLaunched) || GameplayController.GetInstance().IsOnState(GameplayController.State.MainMenu)) { GameSaveData loadedData = SaveSlotManager.LoadPlayerData(SaveSlotManager.GetInstance().selectedSaveSlotID /*Change later to take the ID of the currently selected Save slot*/); if (loadedData != null) { UpdateOptionsMenuWhiteLedgesHighlightUI(loadedData); if (loadedData.playerData.continueButtonEnabled) { MainMenu.GetInstance().continueButtonIsInteractable(); } else { MainMenu.GetInstance().continueButtonIsNotInteractable(); } } UpdateSaveAndLoadSlotsUI(); UpdateCurrentlySelectedSaveSlotText(loadedData); //LoadingUIClose(); } #endregion } /// /// Handles all the logic when it terms to loading the game. /// public void HandleLoading() { if ((GameplayController.GetInstance().currentGameState != GameplayController.State.GameLaunched) || (GameplayController.GetInstance().currentGameState != GameplayController.State.MainMenu)) { if (LoadManager.GetInstance().LoadingGame) { //Maybe instantiate systems or load // game systems = GameSystemsManager.GetInstance().Systems; //I ADDED TO SEE IF IT WORKS!!!!!!!! //GameplayController.GetInstance().loadAdditiveSceneForGameSystemsAndPlayer.LoadAdditiveScene(); Instantiate(GameplayController.GetInstance().GameSystemsAndPlayer); //--------------------------------------------------------------------------------------------- gameSystems = GameSystemsManager.GetInstance().Systems; gameSystems.SetActive(true); GameSaveData loadedData = SaveSlotManager.LoadPlayerData(SaveSlotManager.GetInstance().selectedSaveSlotID/*Change later to take the ID of the currently selected Save slot*/); if (loadedData != null) { // Use the loaded data to set the player's state PlayerManager.GetInstance().playerGameObj.transform.position = loadedData.playerData.playerPosition; PlayerManager.GetInstance().playerGameObj.transform.rotation = loadedData.playerData.playerRotation; //Player related: //Sanity Reset Sanity.GetInstance().SetSanity(Sanity.GetInstance().SanityMaxValue); //Player Controllers: PlayerManager.GetInstance()._PlayerMovement.enabled = loadedData.playerData.playerControllerShouldBeEnabledOnGameLoad; PlayerManager.GetInstance()._cameraMovement.enabled = loadedData.playerData.playerCameraControllerShouldBeEnabledOnGameLoad; //Sanity.GetInstance().ClearAllSanityUnityActionListeners(); //// Activate the saved active Cinemachine camera //ActivateCinemachineCameraByName(loadedData.playerData.activeCameraName); // Implement this function //Save triggers that need to be deactivated: DeactivateSaveTriggersThatPlayerPassed(loadedData.playerData); //White ledges load: LedgesUpdate(loadedData); //Update UI for options. UpdateOptionsMenuWhiteLedgesHighlightUI(loadedData); //Initialisation of inventory before adding items into it. RingInventory.GetInstance().InventoryInitialisationForKeysAndItemsAndCollectables(); //Update InventoryItems: if (loadedData.inventoryData.KeyPickupInventoryItems.Count > 0) //If there are key pickups { foreach (var keyPickupInventoryItem in loadedData.inventoryData.KeyPickupInventoryItems) { KeysManager.GetInstance().AddKeyNameID(keyPickupInventoryItem.KeyNameID); //First instantiate the key model you want: GameObject key = Instantiate(InventoryManager.GetInstance().AccessFieldInInventoryManager(keyPickupInventoryItem.KeyModelNameInInventoryManager).gameObject, InventoryManager.GetInstance().TransformWithPosRotForItemsToAdd.position, InventoryManager.GetInstance().TransformWithPosRotForItemsToAdd.rotation, InventoryManager.GetInstance().itemsToAddTransform); //Set the key name that's going to show up when the player is in the selection of the key's slot. KeyInventoryItem keyInventoryItem = key.GetComponent(); keyInventoryItem.keyNameInInventory = keyPickupInventoryItem.keyNameInInventory; keyInventoryItem.IsReusable = keyPickupInventoryItem.IsReusable; key.name = keyPickupInventoryItem.obtainedKeyItemName + " Inventory Item"; GameObject keyGameObject = GameObject.Find(keyPickupInventoryItem.obtainedKeyItemName); if (keyGameObject != null) { keyGameObject.SetActive(false); } #region KeyModelForKeyHole RELATED keyInventoryItem.keyNameID = keyPickupInventoryItem.KeyNameID; //if (keyPickupInventoryItem.KeyModelForKeyHole != null) //{ // keyInventoryItem.keyModelForKeyHole = keyPickupInventoryItem.KeyModelForKeyHole; // GameObject prefab = AssetDatabase.LoadAssetAtPath("Assets/Prefabs/YourPrefab.prefab"); // if (prefab != null) // { // keyInventoryItem.keyModelForKeyHole = PrefabUtility.LoadPrefabContents(prefab); // // Additional logic for the instantiated object // } // else // { // Debug.LogError("Prefab not found!"); // } //} #endregion //keyInventoryItem.keyTypeString = keyType.ToString(); //Add the new instantiated item into the keysAndItemsInventory RingInventory.GetInstance().AddItemToKeysAndItemsInventory(key.transform); //key.GetComponentInChildren().gameObject.layer = 5; //Added today 11/08/24 Yiannis ChangeLayerRecursively(key.transform, 5); } } //Update Environment obtained items if (loadedData.inventoryData.ObtainedItems.Count > 0) { foreach (var obtainedItem in loadedData.inventoryData.ObtainedItems) { GameObject gameObject = GameObject.Find(obtainedItem.obtainedItemName); if (gameObject != null) { gameObject.SetActive(false); // or perform other operations } //if (gameObject != null && !gameObject.activeInHierarchy) //{ // // The object is found, and it's currently disabled // gameObject.SetActive(false); // or perform other operations //} } } //Update Flashlight Batteries in InventoryManager BatteryManager.GetInstance().batteriesCollected = loadedData.inventoryData.BatteriesPickup.BatteriesCollected; if (BatteryManager.GetInstance().batteriesCollected > 0) { if (InventoryManager.GetInstance().batteryOnRingInventory.activeSelf == false) { RingInventory.GetInstance().AddItemToKeysAndItemsInventory(InventoryManager.GetInstance().batteryOnRingInventory.transform); print("Is reconstructing inventory for batteries"); InventoryManager.GetInstance().batteryOnRingInventory.SetActive(true); } } if (loadedData.inventoryData.BatteriesPickup.BatteriesCollected > 0) { foreach (var obtainedItem in loadedData.inventoryData.IndividualBatteriesPickup) { GameObject gameObject = GameObject.Find(obtainedItem.obtainedBatteryItemName); if (gameObject != null) { if (gameObject.GetComponent().uniqueID == obtainedItem.obtainedBatteryItemUniqueID) { gameObject.SetActive(false); // or perform other operations } } //if (gameObject != null && !gameObject.activeInHierarchy) //{ // // The object is found, and it's currently disabled // gameObject.SetActive(false); // or perform other operations //} } } //Update Pills in InventoryManager PlayerHealthManager.GetInstance().pillsCollected = loadedData.inventoryData.PillsPickup.PillsCollected; if (PlayerHealthManager.GetInstance().pillsCollected > 0) { if (InventoryManager.GetInstance().pillsOnRingInventory.activeSelf == false) { RingInventory.GetInstance().AddItemToKeysAndItemsInventory(InventoryManager.GetInstance().pillsOnRingInventory.transform); print("Is reconstructing inventory for pills"); InventoryManager.GetInstance().pillsOnRingInventory.SetActive(true); } } if (loadedData.inventoryData.PillsPickup.PillsCollected > 0) { foreach (var obtainedItem in loadedData.inventoryData.IndividualPillsPickup) { GameObject gameObject = GameObject.Find(obtainedItem.obtainedPillsItemName); if (gameObject != null) { if (gameObject.GetComponent().uniqueID == obtainedItem.obtainedPillsItemUniqueID) { gameObject.SetActive(false); // or perform other operations } } } } //Pocket Watch Update: if (loadedData.inventoryData.pocketWatchInventoryItem.pocketWatchCollected == true) { RingInventory.GetInstance().AddItemToKeysAndItemsInventory(InventoryManager.GetInstance().pocketWatchOnRingInventory.transform); print("Is reconstructing inventory for pocket watch"); InventoryManager.GetInstance().pocketWatchOnRingInventory.SetActive(true); GameProgressManager.GetInstance().PocketWatchIsObtained = true; } //Diary Entry Update: if (loadedData.collectablesData.DiaryEntryItem.Count > 0) { foreach (var obtainedDiaryEntryItem in loadedData.collectablesData.DiaryEntryItem) { RingInventory.GetInstance().AddItemToCollectablesInventory(InventoryManager.GetInstance().medeaDiary.transform); InventoryManager.GetInstance().medeaDiary.SetActive(true); print("Is reconstructing inventory for Medea diary"); GameObject DiaryEntryGameObject = GameObject.Find(obtainedDiaryEntryItem.obtainedDiaryEntryItemName); if (DiaryEntryGameObject != null) { DiaryEntryGameObject.SetActive(false); } } } //Update Regular Inventory Items: if (loadedData.inventoryData.RegularItems.Count > 0) //If there are any regular items { foreach (var regularInventoryItem in loadedData.inventoryData.RegularItems) { //First instantiate the key model you want: GameObject regularItem = InventoryManager.GetInstance().AccessFieldInInventoryManager(regularInventoryItem.ItemModelNameInInventoryManager).gameObject; regularItem.gameObject.SetActive(true); //In scene find and disable if it is already obtained. GameObject sceneItemGameObject = GameObject.Find(regularInventoryItem.ItemName); if (sceneItemGameObject != null) { sceneItemGameObject.SetActive(false); } if (regularInventoryItem.AddToKeysAndItemsInventory) { //Add the item into the keysAndItemsInventory RingInventory.GetInstance().AddItemToKeysAndItemsInventory(regularItem.transform); } else { //Add the item into the CollectablesInventory RingInventory.GetInstance().AddItemToCollectablesInventory(regularItem.transform); } //key.GetComponentInChildren().gameObject.layer = 5; //Added today 11/08/24 Yiannis ChangeLayerRecursively(regularItem.transform, 5); } } // //Flashlight battery life: FlashlightController.GetInstance()._flashlightLife = loadedData.inventoryData.Flashlight.flashlightBatteryLife; ////Update secret items: //SecretsLoadUpdate(loadedData); //Game progress load: // Update the initial cutscene flag GameProgressManager.GetInstance().initialCutscenePlayed = loadedData.gameProgressData.initialCutscenePlayed; GameProgressManager.GetInstance().firefliesAreDead = loadedData.gameProgressData.firefliesAreDead; GameProgressManager.GetInstance().UpdateGameProgress(); //Load the state of the storyline GameProgressManager.GetInstance().currentStorylineState = loadedData.gameProgressData.currentStorylineState; GameProgressManager.GetInstance().loadCurrentStorylineState = true; //In order for the current storyline manager to go to the correct state. //Save the state of the global storyline GameProgressManager.GetInstance().currentGlobalStorylineState = loadedData.gameProgressData.currentGlobalStorylineState; GameProgressManager.GetInstance().loadCurrentGlobalStorylineState = true; //In order for the current storyline manager to go to the correct state. #region Sanity Enable Or Disable GameProgressManager.GetInstance().playerSanityShouldBeEnabledOnGameLoad = loadedData.playerData.playerSanityShouldBeEnabledOnGameLoad; PlayerManager.GetInstance().playerSanity.enabled = GameProgressManager.GetInstance().playerSanityShouldBeEnabledOnGameLoad; #endregion //Change state to Gameplay: GameplayController.GetInstance().GoToGameplayState(); //Fade out black screen: CutscenesManager.GetInstance().FindGameLoadedFadeOutPlayableDirector(); CutscenesManager.GetInstance().gameLoadedFadeOutPlayableDirector.Play(); //LoadingUIClose(); //GameManager.GetInstance().HandleStoryState(GameManager.GetInstance().currentStoryState); print("Game loaded"); //if (GameplayController.GetInstance().demoMode == false) //{ GameManager.GetInstance().LoadCurrentStoryState(); GameManager.GetInstance().HandleStoryState(GameManager.GetInstance().currentStoryState); //} if(SaveableObjectsOnSceneManager.GetInstance()!= null) { foreach (var data in loadedData.sceneSaveData.ObjectsData) { // Βρες το αντικείμενο στη σκηνή με το αντίστοιχο ID SaveableObject obj = SaveableObjectsOnSceneManager.GetInstance().SaveableObjects.Find(o => o.GameObjectID == data.GameObjectID); if (obj != null) { // Ενημέρωσε την κατάσταση ενεργοποίησης obj.gameObject.SetActive(data.IsSetActive); obj.IsSetActiveTrueAfterLoad = data.IsSetActive; } else { Debug.LogWarning("Object with ID " + data.GameObjectID + " not found!"); } } foreach (var data in loadedData.sceneSaveData.DoorsData) { // Βρες το αντικείμενο στη σκηνή με το αντίστοιχο ID SaveableDoor obj = SaveableObjectsOnSceneManager.GetInstance().SaveableDoors.Find(o => o.SaveableDoorID == data.SaveableDoorID); if (obj != null) { obj.doorBehaviour.DoorRequiresKey = data.IsLockedAfterLoad; obj.IsLockedAfterLoad = data.IsLockedAfterLoad; if (!data.IsLockedAfterLoad) //If not locked after load: { obj.doorBehaviour.CanOpenDoor = true; //Can open door. if(obj.doorBehaviour.TryGetComponent(out KeyHole keyHole)) { keyHole.keyAndDoorNameMatch = true; } } } else { Debug.LogWarning("Door Object with ID " + data.SaveableDoorID + " not found!"); } } } foreach (var currentAdditiveScene in loadedData.gameProgressData.currentAdditiveScenes) { DynamicSceneManager.GetInstance().loadedScenes.Add(currentAdditiveScene); } RoomManager.GetInstance().necessarySceneNamesToKeepLoaded = loadedData.gameProgressData.currentNecessaryScenesToKeepLoaded; //AfterLoadingDone?.Invoke(); LoadManager.GetInstance().LoadingGame = false; } } if (LoadManager.GetInstance().IsEnteringNewGame) { //I ADDED TO SEE IF IT WORKS!!!!!!!! //GameplayController.GetInstance().loadAdditiveSceneForGameSystemsAndPlayer.LoadAdditiveScene(); Instantiate(GameplayController.GetInstance().GameSystemsAndPlayer); //--------------------------------------------------------------------------------------------- gameSystems = GameSystemsManager.GetInstance().Systems; gameSystems.SetActive(true); //Initialisation of inventory before adding items into it. RingInventory.GetInstance().InventoryInitialisationForKeysAndItemsAndCollectables(); if (GameplayController.GetInstance().demoMode == false) { if (GameplayController.GetInstance().isInDebuggingState == false) { GameManager.GetInstance().currentStoryState = GameManager.StoryState.Prologue; GameManager.GetInstance().HandleStoryState(GameManager.GetInstance().currentStoryState); } else //IS IN DEBUGGING STATE: { GameManager.GetInstance().HandleStoryState(GameManager.GetInstance().currentStoryState); } } else //If it's in demo mode: { GameManager.GetInstance().currentStoryState = GameManager.StoryState.ChildrenLoopsDemo; GameManager.GetInstance().HandleStoryState(GameManager.GetInstance().currentStoryState); } GameSaveData loadedData = SaveSlotManager.LoadPlayerData(SaveSlotManager.GetInstance().selectedSaveSlotID/*Change later to take the ID of the currently selected Save slot*/); if (loadedData != null) { //White ledges load: LedgesUpdate(loadedData); GameProgressManager.GetInstance().UpdateGameProgress(); //In order to play the first cutscene when entering the new game. //Change state to Gameplay: GameplayController.GetInstance().GoToGameplayState(); //LoadingUIClose(); print("New game entered"); LoadManager.GetInstance().IsEnteringNewGame = false; } } } #region Main Menu related if (GameplayController.GetInstance().IsOnState(GameplayController.State.GameLaunched) || GameplayController.GetInstance().IsOnState(GameplayController.State.MainMenu)) { GameSaveData loadedData = SaveSlotManager.LoadPlayerData(SaveSlotManager.GetInstance().selectedSaveSlotID /*Change later to take the ID of the currently selected Save slot*/); if (loadedData != null) { UpdateOptionsMenuWhiteLedgesHighlightUI(loadedData); if (loadedData.playerData.continueButtonEnabled) { MainMenu.GetInstance().continueButtonIsInteractable(); } else { MainMenu.GetInstance().continueButtonIsNotInteractable(); } } UpdateSaveAndLoadSlotsUI(); UpdateCurrentlySelectedSaveSlotText(loadedData); //LoadingUIClose(); } #endregion } public void UpdateSaveAndLoadSlotsUI() { GameSaveData loadedDataSaveSlot1 = SaveSlotManager.LoadPlayerData(0); if (loadedDataSaveSlot1 != null) { MainMenu.GetInstance().saveSlotsDateTime[0].text = loadedDataSaveSlot1.saveTimestamp; MainMenu.GetInstance().loadSlotDateTime[0].text = loadedDataSaveSlot1.saveTimestamp; } GameSaveData loadedDataSaveSlot2 = SaveSlotManager.LoadPlayerData(1); if (loadedDataSaveSlot2 != null) { MainMenu.GetInstance().saveSlotsDateTime[1].text = loadedDataSaveSlot2.saveTimestamp; MainMenu.GetInstance().loadSlotDateTime[1].text = loadedDataSaveSlot2.saveTimestamp; } GameSaveData loadedDataSaveSlot3 = SaveSlotManager.LoadPlayerData(2); if (loadedDataSaveSlot3 != null) { MainMenu.GetInstance().saveSlotsDateTime[2].text = loadedDataSaveSlot3.saveTimestamp; MainMenu.GetInstance().loadSlotDateTime[2].text = loadedDataSaveSlot3.saveTimestamp; } } public void UpdateCurrentlySelectedSaveSlotUI() { GameSaveData loadedData = SaveSlotManager.LoadPlayerData(SaveSlotManager.GetInstance().selectedSaveSlotID /*Change later to take the ID of the currently selected Save slot*/); UpdateCurrentlySelectedSaveSlotText(loadedData); } public void UpdateCurrentlySelectedSaveSlotText(GameSaveData data) { data = SaveSlotManager.LoadPlayerData(SaveSlotManager.GetInstance().selectedSaveSlotID/*Change later to take the ID of the currently selected Save slot*/); if (data != null) { if (data.saveSlot == 0) { MainMenu.GetInstance().currentlySelectedSaveSlot.text = "Save Slot 1"; } if (data.saveSlot == 1) { MainMenu.GetInstance().currentlySelectedSaveSlot.text = "Save Slot 2"; } if (data.saveSlot == 2) { MainMenu.GetInstance().currentlySelectedSaveSlot.text = "Save Slot 3"; } } } public void UpdateOptionsMenuWhiteLedgesHighlightUI(GameSaveData loadedData) { //if (loadedData.gameOptionsData.whiteLedgesAreOn == false) //{ // OptionsMenu.GetInstance().WhiteLedgesOFFIsHighlighted(); //} //else //{ // OptionsMenu.GetInstance().WhiteLedgesONIsHighlighted(); //} } public void LedgesUpdate(GameSaveData gameSaveData) { if (gameSaveData.gameOptionsData.whiteLedgesAreOn == false) { foreach (var whiteLedge in whiteLedges) { whiteLedge.gameObject.SetActive(false); } } else { foreach (var whiteLedge in whiteLedges) { whiteLedge.gameObject.SetActive(true); } } } private void DeactivateSaveTriggersThatPlayerPassed(PlayerData playerData) { //Save triggers that need to be deactivated: foreach (var saveTrigger in saveTriggers) { foreach (var name in playerData.saveTriggersThatNeedToBeDeactivated) { if (saveTrigger.name == name) { saveTrigger.gameObject.SetActive(false); } } } } public void InventoryItemsUpdate(GameSaveData gameSaveData) { //if() } //// Function to activate a Cinemachine camera by name //public void ActivateCinemachineCameraByName(string cameraName) //{ // // Iterate through the virtualCameras array to find the camera by name // foreach (var CVCam in CameraManager.GetInstance().virtualCameras) // { // if (CVCam.Name == cameraName) // { // //Find the highest priority CMV camera // CameraManager.GetInstance().FindHighestPriorityCamera(); // // Activate the found camera // CVCam.Priority = CameraManager.GetInstance().highestPriorityCamera.Priority + 1; // } // } //} #region Secrets (See if it's possible to replace with the collectables) //private void SecretsLoadUpdate(GameSaveData loadedGameData) //{ // SecretsManager.GetInstance().secretsFoundCount = loadedGameData.playerData.collectedSecretItemCount; // //Deactivate secrets that are already collected: // foreach (var collectedSecretItems in loadedGameData.playerData.collectedSecretItems) // { // foreach (var secretItem in SecretsManager.GetInstance().secretItems) // { // if(secretItem.name == collectedSecretItems) // { // secretItem.gameObject.SetActive(false); // } // } // } //} #endregion public void LoadGame() { LoadManager.GetInstance().LoadGame(); LoadingUIOpen(); } public void NewGame() { LoadManager.GetInstance().NewGame(); LoadingUIOpen(); } public void LoadingUIOpen() { SaveSlotManager.GetInstance().LoadingScreen.SetActive(true); SaveSlotManager.GetInstance().loadingUIAnimator.SetBool("FadeIn",true); Time.timeScale = 0f; TutorialHintManager.GetInstance().DisplayLoadingTutorialHint(); } public void LoadingUIClose() { SaveSlotManager.GetInstance().LoadingScreen.SetActive(false); SaveSlotManager.GetInstance().loadingUIAnimator.SetBool("FadeIn", false); Time.timeScale = 1f; TutorialHintManager.GetInstance().StopDisplayingTutorialHints(); } void ChangeLayerRecursively(Transform obj, int newLayer) { // Skip changing the layer if the object has the VisibilityIcon script if (obj.GetComponent() != null) { return; } // Change the layer of the current child object obj.gameObject.layer = newLayer; // Recursively change the layer of all children foreach (Transform child in obj) { ChangeLayerRecursively(child, newLayer); } } }