【m】移除DoTween,改为异步动画
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using DG.Tweening;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -21,6 +20,10 @@ namespace Stary.Evo.StoryEditor
|
||||
/// 动画单次时长
|
||||
/// </summary>
|
||||
private const float AnimationTime = 0.2f;
|
||||
/// <summary>
|
||||
/// 刷新帧率
|
||||
/// </summary>
|
||||
private const float UpdateInterval = 0.02f;
|
||||
|
||||
/// <summary>
|
||||
/// 字幕组件
|
||||
@@ -101,11 +104,9 @@ namespace Stary.Evo.StoryEditor
|
||||
_caption.sprite = await _loader.Load<Sprite>(para.CaptionPath);
|
||||
if (_audio)
|
||||
_audio.clip = await _loader.Load<AudioClip>(para.AudioPath);
|
||||
|
||||
|
||||
// 淡入
|
||||
_caption?.DOColor(Color.white, AnimationTime);
|
||||
_audio?.DOFade(1, AnimationTime);
|
||||
await UniTask.Delay(TimeSpan.FromSeconds(AnimationTime), cancellationToken:ct);
|
||||
await SetCaptionColor(1,ct);
|
||||
|
||||
// 等音频播放完
|
||||
if (_audio)
|
||||
@@ -115,8 +116,7 @@ namespace Stary.Evo.StoryEditor
|
||||
}
|
||||
|
||||
// 淡出
|
||||
_caption?.DOColor(Color.clear, AnimationTime);
|
||||
_audio?.DOFade(0, AnimationTime);
|
||||
await SetCaptionColor(0, ct);
|
||||
await UniTask.Delay(TimeSpan.FromSeconds(AnimationTime), cancellationToken:ct);
|
||||
}
|
||||
|
||||
@@ -127,23 +127,36 @@ namespace Stary.Evo.StoryEditor
|
||||
{
|
||||
_graph.Stop();
|
||||
|
||||
var hasAnim = false;
|
||||
if (_caption && _caption.color != Color.clear)
|
||||
{
|
||||
_caption?.DOColor(Color.clear, AnimationTime);
|
||||
hasAnim = true;
|
||||
}
|
||||
if (_audio && _audio.volume > 0)
|
||||
{
|
||||
_audio?.DOFade(0, AnimationTime);
|
||||
hasAnim = true;
|
||||
}
|
||||
if(hasAnim)
|
||||
await UniTask.Delay(TimeSpan.FromSeconds(AnimationTime));
|
||||
await SetCaptionColor(0, CancellationToken.None);
|
||||
|
||||
ReleaseGraph();
|
||||
}
|
||||
|
||||
public static void ReleaseGraph() => _graph = null;
|
||||
|
||||
private static async UniTask DoAnim(Action animAction, CancellationToken ct)
|
||||
{
|
||||
float time = 0;
|
||||
while (time < AnimationTime)
|
||||
{
|
||||
animAction?.Invoke();
|
||||
await UniTask.Delay(TimeSpan.FromSeconds(UpdateInterval), cancellationToken: ct);
|
||||
time+=UpdateInterval;
|
||||
}
|
||||
}
|
||||
|
||||
private static async UniTask SetCaptionColor(int alpha, CancellationToken ct)
|
||||
{
|
||||
var isAdd = alpha > _caption.color.a;
|
||||
|
||||
var speed = Mathf.Abs(_caption.color.a - alpha) / AnimationTime * UpdateInterval;
|
||||
if (speed == 0)
|
||||
return;
|
||||
|
||||
await DoAnim(() =>
|
||||
{
|
||||
_caption.color = new(1, 1, 1, _caption.color.a + (isAdd ? speed : -speed));
|
||||
}, ct);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:f51ebe6a0ceec4240a699833d6309b23",
|
||||
"GUID:fad681b9bfe621d4fa07f4f69c311443",
|
||||
"GUID:b8e24fd1eb19b4226afebb2810e3c19b"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "com.staryevo.storyeditor",
|
||||
"version": "1.0.2",
|
||||
"version": "1.0.3",
|
||||
"displayName": "10.StoryEditor",
|
||||
"description": "可视化剧本编辑器\n1.通过可视化图表编辑剧本内容\n2.将剧本导出为json\n3.解析剧本并执行",
|
||||
"unity": "2021.3",
|
||||
|
||||
Reference in New Issue
Block a user