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.
111 lines
3.6 KiB
C#
111 lines
3.6 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((l, r) => l.Clip.EndTime.CompareTo(r.Clip.EndTime));
|
|
entityTimeline.Clips.AddRange(clips);
|
|
}
|
|
|
|
entity.timeline.TimePast = 0;
|
|
entity.timeline.TimeMax = timeMax;
|
|
entity.timeline.IsRunning = true;
|
|
}
|
|
|
|
public void SetTimelineTime(GameEntity entity, float from, float to)
|
|
{
|
|
var timeline = entity.timeline;
|
|
if (!timeline.IsRunning)
|
|
return;
|
|
if (timeline.Timeline == null)
|
|
return;
|
|
if (from == to)
|
|
return;
|
|
//往前设置
|
|
timeline.TimePast = to;
|
|
if (from > to)
|
|
{
|
|
foreach (var clip in timeline.Timeline.Clips)
|
|
{
|
|
var clipReal = clip.Clip;
|
|
if (clipReal.StartTime <= to && clipReal.EndTime > to)
|
|
{
|
|
clipReal.HasRun = false;
|
|
clipReal.IsAlive = false;
|
|
}
|
|
|
|
if (clipReal.StartTime > to && clipReal.StartTime < from)
|
|
{
|
|
clipReal.HasRun = false;
|
|
clipReal.IsAlive = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
} |