Add lobby and scene managers, implement scene switching with fade in/out
This commit is contained in:
60
Assets/Scripts/Managers/SceneManager.cs
Normal file
60
Assets/Scripts/Managers/SceneManager.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using HurricaneVR.Framework.Core.Player;
|
||||
using Sirenix.OdinInspector;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using Zenject;
|
||||
|
||||
public class SceneManager : MonoBehaviour
|
||||
{
|
||||
enum Scene
|
||||
{
|
||||
Lobby = 0,
|
||||
Entrance = 1,
|
||||
Forge = 2
|
||||
}
|
||||
|
||||
[Inject]
|
||||
[ReadOnly]
|
||||
[SerializeField]
|
||||
private HVRPlayerController playerController;
|
||||
|
||||
[ReadOnly]
|
||||
[SerializeField]
|
||||
private float fadeDuration = 2f;
|
||||
|
||||
[ReadOnly]
|
||||
[SerializeField]
|
||||
private Scene scene;
|
||||
|
||||
[Button]
|
||||
public void SwitchToEntranceLevel()
|
||||
{
|
||||
StartCoroutine(SwitchToScene(Scene.Entrance));
|
||||
}
|
||||
|
||||
private IEnumerator SwitchToScene(Scene scene)
|
||||
{
|
||||
playerController.ScreenFader.Fade(1, fadeDuration);
|
||||
|
||||
var operation = UnityEngine.SceneManagement.SceneManager
|
||||
.LoadSceneAsync((int)scene);
|
||||
|
||||
operation.allowSceneActivation = false;
|
||||
|
||||
float timer = 0;
|
||||
|
||||
while (timer <= fadeDuration && !operation.isDone)
|
||||
{
|
||||
timer += Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
operation.allowSceneActivation = true;
|
||||
|
||||
this.scene = scene;
|
||||
|
||||
playerController.ScreenFader.Fade(0, fadeDuration);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user