You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.0 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
namespace UltraCombos.Marvel.DrawHeroes
{
public class SceneLoader : MonoBehaviour
{
[Configuration.Config]
[Range(0, 300)]
public float duration = 0.0f;
float duration_stamp;
public string scenePath = "MainScene";
bool is_scene_loading = false;
ImageFader fader;
[System.Serializable]
public class CountdownEvent : UnityEvent<float, float> { }
[Space(10)]
public CountdownEvent onCountdown = new CountdownEvent();
public UnityEvent onLoadScene = new UnityEvent();
private void Start()
{
Configuration.GrpcServer.Instance.LoadSettings();
duration_stamp = Time.time;
fader = GetComponent<ImageFader>();
if (fader == null) fader = gameObject.AddComponent<ImageFader>();
}
private void Update()
{
if (duration > 0.0f && is_scene_loading == false)
{
float elapsed_time = Time.time - duration_stamp;
if (elapsed_time > duration)
{
LoadScene();
}
else
{
onCountdown.Invoke(duration, elapsed_time);
}
}
}
public void LoadScene()
{
if (is_scene_loading)
return;
is_scene_loading = true;
fader.SetActive(true);
//onLoadScene.Invoke();
//UnityEngine.SceneManagement.SceneManager.LoadScene(scenePath);
StartCoroutine(OnLoadSceneAsync());
}
private IEnumerator OnLoadSceneAsync()
{
onLoadScene.Invoke();
yield return new WaitForSeconds(1.0f);
yield return UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(scenePath);
}
}
}