2024-12-14 18:27:59 +08:00
|
|
|
using System;
|
2024-12-30 10:29:48 +08:00
|
|
|
using System.Collections.Generic;
|
2024-12-14 18:27:59 +08:00
|
|
|
using UnityEngine;
|
2024-12-30 10:29:48 +08:00
|
|
|
using UnityEngine.Rendering.Universal;
|
2024-12-14 18:27:59 +08:00
|
|
|
|
|
|
|
|
namespace QFramework
|
|
|
|
|
{
|
|
|
|
|
internal class AnimationAction : IAction
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public System.Action OnFinished { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private AnimationAction()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static readonly SimpleObjectPool<AnimationAction> mPool =
|
|
|
|
|
new SimpleObjectPool<AnimationAction>(() => new AnimationAction(), null, 10);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string path;
|
|
|
|
|
string animName;
|
|
|
|
|
Animation anim;
|
2024-12-30 10:29:48 +08:00
|
|
|
string frame;
|
|
|
|
|
string speed;
|
|
|
|
|
public static AnimationAction Allocate(string path, Dictionary<string, string> datas, System.Action OnFinished = null)
|
2024-12-14 18:27:59 +08:00
|
|
|
{
|
|
|
|
|
var retNode = mPool.Allocate();
|
|
|
|
|
retNode.ActionID = ActionKit.ID_GENERATOR++;
|
|
|
|
|
retNode.Deinited = false;
|
2024-12-18 11:17:08 +08:00
|
|
|
retNode.Reset();
|
2024-12-14 18:27:59 +08:00
|
|
|
retNode.path = path;
|
2024-12-30 10:29:48 +08:00
|
|
|
retNode.animName = datas.ContainsKey("animName") ? datas["animName"] : "";
|
|
|
|
|
retNode.frame = datas.ContainsKey("frame") ? datas["frame"] : "";
|
|
|
|
|
retNode.speed = datas.ContainsKey("speed") ? datas["speed"] : "";
|
2024-12-14 18:27:59 +08:00
|
|
|
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<Animation>();
|
2024-12-30 10:29:48 +08:00
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(frame) == false && frame != "-1")
|
|
|
|
|
{
|
|
|
|
|
int curFrame = 0;
|
|
|
|
|
int.TryParse(frame, out curFrame);
|
|
|
|
|
anim[animName].time = curFrame / anim.clip.frameRate;
|
|
|
|
|
anim[animName].speed = 0;
|
|
|
|
|
anim.Play(animName);
|
|
|
|
|
this.Finish();
|
|
|
|
|
}
|
|
|
|
|
else
|
2024-12-18 11:17:08 +08:00
|
|
|
{
|
2024-12-30 10:29:48 +08:00
|
|
|
float curSpeed = 1;
|
|
|
|
|
if (string.IsNullOrEmpty(speed)==false)
|
|
|
|
|
{
|
|
|
|
|
float.TryParse(speed, out curSpeed);
|
|
|
|
|
}
|
|
|
|
|
anim[animName].speed = curSpeed;
|
|
|
|
|
anim.Play(animName);
|
2024-12-18 11:17:08 +08:00
|
|
|
}
|
2024-12-14 18:27:59 +08:00
|
|
|
}
|
|
|
|
|
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; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|