冷却器表现添加,进入手术室timeline添加,其他表现优化
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 81a3c7f5c3edcc94e83bef49a64c7183
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,111 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Playables;
|
||||
using Yarn.Unity;
|
||||
|
||||
public class TimelineManager : MonoBehaviour
|
||||
{
|
||||
public static TimelineManager Instance { get; private set; }
|
||||
|
||||
// 使用字典来管理多个PlayableDirector
|
||||
private Dictionary<string, PlayableDirector> directors = new Dictionary<string, PlayableDirector>();
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this;
|
||||
DontDestroyOnLoad(gameObject); // 不销毁
|
||||
}
|
||||
else
|
||||
{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
|
||||
// 自动注册所有子对象中的PlayableDirector
|
||||
RegisterAllDirectors();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 自动注册所有子对象中的PlayableDirector
|
||||
/// </summary>
|
||||
private void RegisterAllDirectors()
|
||||
{
|
||||
var allDirectors = GetComponentsInChildren<PlayableDirector>();
|
||||
foreach (var director in allDirectors)
|
||||
{
|
||||
if (director.playableAsset != null)
|
||||
{
|
||||
RegisterDirector(director.playableAsset.name, director);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 注册PlayableDirector
|
||||
/// </summary>
|
||||
/// <param name="name">Timeline的名称</param>
|
||||
/// <param name="director">PlayableDirector实例</param>
|
||||
public void RegisterDirector(string name, PlayableDirector director)
|
||||
{
|
||||
if (!directors.ContainsKey(name))
|
||||
{
|
||||
directors.Add(name, director);
|
||||
Debug.Log($"Registered PlayableDirector for {name}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 播放指定的Timeline并等待其完成
|
||||
/// </summary>
|
||||
/// <param name="name">Timeline的名称</param>
|
||||
[YarnCommand("play_timeline")]
|
||||
public IEnumerator PlayTimeline(string name)
|
||||
{
|
||||
if (directors.TryGetValue(name, out var director))
|
||||
{
|
||||
director.Play();
|
||||
Debug.Log($"Timeline {name} playing.");
|
||||
|
||||
// 等待Timeline播放完成
|
||||
bool isPlaying = true;
|
||||
director.stopped += (PlayableDirector aDirector) => { isPlaying = false; };
|
||||
|
||||
while (isPlaying)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
Debug.Log($"Timeline {name} finished.");
|
||||
|
||||
// 重置PlayableDirector的状态
|
||||
director.time = 0;
|
||||
director.Evaluate(); // 评估以应用时间重置
|
||||
director.Stop();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"PlayableDirector for {name} not found.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 暂停指定的Timeline
|
||||
/// </summary>
|
||||
/// <param name="name">Timeline的名称</param>
|
||||
[YarnCommand("pause_timeline")]
|
||||
public void PauseTimeline(string name)
|
||||
{
|
||||
if (directors.TryGetValue(name, out var director))
|
||||
{
|
||||
director.Pause();
|
||||
Debug.Log($"Timeline {name} paused.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"PlayableDirector for {name} not found.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ccea65c35014bc24080e71809ed81683
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user