102 lines
3.9 KiB
C#
102 lines
3.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using System;
|
|
|
|
public class StorylinePrologueManager : MonoBehaviour
|
|
{
|
|
[SerializeField] private Transform playerNewGameStartPosition;
|
|
|
|
private void Start()
|
|
{
|
|
StartCoroutine(CheckIfLoadIsCompleted());
|
|
}
|
|
|
|
IEnumerator CheckIfLoadIsCompleted()
|
|
{
|
|
while (LoadManager.GetInstance().LoadingGame || LoadManager.GetInstance().IsEnteringNewGame)
|
|
{
|
|
yield return null;
|
|
}
|
|
//When done loading:
|
|
UpdateStoryline();
|
|
}
|
|
|
|
public enum PrologueStorylineState
|
|
{
|
|
CheckLoad,
|
|
InsideCar,
|
|
ExitedCar,
|
|
OutsideHouse
|
|
}
|
|
|
|
public PrologueStorylineState prologueStorylineState = PrologueStorylineState.CheckLoad;
|
|
|
|
public void UpdateStoryline()
|
|
{
|
|
switch (prologueStorylineState)
|
|
{
|
|
case PrologueStorylineState.CheckLoad:
|
|
if (GameProgressManager.GetInstance().initialCutscenePlayed) //This is when you have entered the game the first time.
|
|
{
|
|
|
|
prologueStorylineState = (PrologueStorylineState)Enum.Parse(typeof(PrologueStorylineState), GameProgressManager.GetInstance().currentStorylineState);
|
|
}
|
|
else
|
|
{
|
|
GameProgressManager.GetInstance().initialCutscenePlayed = true; //CHANGE LATER.
|
|
GameProgressManager.GetInstance().playerControllerShouldBeEnabledOnGameLoad = false; //Player controller should not be enabled at start because you're inside the car when the game starts.
|
|
GameProgressManager.GetInstance().playerCameraControllerShouldBeEnabledOnGameLoad = true;
|
|
GameProgressManager.GetInstance().playerSanityShouldBeEnabledOnGameLoad = false;
|
|
PlayerManager.GetInstance().playerSanity.enabled = false;
|
|
print("Started game position");
|
|
|
|
PlayerManager.GetInstance().DisablePlayerMovement();
|
|
//Player start position should be the one inside the car.
|
|
PlayerManager.GetInstance().playerGameObj.transform.position = playerNewGameStartPosition.position;
|
|
PlayerManager.GetInstance().playerGameObj.transform.rotation = playerNewGameStartPosition.rotation;
|
|
PlayerManager.GetInstance().playerGameObj.transform.SetParent(playerNewGameStartPosition); //sets the new parent of player in order to be inside the car.
|
|
PlayerManager.GetInstance()._cameraMovement.cameraCarMovement = true; //Enables the camera movement for the car.
|
|
UpdateToTheNextStorylineState(); //In order to go to: BeforeMirrorLibrary State.
|
|
}
|
|
|
|
break;
|
|
case PrologueStorylineState.InsideCar:
|
|
MemorizeTemporarilyCurrentStorylineState();
|
|
break;
|
|
case PrologueStorylineState.ExitedCar:
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
public void MemorizeTemporarilyCurrentStorylineState()
|
|
{
|
|
GameProgressManager.GetInstance().currentStorylineState = prologueStorylineState.ToString();
|
|
}
|
|
|
|
public void UpdateToTheNextStorylineState()
|
|
{
|
|
// Get all values of the enum
|
|
PrologueStorylineState[] allCases = (PrologueStorylineState[])Enum.GetValues(typeof(PrologueStorylineState));
|
|
|
|
// Get the index of the current case
|
|
int currentIndex = Array.IndexOf(allCases, prologueStorylineState);
|
|
|
|
// 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
|
|
prologueStorylineState = allCases[currentIndex];
|
|
|
|
UpdateStoryline();
|
|
}
|
|
}
|