2025-01-14 10:16:29 +08:00
|
|
|
|
using DG.Tweening;
|
2025-01-16 18:48:37 +08:00
|
|
|
|
using DG.Tweening.Core;
|
|
|
|
|
|
using DG.Tweening.Plugins.Options;
|
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;
|
2025-01-16 18:48:37 +08:00
|
|
|
|
using static OperationController;
|
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;
|
2025-01-02 14:19:47 +08:00
|
|
|
|
string deviceName;
|
2025-01-16 17:54:18 +08:00
|
|
|
|
|
|
|
|
|
|
float totalTime;
|
2024-12-30 10:29:48 +08:00
|
|
|
|
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"] : "";
|
2025-01-02 14:19:47 +08:00
|
|
|
|
retNode.deviceName = datas.ContainsKey("deviceName") ? datas["deviceName"] : "";
|
2024-12-14 18:27:59 +08:00
|
|
|
|
retNode.OnFinished = OnFinished;
|
|
|
|
|
|
return retNode;
|
|
|
|
|
|
}
|
|
|
|
|
|
public ulong ActionID { get; set; }
|
|
|
|
|
|
public ActionStatus Status { get; set; }
|
2025-01-16 18:48:37 +08:00
|
|
|
|
TweenerCore<float, float, FloatOptions> animDot;
|
2024-12-14 18:27:59 +08:00
|
|
|
|
public void OnStart()
|
|
|
|
|
|
{
|
2025-01-02 14:19:47 +08:00
|
|
|
|
GameObject obj = null;
|
|
|
|
|
|
if (string.IsNullOrEmpty(deviceName))
|
|
|
|
|
|
{
|
|
|
|
|
|
obj = Utility.FindObj(path);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
obj = DeviceController.Instance.GetDeviceObj(deviceName);
|
|
|
|
|
|
}
|
2024-12-14 18:27:59 +08:00
|
|
|
|
if (obj != null)
|
|
|
|
|
|
{
|
2025-01-08 14:56:51 +08:00
|
|
|
|
if (obj.activeSelf == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError(obj.name + "<22><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬");
|
|
|
|
|
|
}
|
2024-12-31 13:16:06 +08:00
|
|
|
|
try
|
2024-12-18 11:17:08 +08:00
|
|
|
|
{
|
2024-12-31 13:16:06 +08:00
|
|
|
|
anim = obj.GetComponent<Animation>();
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(frame) == false && frame != "-1")
|
2024-12-30 10:29:48 +08:00
|
|
|
|
{
|
2024-12-31 13:16:06 +08:00
|
|
|
|
int curFrame = 0;
|
|
|
|
|
|
int.TryParse(frame, out curFrame);
|
2025-01-02 10:19:41 +08:00
|
|
|
|
anim.clip = anim[animName].clip;
|
2024-12-31 13:16:06 +08:00
|
|
|
|
anim[animName].time = curFrame / anim.clip.frameRate;
|
|
|
|
|
|
anim[animName].speed = 0;
|
|
|
|
|
|
anim.Play(animName);
|
|
|
|
|
|
this.Finish();
|
2024-12-30 10:29:48 +08:00
|
|
|
|
}
|
2024-12-31 13:16:06 +08:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
float curSpeed = 1;
|
|
|
|
|
|
if (string.IsNullOrEmpty(speed) == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
float.TryParse(speed, out curSpeed);
|
|
|
|
|
|
}
|
2025-01-14 10:16:29 +08:00
|
|
|
|
|
|
|
|
|
|
if (curSpeed < 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
anim.Play(animName);
|
|
|
|
|
|
anim[animName].normalizedTime = 1;
|
2025-01-16 18:48:37 +08:00
|
|
|
|
animDot = DOTween.To(() => anim[animName].normalizedTime, v => anim[animName].normalizedTime = v, 0, anim[animName].length / Math.Abs(curSpeed));
|
|
|
|
|
|
animDot.onComplete = () =>
|
2025-01-14 10:16:29 +08:00
|
|
|
|
{
|
|
|
|
|
|
anim.Stop();
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
2025-01-09 15:52:57 +08:00
|
|
|
|
{
|
2025-01-14 10:16:29 +08:00
|
|
|
|
anim[animName].speed = curSpeed;
|
|
|
|
|
|
anim.Play(animName);
|
|
|
|
|
|
if (anim[animName].wrapMode == WrapMode.Loop)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.Finish();
|
|
|
|
|
|
}
|
2025-01-09 15:52:57 +08:00
|
|
|
|
}
|
2025-01-16 17:54:18 +08:00
|
|
|
|
totalTime = Math.Abs(anim[animName].length / curSpeed);
|
2024-12-31 13:16:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError($"{path} <20><><EFBFBD>Ŷ<EFBFBD><C5B6><EFBFBD> {animName} <20><><EFBFBD><EFBFBD>");
|
2024-12-18 11:17:08 +08:00
|
|
|
|
}
|
2024-12-31 13:16:06 +08:00
|
|
|
|
|
2024-12-14 18:27:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-12-31 13:16:06 +08:00
|
|
|
|
Debug.LogError("δ<>ҵ<EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD>" + path);
|
2024-12-14 18:27:59 +08:00
|
|
|
|
this.Finish();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-01-16 18:48:37 +08:00
|
|
|
|
|
2024-12-14 18:27:59 +08:00
|
|
|
|
public void OnExecute(float dt)
|
|
|
|
|
|
{
|
2025-01-16 17:54:18 +08:00
|
|
|
|
totalTime -= Time.deltaTime;
|
|
|
|
|
|
if (anim != null && (anim.isPlaying == false || totalTime <= 0))
|
2024-12-14 18:27:59 +08:00
|
|
|
|
{
|
|
|
|
|
|
this.Finish();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnFinish()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Reset()
|
|
|
|
|
|
{
|
|
|
|
|
|
Status = ActionStatus.NotStart;
|
|
|
|
|
|
Paused = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool Paused { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public void Deinit()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!Deinited)
|
|
|
|
|
|
{
|
2025-01-16 18:48:37 +08:00
|
|
|
|
animDot?.Kill();
|
|
|
|
|
|
anim?.Stop();
|
2024-12-14 18:27:59 +08:00
|
|
|
|
OnFinished = null;
|
|
|
|
|
|
Deinited = true;
|
|
|
|
|
|
mPool.Recycle(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool Deinited { get; set; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|