diff --git a/Assets/Scripts/Actions/ActionHelper.cs b/Assets/Scripts/Actions/ActionHelper.cs index 295aa93a..bc557228 100644 --- a/Assets/Scripts/Actions/ActionHelper.cs +++ b/Assets/Scripts/Actions/ActionHelper.cs @@ -191,6 +191,11 @@ public class ActionHelper var strAction = (XMLTool.StringListAction)act; return LedAction.Allocate(act.Value, strAction.args[0], strAction.args[1]); } + case "Script": + { + var strAction = (XMLTool.StringListAction)act; + return ScriptAction.Allocate(act.Name, act.Value, strAction.args[0]); + } default: Debug.LogError($"没有找到此Action的类型{act.Type}"); break; diff --git a/Assets/Scripts/Actions/ScriptAction.cs b/Assets/Scripts/Actions/ScriptAction.cs new file mode 100644 index 00000000..4662157b --- /dev/null +++ b/Assets/Scripts/Actions/ScriptAction.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using Unity.VisualScripting; +using UnityEngine; + +namespace QFramework +{ + internal class ScriptAction : IAction + { + + + public System.Action OnFinished { get; set; } + + + private ScriptAction() + { + } + + private static readonly SimpleObjectPool mPool = + new SimpleObjectPool(() => new ScriptAction(), null, 10); + + public string prefabPath; + string finishedEvent; + string name; + public static ScriptAction Allocate(string name, string prefabPath, string finishedEvent, System.Action OnFinished = null) + { + var retNode = mPool.Allocate(); + retNode.ActionID = ActionKit.ID_GENERATOR++; + retNode.Deinited = false; + retNode.Reset(); + retNode.OnFinished = OnFinished; + retNode.finishedEvent = finishedEvent; + retNode.prefabPath = prefabPath; + retNode.name = name; + return retNode; + } + + + public ulong ActionID { get; set; } + public ActionStatus Status { get; set; } + + public void OnStart() + { + StringEventSystem.Global.Register(finishedEvent, OnCustomFinished); + GameObject obj = GameObject.Instantiate(Resources.Load($"CustomAction/{prefabPath}").As()); + obj.name = name; + } + + private void OnCustomFinished() + { + StringEventSystem.Global.UnRegister(finishedEvent, OnCustomFinished); + this.Finish(); + } + + public void OnExecute(float dt) + { + + } + + public void OnFinish() + { + } + + public void Reset() + { + Status = ActionStatus.NotStart; + Paused = false; + } + + public bool Paused { get; set; } + + public void Deinit() + { + if (!Deinited) + { + OnFinished = null; + Deinited = true; + mPool.Recycle(this); + } + } + + public bool Deinited { get; set; } + } + + +} \ No newline at end of file diff --git a/Assets/Scripts/Actions/ScriptAction.cs.meta b/Assets/Scripts/Actions/ScriptAction.cs.meta new file mode 100644 index 00000000..1cd48e22 --- /dev/null +++ b/Assets/Scripts/Actions/ScriptAction.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6958205303fbb7541b8272f244747fc0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/CustomAction.meta b/Assets/Scripts/CustomAction.meta new file mode 100644 index 00000000..ce6f5980 --- /dev/null +++ b/Assets/Scripts/CustomAction.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6d7f9813c337725468c8739dba68c439 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Xml/XmlParser.cs b/Assets/Scripts/Xml/XmlParser.cs index b4743273..73c73dbb 100644 --- a/Assets/Scripts/Xml/XmlParser.cs +++ b/Assets/Scripts/Xml/XmlParser.cs @@ -869,10 +869,26 @@ namespace XMLTool newAction = act; } break; + case "Script": + { + var act = new StringListAction(); + XAttribute finishedEvent = action.Attribute("finishedEvent"); + if (finishedEvent != null) + { + act.args.Add(finishedEvent.Value); + } + else + { + act.args.Add(""); + } + newAction = act; + } + break; default: newAction = new Action(); break; } + newAction.Type = action.Attribute("type")?.Value; newAction.Name = action.Attribute("name")?.Value; newAction.Value = action.Attribute("value")?.Value; diff --git a/Doc/Xml閰嶇疆鏂囨。.xml b/Doc/Xml閰嶇疆鏂囨。.xml index c3489332..ab600db6 100644 --- a/Doc/Xml閰嶇疆鏂囨。.xml +++ b/Doc/Xml閰嶇疆鏂囨。.xml @@ -85,6 +85,9 @@ number 鏄暟鍊 鏀寔 灏忔暟鐐瑰拰妯嚎 渚嬪 12.34 3-5 --> + + +