108 lines
3.4 KiB
C#
108 lines
3.4 KiB
C#
using System.Threading.Tasks;
|
|
using DG.Tweening;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
|
|
namespace BlueWater
|
|
{
|
|
public static class SceneName
|
|
{
|
|
public static string CombatTile = "00.CombatTitle";
|
|
public static string TycoonTile = "00.TycoonTitle";
|
|
public static string Tycoon = "01.Tycoon";
|
|
public static string Combat = "02.Combat";
|
|
}
|
|
|
|
public class SceneController : Singleton<SceneController>
|
|
{
|
|
[field: SerializeField]
|
|
public GameObject Panel { get; private set; }
|
|
|
|
[SerializeField]
|
|
private Image _fadeImage;
|
|
|
|
[SerializeField]
|
|
private CanvasGroup _loadingPanelCanvasGroup;
|
|
|
|
[Title("연출")]
|
|
[SerializeField]
|
|
private float _fadeInTime = 0.5f;
|
|
|
|
[SerializeField]
|
|
private float _fadeOutTime = 0.5f;
|
|
|
|
[SerializeField]
|
|
private float _loadingWaitTime = 2f;
|
|
|
|
public bool IsLoading { get; private set; }
|
|
|
|
private Tween _fadeIn;
|
|
private Tween _fadeOut;
|
|
private Tween _loadingPanelFadeIn;
|
|
private Tween _loadingPanelFadeOut;
|
|
|
|
protected override void OnAwake()
|
|
{
|
|
_fadeIn = _fadeImage.DOFade(1f, _fadeInTime).From(0f).SetUpdate(true).SetAutoKill(false).Pause();
|
|
_fadeOut = _fadeImage.DOFade(0f, _fadeOutTime).From(1f).SetUpdate(true).SetAutoKill(false).Pause();
|
|
_loadingPanelFadeIn = _loadingPanelCanvasGroup.DOFade(1f, _fadeInTime).From(0f).SetUpdate(true).SetAutoKill(false).Pause();
|
|
_loadingPanelFadeOut = _loadingPanelCanvasGroup.DOFade(0f, _fadeOutTime).From(1f).SetUpdate(true).SetAutoKill(false).Pause();
|
|
_fadeImage.color = new Color(0, 0, 0, 0);
|
|
_loadingPanelCanvasGroup.alpha = 0f;
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (Quitting) return;
|
|
|
|
_fadeIn?.Kill();
|
|
_fadeOut?.Kill();
|
|
_loadingPanelFadeIn?.Kill();
|
|
_loadingPanelFadeOut?.Kill();
|
|
}
|
|
|
|
public void RestartCurrentScene()
|
|
{
|
|
LoadScene(SceneManager.GetActiveScene().name);
|
|
}
|
|
|
|
public async void LoadScene(string sceneName)
|
|
{
|
|
IsLoading = true;
|
|
|
|
_fadeIn.Restart();
|
|
await _fadeIn.AsyncWaitForCompletion();
|
|
|
|
_loadingPanelFadeIn.Restart();
|
|
await _loadingPanelFadeIn.AsyncWaitForCompletion();
|
|
|
|
AsyncOperation asyncOperation = SceneManager.LoadSceneAsync(sceneName);
|
|
asyncOperation.allowSceneActivation = false;
|
|
|
|
while (!asyncOperation.isDone)
|
|
{
|
|
if (asyncOperation.progress >= 0.9f) // 로딩 완료 상태
|
|
{
|
|
break;
|
|
}
|
|
await Task.Yield();
|
|
}
|
|
|
|
asyncOperation.allowSceneActivation = true;
|
|
await Task.Delay((int)(_loadingWaitTime * 1000));
|
|
|
|
_loadingPanelFadeOut.Restart();
|
|
await _loadingPanelFadeOut.AsyncWaitForCompletion();
|
|
|
|
_fadeOut.Restart();
|
|
await _fadeOut.AsyncWaitForCompletion();
|
|
|
|
PopupUiController.ClearPopup();
|
|
VisualFeedbackManager.Instance.ResetTimeScale();
|
|
|
|
IsLoading = false;
|
|
}
|
|
}
|
|
} |