61 lines
1.2 KiB
C#
61 lines
1.2 KiB
C#
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 GameManager gameManager;
|
|
|
|
[ReadOnly]
|
|
[SerializeField]
|
|
private float fadeDuration = 2f;
|
|
|
|
[ReadOnly]
|
|
[SerializeField]
|
|
private Scene scene;
|
|
|
|
[Button]
|
|
public void SwitchToEntranceLevel()
|
|
{
|
|
StartCoroutine(SwitchToScene(Scene.Entrance));
|
|
}
|
|
|
|
private IEnumerator SwitchToScene(Scene scene)
|
|
{
|
|
gameManager.LocalPlayer.FadeScreen(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;
|
|
|
|
gameManager.LocalPlayer.FadeScreen(0, fadeDuration);
|
|
}
|
|
}
|