完善TimeLineAction

This commit is contained in:
shenjianxing 2025-01-07 11:22:06 +08:00
parent 3854e7e48a
commit af131bfa4e
3 changed files with 42 additions and 5 deletions

View File

@ -19,7 +19,12 @@ public class TimeLineAction : IAction
string deviceName = string.Empty;
string finishedEvent = string.Empty;
string isWait = "true";
string frame;
string endFrame;
float curEndFrame = -1;
GameObject obj = null;
PlayableDirector play = null;
float fps = 24;
public static TimeLineAction Allocate(string path, Dictionary<string, string> datas, System.Action onDelayFinish = null)
{
var retNode = mPool.Allocate();
@ -31,6 +36,10 @@ public class TimeLineAction : IAction
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";
retNode.frame = datas.ContainsKey("frame") ? datas["frame"] : string.Empty;
retNode.endFrame = datas.ContainsKey("endFrame") ? datas["endFrame"] : string.Empty;
retNode.curEndFrame = -1;
retNode.play = null;
return retNode;
}
@ -47,7 +56,12 @@ public class TimeLineAction : IAction
public void OnExecute(float dt)
{
if (obj.GetComponent<PlayableDirector>().state != PlayState.Playing)
if (curEndFrame != -1 && play.time * fps >= curEndFrame)
{
play.Stop();
play.time = curEndFrame / 24;
}
if (play.state != PlayState.Playing)
{
Finished();
}
@ -76,9 +90,22 @@ public class TimeLineAction : IAction
{
bool isActive = true;
bool.TryParse(isShow, out isActive);
play = obj.GetComponent<PlayableDirector>();
if (isActive)
{
obj.GetComponent<PlayableDirector>().Play();
float curFrame = 0;
if (string.IsNullOrEmpty(frame) == false)
{
float.TryParse(frame, out curFrame);
}
play.time = curFrame / fps;
play.Play();
if (string.IsNullOrEmpty(endFrame) == false)
{
float.TryParse(endFrame, out curEndFrame);
}
bool iswait = true;
bool.TryParse(isWait, out iswait);
if (iswait == false)
@ -88,7 +115,7 @@ public class TimeLineAction : IAction
}
else
{
obj.GetComponent<PlayableDirector>().Stop();
play.Stop();
}
}

View File

@ -1054,6 +1054,16 @@ namespace XMLTool
{
act.args.Add("isWait", isWait.Value);
}
XAttribute frame = action.Attribute("frame");
if (frame != null)
{
act.args.Add("frame", frame.Value);
}
XAttribute endFrame = action.Attribute("endFrame");
if (endFrame != null)
{
act.args.Add("endFrame", endFrame.Value);
}
newAction = act;
}
break;

View File

@ -133,8 +133,8 @@
-->
<Action type="StrEvent" name="HighLightTrigger" value="false"></Action>
<!--支持deviceName isWait是只Action是否等待结束-->
<Action type="TimeLine" value="Models/CZ_FengXian_Timeline" isShow="true" finishedEvent="播放完毕" isWait="true"></Action>
<!--支持deviceName isWait是只Action是否等待结束 frame 从哪一帧开始播放 endFrame 从哪一帧结束-->
<Action type="TimeLine" value="Models/CZ_FengXian_Timeline" isShow="true" finishedEvent="播放完毕" isWait="true" frame="140" endFrame="240"></Action>
<!--预加载模块 要在app.xml的Data标签内-->
<PreLoad>