100 lines
3.2 KiB
C#
100 lines
3.2 KiB
C#
using System;
|
|
using System.Collections;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
|
|
namespace InterfaceOff
|
|
{
|
|
public class SceneController : MonoBehaviour
|
|
{
|
|
private static SceneController Instance;
|
|
|
|
private RectTransform ImageRectOverlay;
|
|
private Canvas OverlayCanvas;
|
|
|
|
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
|
|
private static void InitializeBeforeSceneLoad()
|
|
{
|
|
GameObject go = new(nameof(SceneController));
|
|
go.AddComponent<SceneController>();
|
|
|
|
DontDestroyOnLoad(go);
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
OverlayCanvas = transform.AddComponent<Canvas>();
|
|
OverlayCanvas.renderMode = RenderMode.ScreenSpaceOverlay;
|
|
OverlayCanvas.worldCamera = Camera.main;
|
|
OverlayCanvas.sortingOrder = 1;
|
|
|
|
GameObject imageHolder = new("ImageHolder");
|
|
imageHolder.transform.SetParent(OverlayCanvas.transform);
|
|
|
|
Image overlayImage = imageHolder.AddComponent<Image>();
|
|
overlayImage.color = Color.black;
|
|
|
|
ImageRectOverlay = imageHolder.GetComponent<RectTransform>();
|
|
|
|
ImageRectOverlay.sizeDelta = new Vector2(0f, 0f);
|
|
ImageRectOverlay.anchoredPosition = new Vector2(0f, 0f);
|
|
|
|
Instance = this;
|
|
}
|
|
|
|
private IEnumerator Load(Action loadAction)
|
|
{
|
|
Vector2 maxSize = new(5000f, 5000f);
|
|
Vector2 minSize = Vector2.zero;
|
|
|
|
float startRotation = ImageRectOverlay.eulerAngles.z;
|
|
float expandRotation = startRotation + 360f;
|
|
float shrinkRotation = expandRotation + 360f;
|
|
|
|
float t = 0f;
|
|
|
|
while (t < 1f)
|
|
{
|
|
ImageRectOverlay.sizeDelta = Vector2.Lerp(minSize, maxSize, t);
|
|
ImageRectOverlay.rotation = Quaternion.Euler(
|
|
0f, 0f, Mathf.Lerp(startRotation, expandRotation, t));
|
|
|
|
t += Time.deltaTime * 2;
|
|
yield return null;
|
|
}
|
|
|
|
ImageRectOverlay.sizeDelta = maxSize;
|
|
ImageRectOverlay.rotation = Quaternion.Euler(0f, 0f, expandRotation);
|
|
|
|
loadAction?.Invoke();
|
|
yield return new WaitForSeconds(0.2f);
|
|
|
|
t = 0f;
|
|
|
|
while (t < 1f)
|
|
{
|
|
ImageRectOverlay.sizeDelta = Vector2.Lerp(maxSize, minSize, t);
|
|
ImageRectOverlay.rotation = Quaternion.Euler(
|
|
0f, 0f, Mathf.Lerp(expandRotation, shrinkRotation, t));
|
|
|
|
t += Time.deltaTime * 2;
|
|
yield return null;
|
|
}
|
|
|
|
ImageRectOverlay.sizeDelta = minSize;
|
|
ImageRectOverlay.rotation = Quaternion.Euler(0f, 0f, shrinkRotation);
|
|
}
|
|
|
|
public static void ReloadScene() => Instance.StartCoroutine(routine: Instance.Load(() =>
|
|
{
|
|
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
|
|
}));
|
|
|
|
public static void Load(string name) => Instance.StartCoroutine(routine: Instance.Load(() =>
|
|
{
|
|
SceneManager.LoadScene(name);
|
|
}));
|
|
}
|
|
} |