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.

63 lines
2.3 KiB
C#

using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Timeline;
namespace Game
{
public class TimelineClipPoolManager : ObjectPoolBase<TimelineClipPoolManager>
{
private delegate TimelineClipPoolItem EventCallbackCreate();
private readonly Dictionary<Type, EventCallbackCreate> _dict = new Dictionary<Type, EventCallbackCreate>();
public override void OnCreate()
{
Register<AnimationPlayableAsset, ClipAnimation>();
Register<SlideClip, ClipSlide>();
Register<BreakClip, ClipBreak>();
Register<MovestepClip, ClipMovestep>();
Register<AttackClip, ClipAttack>();
Register<AttackTriggerClip, ClipAttackTrigger>();
Register<CancelClip, ClipCancel>();
Register<CastShadowClip, ClipCastShadow>();
Register<EffectClip, ClipEffect>();
Register<SubEntityClip, ClipSubEntity>();
Register<SoundClip, ClipSound>();
Register<FollowTargetClip, ClipFollowTarget>();
Register<GlobalEffectClip, ClipGlobalEffect>();
Register<DodgeClip, ClipDodge>();
Register<LoopInAirClip, ClipLoopInAir>();
Register<ThrowControlClip, ClipThrowControl>();
Register<ThrowAnimationClip, ClipThrowAnimation>();
}
private void Register<T1, T2>() where T2 : TimelineClipBase, new()
{
_dict[typeof(T1)] = Create<T2>;
}
public TimelineClipPoolItem CreateByClipType(Type type, TimelineClip clip, GameEntity owner)
{
if (!_dict.ContainsKey(type))
{
Debug.Log("Unknown Clip Type:" + type);
return null;
}
var ret = _dict[type]();
ret.Clip.Create(clip, owner);
return ret;
}
private TimelineClipPoolItem Create<T>() where T : TimelineClipBase, new()
{
var ret = Create<TimelineClipPoolItem>(typeof(T).ToString(), (item) =>
{
item.Clip = new T();
});
ret.Clip.Reset();
return ret;
}
}
public class TimelineClipPoolItem : ObjectPoolItemBase
{
public TimelineClipBase Clip;
}
}