using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.Timeline; namespace Game { public class TimelineClipPoolManager : ObjectPoolBase { private delegate TimelineClipPoolItem EventCallbackCreate(); private readonly Dictionary _dict = new Dictionary(); public override void OnCreate() { Register(); Register(); Register(); Register(); Register(); Register(); Register(); Register(); Register(); Register(); Register(); Register(); Register(); Register(); Register(); Register(); Register(); } private void Register() where T2 : TimelineClipBase, new() { _dict[typeof(T1)] = Create; } 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() where T : TimelineClipBase, new() { var ret = Create(typeof(T).ToString(), (item) => { item.Clip = new T(); }); ret.Clip.Reset(); return ret; } } public class TimelineClipPoolItem : ObjectPoolItemBase { public TimelineClipBase Clip; } }