Initial commit
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
using UnityEngine.TestTools;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace BracerLib.UI
|
||||
{
|
||||
/// A concrete subclass of the Unity UI `Graphic` class that just skips drawing.
|
||||
/// Useful for providing a raycast target without actually drawing anything.
|
||||
[ExcludeFromCoverage]
|
||||
public class NonDrawingGraphic : Graphic
|
||||
{
|
||||
public override void SetMaterialDirty() { }
|
||||
|
||||
public override void SetVerticesDirty() { }
|
||||
|
||||
/// Probably not necessary since the chain of calls `Rebuild()`->`UpdateGeometry()`->`DoMeshGeneration()`->`OnPopulateMesh()` won't happen; so here really just as a fail-safe.
|
||||
protected override void OnPopulateMesh(VertexHelper vh)
|
||||
{
|
||||
vh.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b78fc1af781b54e4392ff1040214c054
|
||||
@@ -0,0 +1,88 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace BracerLib.UI
|
||||
{
|
||||
public class SceneLoadingManager : MonoBehaviour
|
||||
{
|
||||
private static SceneLoadingManager _instance;
|
||||
|
||||
public static void LoadScenes(string[] scenePath, LoadSceneMode sceneMode)
|
||||
{
|
||||
if (!ValidInstance())
|
||||
return;
|
||||
|
||||
_instance.TryLoadScenes(scenePath, sceneMode);
|
||||
}
|
||||
|
||||
public static void Show()
|
||||
{
|
||||
if (ValidInstance())
|
||||
_instance.Toggle(true);
|
||||
}
|
||||
|
||||
public static void Hide()
|
||||
{
|
||||
if (ValidInstance())
|
||||
_instance.Toggle(false);
|
||||
}
|
||||
|
||||
private static bool ValidInstance()
|
||||
{
|
||||
if (_instance != null)
|
||||
return true;
|
||||
|
||||
Debug.LogError("No Load Screen Manager found.");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
private GameObject _loadingScreenGameObject;
|
||||
|
||||
private Coroutine _sceneLoadingCoroutine;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
DontDestroyOnLoad(_loadingScreenGameObject);
|
||||
if (_instance != null)
|
||||
{
|
||||
Debug.LogError("Multiple LoadScreenManagers found. Please delete one", this);
|
||||
Destroy(this);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
_instance = this;
|
||||
}
|
||||
|
||||
private void TryLoadScenes(string[] scenePaths, LoadSceneMode sceneMode)
|
||||
{
|
||||
if (_sceneLoadingCoroutine != null)
|
||||
{
|
||||
Debug.LogError("SceneLoadingManager is already loading scenes.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
_sceneLoadingCoroutine = StartCoroutine(LoadSceneCoroutine(scenePaths, sceneMode));
|
||||
}
|
||||
|
||||
private IEnumerator LoadSceneCoroutine(string[] scenePaths, LoadSceneMode sceneMode)
|
||||
{
|
||||
Show();
|
||||
|
||||
for (var i = 0; i < scenePaths.Length; i++)
|
||||
yield return SceneManager.LoadSceneAsync(scenePaths[i], sceneMode);
|
||||
|
||||
Hide();
|
||||
_sceneLoadingCoroutine = null;
|
||||
}
|
||||
|
||||
private void Toggle(bool state)
|
||||
{
|
||||
_loadingScreenGameObject.SetActive(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7e94d21e86e94de46b81f938aa50a29e
|
||||
Reference in New Issue
Block a user