Files
HauntedBloodlines/Assets/Scripts/Managers/StorylineManagers/StorylineGlobalManager.cs
2025-05-29 22:31:40 +03:00

151 lines
5.7 KiB
C#

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
public class StorylineGlobalManager : MonoBehaviour
{
[SerializeField] StorylineMirrorLibraryManager StorylineMirrorLibraryManager;
[SerializeField] StorylineChildrenPastManager storylineChildrenPastManager;
private void Start()
{
StartCoroutine(CheckIfLoadIsCompleted());
}
IEnumerator CheckIfLoadIsCompleted()
{
while (LoadManager.GetInstance().LoadingGame || LoadManager.GetInstance().IsEnteringNewGame)
{
print("Still loading...");
yield return null;
}
print("Done loading, updating storyline state");
//When done loading:
StartCoroutine(UpdateGlobalStorylineState());
}
public enum StorylineGlobalState
{
CheckWhatManagerShouldBeActive,
StorylineMirrorLibraryManagerIsActive,
StorylineChildrenPastManagerIsActive
}
public StorylineGlobalState storylineGlobalState = StorylineGlobalState.CheckWhatManagerShouldBeActive;
private void GoToNextStorylineStateAfterLoad()
{
GameProgressManager.GetInstance().loadCurrentGlobalStorylineState = false;
print("Bro please");
}
IEnumerator UpdateGlobalStorylineState()
{
while (GameProgressManager.GetInstance().loadCurrentGlobalStorylineState)
{
UpdateStorylineState();
//if (!GameProgressManager.GetInstance().loadCurrentStorylineState)
//{
// GameProgressManager.GetInstance().loadCurrentGlobalStorylineState = false;
//}
print("Is updating gloabl storyline state");
yield return null;
}
}
IEnumerator ForceFalseLoadCurrentStorylineStateTimer()
{
yield return new WaitForSeconds(1f);
GameProgressManager.GetInstance().loadCurrentStorylineState = false;
}
public void UpdateStorylineState()
{
switch (storylineGlobalState)
{
case StorylineGlobalState.CheckWhatManagerShouldBeActive:
if (GameProgressManager.GetInstance().loadCurrentGlobalStorylineState)
{
if (GameProgressManager.GetInstance().currentGlobalStorylineState != "")//If is not empty
{
//storylineGlobalState = (StorylineGlobalState)Enum.Parse(typeof(StorylineGlobalState), GameProgressManager.GetInstance().currentGlobalStorylineState);
//GoToNextStorylineStateAfterLoad();
storylineGlobalState = (StorylineGlobalState)Enum.Parse(typeof(StorylineGlobalState), GameProgressManager.GetInstance().currentGlobalStorylineState);
}
//else //Else entered the game for the first time
//{
// GameProgressManager.GetInstance().loadCurrentGlobalStorylineState = false;
// storylineGlobalState = StorylineGlobalState.StorylineMirrorLibraryManagerIsActive; //Got to update mirror library because new game started for the demo scene.
//}
}
else //Else entered the game for the first time
{
storylineGlobalState = StorylineGlobalState.StorylineMirrorLibraryManagerIsActive; //Got to update mirror library because new game started for the demo scene.
UpdateStorylineState();
GameProgressManager.GetInstance().loadCurrentGlobalStorylineState = false;
}
break;
case StorylineGlobalState.StorylineMirrorLibraryManagerIsActive:
StorylineMirrorLibraryManager.gameObject.SetActive(true);
StorylineMirrorLibraryManager.UpdateStoryline();
MemorizeTemporarilyCurrentStorylineGlobalState();
print("Entered StorylineMirrorLibraryManagerIsActive");
break;
case StorylineGlobalState.StorylineChildrenPastManagerIsActive:
StorylineMirrorLibraryManager.gameObject.SetActive(false);
storylineChildrenPastManager.gameObject.SetActive(true);
if (GameProgressManager.GetInstance().loadCurrentStorylineState) //If it should load the current storylinestate:)
{
storylineChildrenPastManager.UpdateStorylineAfterLoad();
print("Updated storyline after load");
}
else
{
storylineChildrenPastManager.UpdateStoryline();
}
MemorizeTemporarilyCurrentStorylineGlobalState();
print("Entered StorylineChildrenPastManagerIsActive");
break;
default:
break;
}
}
public void MemorizeTemporarilyCurrentStorylineGlobalState()
{
GameProgressManager.GetInstance().currentGlobalStorylineState = storylineGlobalState.ToString();
}
/// <summary>
/// /Increases to the next loop
/// </summary>
public void UpdateToTheNextCurrentStorylineGlobalState()
{
// Get all values of the enum
StorylineGlobalState[] allCases = (StorylineGlobalState[])Enum.GetValues(typeof(StorylineGlobalState));
// Get the index of the current case
int currentIndex = Array.IndexOf(allCases, storylineGlobalState);
// 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
storylineGlobalState = allCases[currentIndex];
UpdateStorylineState();
}
}