45 lines
1.4 KiB
C#
45 lines
1.4 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Playables;
|
|
|
|
public class EventTargetDirty : MonoBehaviour
|
|
{
|
|
public int dirtyName { set; get; }
|
|
public int timelineIndex { set; get; }
|
|
public bool isShowDirty { set; get; } = false;
|
|
|
|
public PlayableDirector playableDirector;
|
|
public PlayableAsset[] playableAsset;
|
|
Dictionary<string, PlayableAsset> playableAssetDict;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
playableAssetDict = new Dictionary<string, PlayableAsset>();
|
|
foreach (var asset in playableAsset)
|
|
{
|
|
playableAssetDict[asset.name] = asset;
|
|
}
|
|
}
|
|
public void PlayTimeline(string name, DirectorWrapMode directorWrapMode, System.Action onFinish = null)
|
|
{
|
|
StopAllCoroutines();
|
|
if (playableAssetDict.TryGetValue(name, out var asset))
|
|
{
|
|
playableDirector.Play(asset, directorWrapMode);
|
|
if (onFinish != null)
|
|
{
|
|
StartCoroutine(WaitForTimelineFinish(asset.duration, onFinish));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning($"PlayableAsset with name {name} not found.");
|
|
}
|
|
}
|
|
|
|
private System.Collections.IEnumerator WaitForTimelineFinish(double duration, System.Action onFinish)
|
|
{
|
|
yield return new WaitForSeconds((float)duration);
|
|
onFinish?.Invoke();
|
|
}
|
|
} |