Add lobby and scene managers, implement scene switching with fade in/out

This commit is contained in:
2024-08-20 18:47:34 +02:00
parent 0d490be61a
commit 3f64f82464
28 changed files with 353 additions and 19 deletions

View File

@@ -1,4 +1,5 @@
using HurricaneVR.Framework.Core;
using HurricaneVR.Framework.Core.Player;
using HurricaneVR.Framework.Core.Utils;
using UnityEngine;
using Zenject;
@@ -16,6 +17,9 @@ public class GlobalInstaller : MonoInstaller
[SerializeField]
private GameObject playerPrefab;
[SerializeField]
private GameObject sceneManagerPrefab;
public override void Start()
{
base.Start();
@@ -42,12 +46,21 @@ public class GlobalInstaller : MonoInstaller
})
.NonLazy();
Container.Bind<HVRObjectCollisionDisabler>()
Container.Bind<HVRPlayerController>()
.FromComponentInNewPrefab(playerPrefab)
.AsSingle()
.OnInstantiated<HVRObjectCollisionDisabler>((ctx, obj) =>
.OnInstantiated<HVRPlayerController>((ctx, obj) =>
{
obj.name = playerPrefab.name;
obj.transform.parent.name = playerPrefab.name;
})
.NonLazy();
Container.Bind<SceneManager>()
.FromComponentInNewPrefab(sceneManagerPrefab)
.AsSingle()
.OnInstantiated<SceneManager>((ctx, obj) =>
{
obj.name = sceneManagerPrefab.name;
})
.NonLazy();
}

View File

@@ -1,18 +1,17 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Zenject;
public class LobbyInstaller : MonoBehaviour
public class LobbyInstaller : MonoInstaller
{
// Start is called before the first frame update
void Start()
public override void InstallBindings()
{
Container.Bind<LobbyManager>()
.FromComponentsInNewPrefabResource("Managers/LobbyManager")
.AsSingle()
.OnInstantiated<LobbyManager>((ctx, obj) =>
{
obj.name = "LobbyManager";
})
.NonLazy();
}
// Update is called once per frame
void Update()
{
}
}
}

View File

@@ -0,0 +1,21 @@
using Sirenix.OdinInspector;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Zenject;
public class LobbyManager : MonoBehaviour
{
[Inject]
[SerializeField]
[ReadOnly]
private MusicManager musicManager;
[SerializeField]
private AudioClip backgroundMusicClip;
private void Start()
{
musicManager.Play(backgroundMusicClip);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b8b4a0794fa1d6c44adcec647be166a6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View 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);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 324a182340742c54cbdb3967f1916e29
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: