2025-01-06 19:29:04 +08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using QFramework;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using UnityEngine.Playables;
|
|
|
|
|
|
public class TimeLineAction : IAction
|
|
|
|
|
|
{
|
|
|
|
|
|
public ulong ActionID { get; set; }
|
|
|
|
|
|
public bool Deinited { get; set; }
|
|
|
|
|
|
public bool Paused { get; set; }
|
|
|
|
|
|
public ActionStatus Status { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static readonly SimpleObjectPool<TimeLineAction> mPool =
|
|
|
|
|
|
new SimpleObjectPool<TimeLineAction>(() => new TimeLineAction(), null, 10);
|
|
|
|
|
|
string path;
|
|
|
|
|
|
string isShow = string.Empty;
|
|
|
|
|
|
string deviceName = string.Empty;
|
|
|
|
|
|
string finishedEvent = string.Empty;
|
|
|
|
|
|
string isWait = "true";
|
2025-01-07 11:22:06 +08:00
|
|
|
|
string frame;
|
|
|
|
|
|
string endFrame;
|
|
|
|
|
|
float curEndFrame = -1;
|
2025-02-27 15:46:27 +08:00
|
|
|
|
string speed = "1";
|
2025-01-06 19:29:04 +08:00
|
|
|
|
GameObject obj = null;
|
2025-01-07 11:22:06 +08:00
|
|
|
|
PlayableDirector play = null;
|
|
|
|
|
|
float fps = 24;
|
2025-01-06 19:29:04 +08:00
|
|
|
|
public static TimeLineAction Allocate(string path, Dictionary<string, string> datas, System.Action onDelayFinish = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var retNode = mPool.Allocate();
|
|
|
|
|
|
retNode.ActionID = ActionKit.ID_GENERATOR++;
|
|
|
|
|
|
retNode.Deinited = false;
|
|
|
|
|
|
retNode.Reset();
|
|
|
|
|
|
retNode.path = path;
|
|
|
|
|
|
retNode.isShow = datas.ContainsKey("isShow") ? datas["isShow"] : string.Empty;
|
|
|
|
|
|
retNode.deviceName = datas.ContainsKey("deviceName") ? datas["deviceName"] : string.Empty;
|
|
|
|
|
|
retNode.finishedEvent = datas.ContainsKey("finishedEvent") ? datas["finishedEvent"] : string.Empty;
|
|
|
|
|
|
retNode.isWait = datas.ContainsKey("isWait") ? datas["isWait"] : "true";
|
2025-01-07 11:22:06 +08:00
|
|
|
|
retNode.frame = datas.ContainsKey("frame") ? datas["frame"] : string.Empty;
|
|
|
|
|
|
retNode.endFrame = datas.ContainsKey("endFrame") ? datas["endFrame"] : string.Empty;
|
2025-02-27 15:46:27 +08:00
|
|
|
|
retNode.speed = datas.ContainsKey("speed") ? datas["speed"] : string.Empty;
|
2025-01-07 11:22:06 +08:00
|
|
|
|
retNode.curEndFrame = -1;
|
|
|
|
|
|
retNode.play = null;
|
2025-01-06 19:29:04 +08:00
|
|
|
|
return retNode;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Deinit()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!Deinited)
|
|
|
|
|
|
{
|
2025-01-13 14:05:32 +08:00
|
|
|
|
play?.Stop();
|
|
|
|
|
|
play = null;
|
2025-01-06 19:29:04 +08:00
|
|
|
|
Deinited = true;
|
|
|
|
|
|
mPool.Recycle(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnExecute(float dt)
|
|
|
|
|
|
{
|
2025-01-07 11:22:06 +08:00
|
|
|
|
if (curEndFrame != -1 && play.time * fps >= curEndFrame)
|
|
|
|
|
|
{
|
|
|
|
|
|
play.time = curEndFrame / 24;
|
2025-03-27 15:48:22 +08:00
|
|
|
|
play.Pause();
|
|
|
|
|
|
|
2025-01-07 11:22:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (play.state != PlayState.Playing)
|
2025-01-06 19:29:04 +08:00
|
|
|
|
{
|
|
|
|
|
|
Finished();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnFinish()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnStart()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrEmpty(deviceName) == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
obj = DeviceController.Instance.GetDeviceObj(deviceName);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
obj = Utility.FindObj(path);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (obj == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError("û<><C3BB><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD> :" + path);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
bool isActive = true;
|
|
|
|
|
|
bool.TryParse(isShow, out isActive);
|
2025-01-07 11:22:06 +08:00
|
|
|
|
play = obj.GetComponent<PlayableDirector>();
|
2025-01-06 19:29:04 +08:00
|
|
|
|
if (isActive)
|
|
|
|
|
|
{
|
2025-01-07 11:22:06 +08:00
|
|
|
|
|
|
|
|
|
|
float curFrame = 0;
|
|
|
|
|
|
if (string.IsNullOrEmpty(frame) == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
float.TryParse(frame, out curFrame);
|
|
|
|
|
|
}
|
|
|
|
|
|
play.time = curFrame / fps;
|
2025-02-27 15:46:27 +08:00
|
|
|
|
float curSpeed = 1;
|
|
|
|
|
|
if (float.TryParse(speed, out curSpeed) == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
curSpeed = 1;
|
|
|
|
|
|
}
|
2025-03-05 09:10:07 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(endFrame) == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
float.TryParse(endFrame, out curEndFrame);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-27 15:51:55 +08:00
|
|
|
|
if (!play.playableGraph.IsValid())
|
|
|
|
|
|
{
|
|
|
|
|
|
play.RebuildGraph();
|
|
|
|
|
|
}
|
2025-03-05 09:10:07 +08:00
|
|
|
|
if (curFrame == curEndFrame)
|
2025-01-07 11:22:06 +08:00
|
|
|
|
{
|
2025-03-05 09:10:07 +08:00
|
|
|
|
play.time = curEndFrame / 24;
|
|
|
|
|
|
play.Evaluate();
|
|
|
|
|
|
Finished();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
play.playableGraph.GetRootPlayable(0).SetSpeed(curSpeed);
|
|
|
|
|
|
play.Play();
|
2025-01-07 11:22:06 +08:00
|
|
|
|
}
|
2025-03-05 09:10:07 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-01-06 19:29:04 +08:00
|
|
|
|
bool iswait = true;
|
|
|
|
|
|
bool.TryParse(isWait, out iswait);
|
|
|
|
|
|
if (iswait == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
Finished();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-01-07 11:22:06 +08:00
|
|
|
|
play.Stop();
|
2025-01-06 19:29:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
public void Finished()
|
|
|
|
|
|
{
|
|
|
|
|
|
this.Finish();
|
|
|
|
|
|
if (string.IsNullOrEmpty(finishedEvent) == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
StringEventSystem.Global.Send(finishedEvent);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Reset()
|
|
|
|
|
|
{
|
|
|
|
|
|
Status = ActionStatus.NotStart;
|
|
|
|
|
|
Paused = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|