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