2
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.5 KiB
C#

using System.Collections.Generic;
using UnityEngine.Timeline;
namespace Game
{
public class TimelineObject
{
public readonly List<TimelineClipPoolItem> Clips = new List<TimelineClipPoolItem>();
}
public class TimelineManager : ManagerBase<TimelineManager>
{
private const string SkillTimelinePathRoot = "Timeline/";
public void RunSkillTimeline(GameEntity entity, string skillName)
{
var entityTimeline = entity.timeline.Timeline;
var asset = EnsureGetSkillTimeline(skillName);
double timeMax = 0;
var clips = new List<TimelineClipPoolItem>();
foreach (var track in asset.GetOutputTracks())
{
clips.Clear();
foreach (var clip in track.GetClips())
{
var clipReal =
TimelineClipPoolManager.Instance.CreateByClipType(clip.asset.GetType(), clip, entity);
if (clipReal == null)
{
continue;
}
clips.Add(clipReal);
if (clipReal.Clip.EndTime > timeMax)
{
timeMax = clipReal.Clip.EndTime;
}
}
//这里需要按时间排序 同类型clip时序问题
clips.Sort((a, b) => (int)((a.Clip.EndTime - b.Clip.EndTime) * 1000));
entityTimeline.Clips.AddRange(clips);
}
entity.timeline.TimePast = 0;
entity.timeline.TimeMax = timeMax;
entity.timeline.IsRunning = true;
}
public void EndSkillTimeline(GameEntity entity)
{
var timeline = entity.timeline;
if (timeline.Timeline != null)
{
foreach (var clip in timeline.Timeline.Clips)
{
var clipReal = clip.Clip;
if (clipReal.IsAlive)
{
clipReal.OnLeave();
}
clip.Destroy();
}
timeline.Timeline.Clips.Clear();
}
timeline.IsRunning = false;
timeline.IsPause = false;
}
public TimelineAsset EnsureGetSkillTimeline(string path)
{
var pathReal = $"{SkillTimelinePathRoot}{path}";
return Util.Load<TimelineAsset>(pathReal);
}
}
}