231 lines
7.7 KiB
C#
231 lines
7.7 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
public class TestingSceneManager : MonoBehaviour
|
|
{
|
|
[Header("Testing Scene Setup")]
|
|
[Tooltip("Check if we're loading a saved game in the Testing Scene section")]
|
|
[SerializeField] private Transform playerNewGameStartPosition;
|
|
public bool isLoadingTestingScene;
|
|
|
|
[Header("Puzzle Objects")]
|
|
[Tooltip("Reference to the puzzle GameObject if applicable")]
|
|
[SerializeField] private GameObject puzzleGameObject;
|
|
[Tooltip("Optional puzzle solved effects, if needed")]
|
|
[SerializeField] private GameObject puzzleSolvedEffects;
|
|
|
|
// 1. Define the loop states (8 loops + 1 puzzle)
|
|
public enum TestingSceneState
|
|
{
|
|
CheckLoad,
|
|
TestingSceneGameplay
|
|
}
|
|
|
|
// Current loop state
|
|
public TestingSceneState testingSceneState = TestingSceneState.CheckLoad;
|
|
|
|
|
|
private void Awake()
|
|
{
|
|
// Assign this manager to GameManager so it can be activated/deactivated appropriately
|
|
if (GameManager.GetInstance() != null)
|
|
{
|
|
GameManager.GetInstance().testingSceneManager = this;
|
|
}
|
|
|
|
// If we are loading a saved game, mark accordingly
|
|
if (LoadManager.GetInstance() != null && LoadManager.GetInstance().LoadingGame)
|
|
{
|
|
isLoadingTestingScene = true;
|
|
}
|
|
}
|
|
|
|
public void Activate()
|
|
{
|
|
Debug.Log("Testing Scene Manager Activated: Initializing Children Loops.");
|
|
//TryLoadSavedState();
|
|
UpdateStoryline();
|
|
}
|
|
|
|
public void Deactivate()
|
|
{
|
|
Debug.Log("Testing Scene Manager Deactivated.");
|
|
|
|
StopAllCoroutines();
|
|
SaveStorylineState();
|
|
CleanupPlayerSettings();
|
|
|
|
// If you want to automatically progress upon deactivation, uncomment below:
|
|
// NotifyCompletion();
|
|
}
|
|
|
|
public void UpdateStoryline()
|
|
{
|
|
switch (testingSceneState)
|
|
{
|
|
case TestingSceneState.CheckLoad:
|
|
HandleCheckLoadState();
|
|
|
|
break;
|
|
|
|
case TestingSceneState.TestingSceneGameplay:
|
|
Debug.Log("Testing Scene Gameplay activated.");
|
|
if (isLoadingTestingScene)
|
|
{
|
|
isLoadingTestingScene = false;
|
|
}
|
|
SaveStorylineState();
|
|
break;
|
|
|
|
default:
|
|
Debug.LogWarning("Unhandled Testing Scene State: " + testingSceneState);
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void HandleCheckLoadState()
|
|
{
|
|
if (IsInitialCutscenePlayed())
|
|
{
|
|
print("Try Load Saved State");
|
|
TryLoadSavedState();
|
|
}
|
|
else //If started new game for the first time:
|
|
{
|
|
print("New game started");
|
|
PlayInitialCutscene();
|
|
SetupPlayer(playerNewGameStartPosition, enableCameraCarMovement: false, enablePlayerController: true,
|
|
pocketWatchIsObtained: false);
|
|
UpdateToNextStorylineState();
|
|
}
|
|
}
|
|
private bool IsInitialCutscenePlayed() => GameProgressManager.GetInstance().initialCutscenePlayed;
|
|
|
|
private void PlayInitialCutscene()
|
|
{
|
|
Debug.Log("Playing initial cutscene...");
|
|
SetInitialCutscenePlayed(true);
|
|
var gameProgressManager = GameProgressManager.GetInstance();
|
|
gameProgressManager.playerControllerShouldBeEnabledOnGameLoad = false;
|
|
gameProgressManager.playerCameraControllerShouldBeEnabledOnGameLoad = true;
|
|
}
|
|
private void SetInitialCutscenePlayed(bool value) => GameProgressManager.GetInstance().initialCutscenePlayed = value;
|
|
|
|
private void SetupPlayer(Transform newPosition, bool enableCameraCarMovement, bool enablePlayerController, bool pocketWatchIsObtained)
|
|
{
|
|
var playerManager = PlayerManager.GetInstance();
|
|
if (playerManager == null)
|
|
{
|
|
Debug.LogError("PlayerManager instance is missing!");
|
|
return;
|
|
}
|
|
|
|
//playerManager.DisablePlayerMovement();
|
|
playerManager.playerGameObj.transform.position = newPosition.position;
|
|
playerManager.playerGameObj.transform.rotation = newPosition.rotation;
|
|
playerManager.playerGameObj.transform.SetParent(newPosition);
|
|
playerManager._cameraMovement.cameraCarMovement = enableCameraCarMovement;
|
|
|
|
var gameProgressManager = GameProgressManager.GetInstance();
|
|
gameProgressManager.playerControllerShouldBeEnabledOnGameLoad = enablePlayerController;
|
|
gameProgressManager.PocketWatchIsObtained = pocketWatchIsObtained;
|
|
InventoryManager.GetInstance().SaveTemporarilyPocketWatchInventoryItemData(true); //Obtained pocket watch so save temporarily.
|
|
}
|
|
|
|
/// <summary>
|
|
/// Moves to the next loop/puzzle state, if available.
|
|
/// </summary>
|
|
public void UpdateToNextStorylineState()
|
|
{
|
|
TestingSceneState[] allStates = (TestingSceneState[])Enum.GetValues(typeof(TestingSceneState));
|
|
int currentIndex = Array.IndexOf(allStates, testingSceneState);
|
|
|
|
if (currentIndex < allStates.Length - 1)
|
|
{
|
|
// Move to the next state
|
|
testingSceneState = allStates[currentIndex + 1];
|
|
UpdateStoryline();
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("All Testing Scene & Puzzles are complete.");
|
|
NotifyCompletion();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Attempt to load the saved Children loop state from GameProgressManager.
|
|
/// </summary>
|
|
private void TryLoadSavedState()
|
|
{
|
|
var gameProgressManager = GameProgressManager.GetInstance();
|
|
if (gameProgressManager == null) return;
|
|
|
|
if (Enum.TryParse(gameProgressManager.currentStorylineState, out TestingSceneState savedState))
|
|
{
|
|
testingSceneState = savedState;
|
|
Debug.Log("Loaded Children Loop State from save: " + savedState);
|
|
UpdateStoryline();
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning("No valid saved Children Loop state found. Starting at Long Hallway Before Mirror Library.");
|
|
testingSceneState = TestingSceneState.TestingSceneGameplay;
|
|
UpdateStoryline();
|
|
}
|
|
|
|
// After loading, no longer in a loading phase
|
|
isLoadingTestingScene = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Saves the current Children loop state to GameProgressManager.
|
|
/// </summary>
|
|
private void SaveStorylineState()
|
|
{
|
|
var gameProgressManager = GameProgressManager.GetInstance();
|
|
if (gameProgressManager == null) return;
|
|
|
|
gameProgressManager.currentStorylineState = testingSceneState.ToString();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Performs any final logic, then notifies GameManager this section is complete.
|
|
/// </summary>
|
|
private void NotifyCompletion()
|
|
{
|
|
// Let GameManager know this story section (ChildrenLoops) is done
|
|
GameManager.GetInstance().OnStorySectionComplete(GameManager.StoryState.ChildrenLoops);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Resets or cleans up player settings if needed.
|
|
/// </summary>
|
|
private void CleanupPlayerSettings()
|
|
{
|
|
var playerManager = PlayerManager.GetInstance();
|
|
if (playerManager != null)
|
|
{
|
|
// Example: disable or reset player movement or camera
|
|
// playerManager.DisablePlayerMovement();
|
|
}
|
|
|
|
Debug.Log("Cleaned up settings specific to Children Loops.");
|
|
}
|
|
|
|
// ------------------------ Puzzle Handler ------------------------
|
|
private void HandlePuzzle()
|
|
{
|
|
// Activate puzzle elements
|
|
if (puzzleGameObject != null)
|
|
{
|
|
puzzleGameObject.SetActive(true);
|
|
}
|
|
|
|
// Optionally handle puzzle-solved scenario:
|
|
// puzzleSolvedEffects.SetActive(true); // if puzzle is solved
|
|
// Then call UpdateToNextLoopState() or NotifyCompletion() if final
|
|
}
|
|
}
|
|
|