Projext/Assets/02_Scripts/UI/Loading/LoadingController.cs

176 lines
5.2 KiB
C#
Raw Normal View History

using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using TMPro;
public class LoadingController : MonoBehaviour
{
// 싱글톤
public static LoadingController Instance;
[Header("--- 로딩 캔버스 ---")]
public GameObject ;
[Header("--- 마법진 ---")]
public RectTransform 1;
public RectTransform 2;
public float 1 = 20f;
public float 2 = 15f;
[Header("--- 힌트 ---")]
public TextMeshProUGUI ;
[TextArea(2, 4)]
public string[] = {
"⚔ 강한 적에게는 정면 돌파보다 측면 공격이 효과적입니다",
"🔮 마법은 마나가 부족할 때 사용하면 반동 피해를 입습니다",
"🛡 방어구의 내구도가 떨어지면 전투 전에 수리하세요",
"🌑 어둠 속에서는 횃불이 적의 시야를 차단해줍니다",
"⚗ 포션은 전투 중 즉시 사용할 수 있도록 단축키에 등록하세요"
};
public float = 2.5f;
[Header("--- 진행바 ---")]
public Image ;
public TextMeshProUGUI ;
[Header("--- 페이드 ---")]
public Image ;
public float = 1.5f;
[Header("--- 씬 이름 ---")]
public string = "GameScene";
[Header("--- 메인메뉴 ---")]
public MenuIntroController ;
private int = 0;
private bool = false;
void Awake()
{
if (Instance == null)
{
Instance = this;
DontDestroyOnLoad(gameObject);
}
else
{
Destroy(gameObject);
}
}
public IEnumerator (string = "")
{
if () yield break;
= true;
if ( != "")
= ;
if ( != null)
yield return StartCoroutine(.PlayOutro());
.SetActive(true);
if ( != null && .Length > 0)
.text = [0];
yield return StartCoroutine(());
StartCoroutine(());
StartCoroutine(());
yield return StartCoroutine(());
}
IEnumerator ()
{
float time = 0f;
.color = new Color(0, 0, 0, 1);
while (time < )
{
time += Time.deltaTime;
float alpha = Mathf.Lerp(1f, 0f, time / );
.color = new Color(0, 0, 0, alpha);
yield return null;
}
.color = new Color(0, 0, 0, 0);
}
IEnumerator ()
{
float time = 0f;
.color = new Color(0, 0, 0, 0);
while (time < )
{
time += Time.deltaTime;
float alpha = Mathf.Lerp(0f, 1f, time / );
.color = new Color(0, 0, 0, alpha);
yield return null;
}
.color = new Color(0, 0, 0, 1);
}
IEnumerator ()
{
while ()
{
yield return new WaitForSeconds();
= ( + 1) % .Length;
if ( != null)
.text = [];
}
}
IEnumerator ()
{
while ()
{
if (1 != null)
1.Rotate(0, 0, 1 * Time.deltaTime);
if (2 != null)
2.Rotate(0, 0, -2 * Time.deltaTime);
yield return null;
}
}
IEnumerator ()
{
float progress = 0f;
AsyncOperation =
SceneManager.LoadSceneAsync();
.allowSceneActivation = false;
while (progress < 1f)
{
float = Mathf.Clamp01(.progress / 0.9f);
progress = Mathf.MoveTowards(progress, , Time.deltaTime * 0.3f);
.fillAmount = progress;
.text = Mathf.RoundToInt(progress * 100f) + "%";
if (.progress >= 0.9f)
{
progress = Mathf.MoveTowards(progress, 1f, Time.deltaTime * 0.2f);
.fillAmount = progress;
.text = Mathf.RoundToInt(progress * 100f) + "%";
if (progress >= 1f) break;
}
yield return null;
}
.fillAmount = 1f;
.text = "100%";
yield return new WaitForSeconds(0.5f);
= false;
yield return StartCoroutine(());
.allowSceneActivation = true;
}
}