From af131bfa4e9f853627e21ef96e6eb1480e3f6032 Mon Sep 17 00:00:00 2001 From: shenjianxing <”315615051@qq.com“> Date: Tue, 7 Jan 2025 11:22:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84TimeLineAction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Actions/TimeLineAction.cs | 33 +++++++++++++++++++++--- Assets/Scripts/Xml/XmlParser.cs | 10 +++++++ Doc/Xml配置文档.xml | 4 +-- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/Assets/Scripts/Actions/TimeLineAction.cs b/Assets/Scripts/Actions/TimeLineAction.cs index 22c8bb4a..89268a34 100644 --- a/Assets/Scripts/Actions/TimeLineAction.cs +++ b/Assets/Scripts/Actions/TimeLineAction.cs @@ -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 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().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(); if (isActive) { - obj.GetComponent().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().Stop(); + play.Stop(); } } diff --git a/Assets/Scripts/Xml/XmlParser.cs b/Assets/Scripts/Xml/XmlParser.cs index fcb9b692..4560222a 100644 --- a/Assets/Scripts/Xml/XmlParser.cs +++ b/Assets/Scripts/Xml/XmlParser.cs @@ -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; diff --git a/Doc/Xml配置文档.xml b/Doc/Xml配置文档.xml index 73f86fc8..dd1aa403 100644 --- a/Doc/Xml配置文档.xml +++ b/Doc/Xml配置文档.xml @@ -133,8 +133,8 @@ --> - - + +