using System; using UnityEngine; namespace QFramework { internal class AnimationAction : IAction { public System.Action OnFinished { get; set; } private AnimationAction() { } private static readonly SimpleObjectPool mPool = new SimpleObjectPool(() => new AnimationAction(), null, 10); string path; string animName; bool reset = false; Animation anim; public static AnimationAction Allocate(string path, string animName, string reset, System.Action OnFinished = null) { var retNode = mPool.Allocate(); retNode.ActionID = ActionKit.ID_GENERATOR++; retNode.Deinited = false; retNode.Reset(); retNode.path = path; retNode.animName = animName; bool.TryParse(reset, out retNode.reset); retNode.OnFinished = OnFinished; return retNode; } public ulong ActionID { get; set; } public ActionStatus Status { get; set; } public void OnStart() { GameObject obj = Utility.FindObj(path); if (obj != null) { anim = obj.GetComponent(); anim.Play(animName); if (reset) { ActionKit.DelayFrame(1, () => anim.Stop()); } } else { this.Finish(); } } public void OnExecute(float dt) { if (anim != null && anim.isPlaying == false) { this.Finish(); } } public void OnFinish() { } public void Reset() { Status = ActionStatus.NotStart; Paused = false; } public bool Paused { get; set; } public void Deinit() { if (!Deinited) { OnFinished = null; Deinited = true; mPool.Recycle(this); } } public bool Deinited { get; set; } } }