119 lines
4.5 KiB
C#
119 lines
4.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using System;
|
|
|
|
public class StorylineMirrorLibraryManager : MonoBehaviour
|
|
{
|
|
[SerializeField] private Transform playerNewGameStartPosition;
|
|
|
|
[SerializeField] private GameObject sceneRoot_MirrorLibrary;
|
|
[SerializeField] private GameObject libraryRoot;
|
|
[SerializeField] private GameObject hallwayBeforeLibrary;
|
|
[SerializeField] private GameObject hallwayAfterLibrary;
|
|
[SerializeField] private GameObject sceneRoot_ChildrenLoops;
|
|
|
|
//private void Update()
|
|
//{
|
|
// UpdateStoryline();
|
|
//}
|
|
|
|
private void Start()
|
|
{
|
|
//Commented out for testing one single scene.
|
|
//StartCoroutine(CheckIfLoadIsCompleted());
|
|
}
|
|
|
|
IEnumerator CheckIfLoadIsCompleted()
|
|
{
|
|
while (LoadManager.GetInstance().LoadingGame || LoadManager.GetInstance().IsEnteringNewGame)
|
|
{
|
|
yield return null;
|
|
}
|
|
//When done loading:
|
|
UpdateStoryline();
|
|
}
|
|
|
|
public enum MirrorLibraryStorylineState
|
|
{
|
|
CheckLoad,
|
|
BeforeMirrorLibrary,
|
|
EnteredMirrorLibrary,
|
|
AfterMirrorLibrary
|
|
}
|
|
|
|
public MirrorLibraryStorylineState mirrorLibraryStorylineState = MirrorLibraryStorylineState.CheckLoad;
|
|
|
|
public void UpdateStoryline()
|
|
{
|
|
switch (mirrorLibraryStorylineState)
|
|
{
|
|
case MirrorLibraryStorylineState.CheckLoad:
|
|
if (GameProgressManager.GetInstance().initialCutscenePlayed) //This is when you have entered the game the first time.
|
|
{
|
|
mirrorLibraryStorylineState = (MirrorLibraryStorylineState)Enum.Parse(typeof(MirrorLibraryStorylineState), GameProgressManager.GetInstance().currentStorylineState);
|
|
UpdateStoryline();
|
|
}
|
|
else
|
|
{
|
|
GameProgressManager.GetInstance().initialCutscenePlayed = true; //CHANGE LATER.
|
|
GameProgressManager.GetInstance().playerControllerShouldBeEnabledOnGameLoad = true;
|
|
GameProgressManager.GetInstance().playerCameraControllerShouldBeEnabledOnGameLoad = true;
|
|
print("Started game position");
|
|
PlayerManager.GetInstance().playerGameObj.transform.position = playerNewGameStartPosition.position;
|
|
PlayerManager.GetInstance().playerGameObj.transform.rotation = playerNewGameStartPosition.rotation;
|
|
UpdateToTheNextStorylineState(); //In order to go to: BeforeMirrorLibrary State.
|
|
}
|
|
BackgroundSoundsManager.GetInstance().PlayHouseSounds();
|
|
break;
|
|
case MirrorLibraryStorylineState.BeforeMirrorLibrary:
|
|
sceneRoot_MirrorLibrary.gameObject.SetActive(true);
|
|
libraryRoot.gameObject.SetActive(true);
|
|
hallwayBeforeLibrary.SetActive(true);
|
|
MemorizeTemporarilyCurrentStorylineState();
|
|
break;
|
|
case MirrorLibraryStorylineState.EnteredMirrorLibrary:
|
|
sceneRoot_MirrorLibrary.gameObject.SetActive(true);
|
|
libraryRoot.gameObject.SetActive(true);
|
|
MemorizeTemporarilyCurrentStorylineState();
|
|
break;
|
|
case MirrorLibraryStorylineState.AfterMirrorLibrary:
|
|
sceneRoot_MirrorLibrary.gameObject.SetActive(true);
|
|
hallwayAfterLibrary.gameObject.SetActive(true);
|
|
sceneRoot_ChildrenLoops.gameObject.SetActive(true);
|
|
MemorizeTemporarilyCurrentStorylineState();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
public void MemorizeTemporarilyCurrentStorylineState()
|
|
{
|
|
GameProgressManager.GetInstance().currentStorylineState = mirrorLibraryStorylineState.ToString();
|
|
}
|
|
|
|
public void UpdateToTheNextStorylineState()
|
|
{
|
|
// Get all values of the enum
|
|
MirrorLibraryStorylineState[] allCases = (MirrorLibraryStorylineState[])Enum.GetValues(typeof(MirrorLibraryStorylineState));
|
|
|
|
// Get the index of the current case
|
|
int currentIndex = Array.IndexOf(allCases, mirrorLibraryStorylineState);
|
|
|
|
// Increment the index
|
|
currentIndex++;
|
|
|
|
// Wrap around if it exceeds the array length
|
|
if (currentIndex >= allCases.Length)
|
|
{
|
|
currentIndex = 0; // Go back to the first case or handle differently if desired
|
|
}
|
|
|
|
// Update the current case
|
|
mirrorLibraryStorylineState = allCases[currentIndex];
|
|
|
|
UpdateStoryline();
|
|
}
|
|
}
|