fix(ui): 修复时间流转动画重叠和泄漏问题
This commit is contained in:
@@ -17,9 +17,19 @@ namespace AibisDream.UI
|
||||
[SerializeField] private float holdTime = 1f;
|
||||
[SerializeField] private float inoutTime = 0.5f;
|
||||
|
||||
private int _runVersion;
|
||||
|
||||
public void ForceStop()
|
||||
{
|
||||
_runVersion++;
|
||||
ResetVisuals();
|
||||
}
|
||||
|
||||
public IEnumerator TurnTimeTo(string originState, string targetState)
|
||||
{
|
||||
var version = ++_runVersion;
|
||||
var originImage = originAnimator.GetComponent<Image>();
|
||||
|
||||
// 设置起始状态
|
||||
targetAnimator.gameObject.SetActive(true);
|
||||
originAnimator.gameObject.SetActive(true);
|
||||
@@ -34,17 +44,35 @@ namespace AibisDream.UI
|
||||
originImage.color = Color.white;
|
||||
|
||||
// 淡入
|
||||
yield return canvasGroup.DOFade(1, inoutTime).WaitForCompletion();;
|
||||
yield return canvasGroup.DOFade(1, inoutTime).WaitForCompletion();
|
||||
if (version != _runVersion) yield break;
|
||||
|
||||
// 等待静止时间
|
||||
yield return new WaitForSeconds(holdTime);
|
||||
if (version != _runVersion) yield break;
|
||||
|
||||
// 淡出起始状态
|
||||
yield return originAnimator.GetComponent<Image>().DOFade(0, fadeTime).WaitForCompletion();
|
||||
yield return originImage.DOFade(0, fadeTime).WaitForCompletion();
|
||||
if (version != _runVersion) yield break;
|
||||
|
||||
// 等待静止时间
|
||||
yield return new WaitForSeconds(holdTime);
|
||||
if (version != _runVersion) yield break;
|
||||
|
||||
// 淡出
|
||||
yield return canvasGroup.DOFade(0, inoutTime).WaitForCompletion();
|
||||
if (version != _runVersion) yield break;
|
||||
|
||||
ResetVisuals();
|
||||
}
|
||||
|
||||
private void ResetVisuals()
|
||||
{
|
||||
canvasGroup.DOKill();
|
||||
originAnimator.GetComponent<Image>().DOKill();
|
||||
|
||||
canvasGroup.alpha = 0;
|
||||
originAnimator.GetComponent<Image>().color = Color.white;
|
||||
|
||||
targetAnimator.gameObject.SetActive(false);
|
||||
originAnimator.gameObject.SetActive(false);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using AibisDream.Framework;
|
||||
using AibisDream.Kit;
|
||||
@@ -35,6 +35,7 @@ namespace AibisDream.UI
|
||||
private ModalWindow _warningWindow;
|
||||
private SignBoard _signBoard;
|
||||
private TimeTurner _timeTurner;
|
||||
private int _timeFlowsVersion;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -211,18 +212,32 @@ namespace AibisDream.UI
|
||||
|
||||
private void HideAll()
|
||||
{
|
||||
_timeFlowsVersion++;
|
||||
|
||||
_fadeImage.DOKill();
|
||||
_fadeImage.color = Color.clear;
|
||||
_fadeImage.gameObject.SetActive(false);
|
||||
|
||||
_fullScreenImage.FadeOut(0.1f);
|
||||
_showObjImage.FadeOut(0.1f);
|
||||
_showObjPanel.SetActive(false);
|
||||
|
||||
_timeTurner.ForceStop();
|
||||
}
|
||||
|
||||
// ------------------------------- 时间流转 -------------------------------
|
||||
public IEnumerator TimeFlowsOn(string originState, string targetState)
|
||||
{
|
||||
var version = ++_timeFlowsVersion;
|
||||
|
||||
// 黑屏淡入
|
||||
yield return _fadeImage.FadeInAsync(0.5f);
|
||||
if (version != _timeFlowsVersion) yield break;
|
||||
|
||||
// 时间流转
|
||||
yield return _timeTurner.TurnTimeTo(originState, targetState);
|
||||
if (version != _timeFlowsVersion) yield break;
|
||||
|
||||
// 黑屏淡出
|
||||
yield return _fadeImage.FadeOutAsync(0.5f);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user