Implement hand menu features

This commit is contained in:
2024-09-07 20:42:45 +02:00
parent f690fb53c8
commit 3357191134
621 changed files with 410674 additions and 3861 deletions

View File

@@ -4,6 +4,7 @@ using System.Collections;
using System.Collections.Generic;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using Zenject;
@@ -36,13 +37,6 @@ public class SceneManager : NetworkBehaviour
[ReadOnly]
private string forgeSceneName;
//enum Scene
//{
// Lobby = 0,
// Entrance = 1,
// Forge = 2
//}
[Inject]
[ReadOnly]
[SerializeField]
@@ -56,10 +50,25 @@ public class SceneManager : NetworkBehaviour
[SerializeField]
private Scene loadedScene;
public Scene LoadedScene => loadedScene;
public bool IsInLobby => loadedScene.name == lobbySceneName;
public UnityEvent SceneLoaded;
private bool isMultiplayer => gameManager.IsMultiplayer;
private void Awake()
{
loadedScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene();
}
public override void OnNetworkSpawn()
{
NetworkManager.SceneManager.OnSceneEvent += OnSceneEvent;
Debug.Log("network spawn");
base.OnNetworkSpawn();
}
@@ -76,6 +85,7 @@ public class SceneManager : NetworkBehaviour
{
// Keep track of the loaded scene, you need this to unload it
loadedScene = sceneEvent.Scene;
SceneLoaded.Invoke();
}
Debug.Log($"Loaded the {sceneEvent.SceneName} scene on " +
@@ -135,19 +145,31 @@ public class SceneManager : NetworkBehaviour
[Button]
public void SwitchToLobbyLevel()
{
StartCoroutine(SwitchToSceneMultiplayer(lobbySceneName));
SwitchToScene(lobbySceneName);
}
[Button]
public void SwitchToEntranceLevel()
{
StartCoroutine(SwitchToSceneMultiplayer(entranceSceneName));
SwitchToScene(entranceSceneName);
}
[Button]
public void SwitchToForgeLevel()
{
StartCoroutine(SwitchToSceneMultiplayer(forgeSceneName));
SwitchToScene(forgeSceneName);
}
private void SwitchToScene(string sceneName)
{
if (isMultiplayer)
{
StartCoroutine(SwitchToSceneMultiplayer(sceneName));
}
else
{
StartCoroutine(SwitchToSceneSolo(sceneName));
}
}
private IEnumerator SwitchToSceneMultiplayer(string scene)
@@ -176,29 +198,27 @@ public class SceneManager : NetworkBehaviour
//gameManager.LocalPlayer.FadeScreen(0, fadeDuration);
}
//private IEnumerator SwitchToSceneSolo(Scene scene)
//{
// gameManager.LocalPlayer.FadeScreen(1, fadeDuration);
private IEnumerator SwitchToSceneSolo(string scene)
{
gameManager.LocalPlayer.FadeScreen(1, fadeDuration);
// //NetworkManager.SceneManager.LoadScene()
var operation = UnityEngine.SceneManagement.SceneManager
.LoadSceneAsync(scene);
// var operation = UnityEngine.SceneManagement.SceneManager
// .LoadSceneAsync((int)scene);
operation.allowSceneActivation = false;
// operation.allowSceneActivation = false;
// float timer = 0;
float timer = 0;
// while (timer <= fadeDuration && !operation.isDone)
// {
// timer += Time.deltaTime;
// yield return null;
// }
while (timer <= fadeDuration && !operation.isDone)
{
timer += Time.deltaTime;
yield return null;
}
// operation.allowSceneActivation = true;
operation.allowSceneActivation = true;
// this.scene = scene;
gameManager.LocalPlayer.FadeScreen(0, fadeDuration);
// gameManager.LocalPlayer.FadeScreen(0, fadeDuration);
//}
loadedScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene();
}
}