diff --git a/Assets/Scripts/Actions/ActionHelper.cs b/Assets/Scripts/Actions/ActionHelper.cs index 464d9f09..a13fb53d 100644 --- a/Assets/Scripts/Actions/ActionHelper.cs +++ b/Assets/Scripts/Actions/ActionHelper.cs @@ -218,7 +218,11 @@ public class ActionHelper var dictAction = (XMLTool.DictionaryAction)act; return SkinnedBakeAction.Allocate(act.Value, dictAction.args); } - + case "TimeLine": + { + var dictAction = (XMLTool.DictionaryAction)act; + return TimeLineAction.Allocate(act.Value, dictAction.args); + } default: Debug.LogError($"没有找到此Action的类型{act.Type}"); break; diff --git a/Assets/Scripts/Actions/TimeLineAction.cs b/Assets/Scripts/Actions/TimeLineAction.cs new file mode 100644 index 00000000..22c8bb4a --- /dev/null +++ b/Assets/Scripts/Actions/TimeLineAction.cs @@ -0,0 +1,110 @@ +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 mPool = + new SimpleObjectPool(() => new TimeLineAction(), null, 10); + string path; + string isShow = string.Empty; + string deviceName = string.Empty; + string finishedEvent = string.Empty; + string isWait = "true"; + GameObject obj = null; + public static TimeLineAction Allocate(string path, Dictionary 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"; + return retNode; + } + + + + public void Deinit() + { + if (!Deinited) + { + Deinited = true; + mPool.Recycle(this); + } + } + + public void OnExecute(float dt) + { + if (obj.GetComponent().state != PlayState.Playing) + { + 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("没有找到物体 :" + path); + } + else + { + bool isActive = true; + bool.TryParse(isShow, out isActive); + if (isActive) + { + obj.GetComponent().Play(); + bool iswait = true; + bool.TryParse(isWait, out iswait); + if (iswait == false) + { + Finished(); + } + } + else + { + obj.GetComponent().Stop(); + } + } + + } + public void Finished() + { + this.Finish(); + if (string.IsNullOrEmpty(finishedEvent) == false) + { + StringEventSystem.Global.Send(finishedEvent); + } + } + + public void Reset() + { + Status = ActionStatus.NotStart; + Paused = false; + } +} diff --git a/Assets/Scripts/Actions/TimeLineAction.cs.meta b/Assets/Scripts/Actions/TimeLineAction.cs.meta new file mode 100644 index 00000000..43b09721 --- /dev/null +++ b/Assets/Scripts/Actions/TimeLineAction.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 462024ac1d5ecb649b460f3bdebef004 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Xml/XmlParser.cs b/Assets/Scripts/Xml/XmlParser.cs index 47555553..fcb9b692 100644 --- a/Assets/Scripts/Xml/XmlParser.cs +++ b/Assets/Scripts/Xml/XmlParser.cs @@ -1031,6 +1031,32 @@ namespace XMLTool newAction = act; } break; + case "TimeLine": + { + var act = new DictionaryAction(); + XAttribute deviceName = action.Attribute("deviceName"); + if (deviceName != null) + { + act.args.Add("deviceName", deviceName.Value); + } + XAttribute isShow = action.Attribute("isShow"); + if (isShow != null) + { + act.args.Add("isShow", isShow.Value); + } + XAttribute finishedEvent = action.Attribute("finishedEvent"); + if (finishedEvent != null) + { + act.args.Add("finishedEvent", finishedEvent.Value); + } + XAttribute isWait = action.Attribute("isWait"); + if (isWait != null) + { + act.args.Add("isWait", isWait.Value); + } + newAction = act; + } + break; default: newAction = new Action(); break; diff --git a/Doc/Xml閰嶇疆鏂囨。.xml b/Doc/Xml閰嶇疆鏂囨。.xml index 37600c9e..73f86fc8 100644 --- a/Doc/Xml閰嶇疆鏂囨。.xml +++ b/Doc/Xml閰嶇疆鏂囨。.xml @@ -133,6 +133,9 @@ --> + + +