XRoom_Unity/Assets/BNG Framework/Scripts/Extras/SceneLoader.cs
2025-05-31 10:20:20 +03:30

73 lines
2.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using Fusion.Addons.ConnectionManagerAddon;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace BNG {
public class SceneLoader : MonoBehaviour {
[Tooltip("The Unity 'LoadSceneMode' method of loading the scene (In most cases should be 'Single'). ")]
public LoadSceneMode loadSceneMode = LoadSceneMode.Single;
[Tooltip("If true, the ScreenFader component will fade the screen to black before loading a level.")]
public bool UseSceenFader = true;
[Tooltip("Wait this long in seconds before attempting to load the scene. Useful if you need to fade the screen out before attempting to load the level.")]
public float ScreenFadeTime = 0.5f;
ScreenFader sf;
public void Update()
{
}
private string _loadSceneName = string.Empty;
public void LoadScene(string SceneName) {
_loadSceneName = SceneName;
if (UseSceenFader) {
StartCoroutine("FadeThenLoadScene");
}
else {
SceneManager.LoadScene(_loadSceneName, loadSceneMode);
}
}
public IEnumerator FadeThenLoadScene() {
if (UseSceenFader) {
if (sf == null) {
sf = FindObjectOfType<ScreenFader>();
// May not have found anything
if (sf != null) {
sf.DoFadeIn();
}
}
}
if(ScreenFadeTime > 0) {
yield return new WaitForSeconds(ScreenFadeTime);
}
SceneManager.LoadScene(_loadSceneName, loadSceneMode);
}
public Color[] colors;
public void CreateMarker(int i)
{
ConnectionManager.instance.CreateMarker(transform, colors[i]);
}
public void CreateTablet()
{
// ConnectionManager.instance.CreateTablet(transform);
}
public void CreateLaser()
{
ConnectionManager.instance.CreateLaser(transform);
}
}
}