From 70c8bbe18b5d3438853bc0323c2039d882a8d92e Mon Sep 17 00:00:00 2001
From: mzh <3213885650@qq.com>
Date: Tue, 6 Jan 2026 15:59:37 +0800
Subject: [PATCH] =?UTF-8?q?=E3=80=90m=E3=80=91=E7=A7=BB=E9=99=A4DoTween?=
=?UTF-8?q?=EF=BC=8C=E6=94=B9=E4=B8=BA=E5=BC=82=E6=AD=A5=E5=8A=A8=E7=94=BB?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../RunTime/Player/ScriptPlayer.cs | 53 ++++++++++++-------
.../RunTime/com.storyeditor.runtime.asmdef | 1 -
Assets/10.StoryEditor/package.json | 2 +-
3 files changed, 34 insertions(+), 22 deletions(-)
diff --git a/Assets/10.StoryEditor/RunTime/Player/ScriptPlayer.cs b/Assets/10.StoryEditor/RunTime/Player/ScriptPlayer.cs
index b7e45be..5be0bab 100644
--- a/Assets/10.StoryEditor/RunTime/Player/ScriptPlayer.cs
+++ b/Assets/10.StoryEditor/RunTime/Player/ScriptPlayer.cs
@@ -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
/// 动画单次时长
///
private const float AnimationTime = 0.2f;
+ ///
+ /// 刷新帧率
+ ///
+ private const float UpdateInterval = 0.02f;
///
/// 字幕组件
@@ -101,11 +104,9 @@ namespace Stary.Evo.StoryEditor
_caption.sprite = await _loader.Load(para.CaptionPath);
if (_audio)
_audio.clip = await _loader.Load(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);
+ }
}
}
\ No newline at end of file
diff --git a/Assets/10.StoryEditor/RunTime/com.storyeditor.runtime.asmdef b/Assets/10.StoryEditor/RunTime/com.storyeditor.runtime.asmdef
index 94acf3c..9229dbe 100644
--- a/Assets/10.StoryEditor/RunTime/com.storyeditor.runtime.asmdef
+++ b/Assets/10.StoryEditor/RunTime/com.storyeditor.runtime.asmdef
@@ -3,7 +3,6 @@
"rootNamespace": "",
"references": [
"GUID:f51ebe6a0ceec4240a699833d6309b23",
- "GUID:fad681b9bfe621d4fa07f4f69c311443",
"GUID:b8e24fd1eb19b4226afebb2810e3c19b"
],
"includePlatforms": [],
diff --git a/Assets/10.StoryEditor/package.json b/Assets/10.StoryEditor/package.json
index d0e491c..c898cd2 100644
--- a/Assets/10.StoryEditor/package.json
+++ b/Assets/10.StoryEditor/package.json
@@ -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",