139 lines
4.0 KiB
C#
139 lines
4.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Rendering.Universal;
|
|
|
|
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;
|
|
string frame;
|
|
string speed;
|
|
string deviceName;
|
|
public static AnimationAction Allocate(string path, Dictionary<string, string> datas, System.Action OnFinished = null)
|
|
{
|
|
var retNode = mPool.Allocate();
|
|
retNode.ActionID = ActionKit.ID_GENERATOR++;
|
|
retNode.Deinited = false;
|
|
retNode.Reset();
|
|
retNode.path = path;
|
|
retNode.animName = datas.ContainsKey("animName") ? datas["animName"] : "";
|
|
retNode.frame = datas.ContainsKey("frame") ? datas["frame"] : "";
|
|
retNode.speed = datas.ContainsKey("speed") ? datas["speed"] : "";
|
|
retNode.deviceName = datas.ContainsKey("deviceName") ? datas["deviceName"] : "";
|
|
retNode.OnFinished = OnFinished;
|
|
return retNode;
|
|
}
|
|
public ulong ActionID { get; set; }
|
|
public ActionStatus Status { get; set; }
|
|
|
|
public void OnStart()
|
|
{
|
|
GameObject obj = null;
|
|
if (string.IsNullOrEmpty(deviceName))
|
|
{
|
|
obj = Utility.FindObj(path);
|
|
}
|
|
else
|
|
{
|
|
obj = DeviceController.Instance.GetDeviceObj(deviceName);
|
|
}
|
|
if (obj != null)
|
|
{
|
|
if (obj.activeSelf == false)
|
|
{
|
|
Debug.LogError(obj.name + "µ±Ç°ÊÇÒþ²Ø×´Ì¬");
|
|
}
|
|
try
|
|
{
|
|
anim = obj.GetComponent<Animation>();
|
|
|
|
if (string.IsNullOrEmpty(frame) == false && frame != "-1")
|
|
{
|
|
int curFrame = 0;
|
|
int.TryParse(frame, out curFrame);
|
|
anim.clip = anim[animName].clip;
|
|
anim[animName].time = curFrame / anim.clip.frameRate;
|
|
anim[animName].speed = 0;
|
|
anim.Play(animName);
|
|
this.Finish();
|
|
}
|
|
else
|
|
{
|
|
float curSpeed = 1;
|
|
if (string.IsNullOrEmpty(speed) == false)
|
|
{
|
|
float.TryParse(speed, out curSpeed);
|
|
}
|
|
anim[animName].speed = curSpeed;
|
|
anim.Play(animName);
|
|
if (anim[animName].wrapMode== WrapMode.Loop)
|
|
{
|
|
this.Finish();
|
|
}
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
Debug.LogError($"{path} ²¥·Å¶¯» {animName} ³ö´í");
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError("δÕÒµ½Â·¾¶£º" + path);
|
|
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; }
|
|
}
|
|
|
|
|
|
} |