diff --git a/Assets/Scripts/Actions/ActionHelper.cs b/Assets/Scripts/Actions/ActionHelper.cs index 91e2cf01..f1a48dc4 100644 --- a/Assets/Scripts/Actions/ActionHelper.cs +++ b/Assets/Scripts/Actions/ActionHelper.cs @@ -196,6 +196,11 @@ public class ActionHelper var strAction = (XMLTool.StringListAction)act; return ScriptAction.Allocate(act.Name, act.Value, strAction.args[0]); } + case "Collider": + { + var strAction = (XMLTool.StringListAction)act; + return ColliderAction.Allocate(act.Value, strAction.args[0], strAction.args[1], strAction.args[2]); + } default: Debug.LogError($"没有找到此Action的类型{act.Type}"); break; diff --git a/Assets/Scripts/Actions/ColliderAction.cs b/Assets/Scripts/Actions/ColliderAction.cs new file mode 100644 index 00000000..ebbc7e2e --- /dev/null +++ b/Assets/Scripts/Actions/ColliderAction.cs @@ -0,0 +1,121 @@ +using QFramework.Example; +using System; +using UnityEngine; + +namespace QFramework +{ + internal class ColliderAction : IAction + { + + public System.Action OnFinished { get; set; } + + + private ColliderAction() + { + } + + private static readonly SimpleObjectPool mPool = + new SimpleObjectPool(() => new ColliderAction(), null, 10); + string type; + string path; + string args; + string deviceName; + public static ColliderAction Allocate(string path, string deviceName, string type, string args, System.Action OnFinished = null) + { + var retNode = mPool.Allocate(); + retNode.ActionID = ActionKit.ID_GENERATOR++; + retNode.Deinited = false; + retNode.Reset(); + retNode.type = type; + retNode.path = path; + retNode.args = args; + retNode.deviceName = deviceName; + return retNode; + } + + + public ulong ActionID { get; set; } + public ActionStatus Status { get; set; } + + public void OnStart() + { + GameObject obj = null; + if (string.IsNullOrEmpty(deviceName)) + { + obj = Utility.FindObj(path); + } + else + { + obj = DeviceController.Instance.GetDeviceObj(deviceName); + } + + if (obj != null) + { + Collider[] colliders = obj.GetComponents(); + switch (type) + { + case "AddBox": + string[] args = this.args.Split('|'); + Vector3 center = Utility.GetVector3FromStrArray(args[0]); + Vector3 size = Utility.GetVector3FromStrArray(args[1]); + BoxCollider box = obj.AddComponent(); + box.center = center; + box.size = size; + break; + case "AddMesh": + obj.AddComponent(); + break; + case "Remove": + foreach (var item in colliders) + { + GameObject.Destroy(item); + } + break; + case "Active": + bool active = true; + bool.TryParse(this.args, out active); + foreach (var item in colliders) + { + item.enabled = active; + } + break; + default: + Debug.LogError("找不到类型:" + type); + break; + } + } + 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/ColliderAction.cs.meta b/Assets/Scripts/Actions/ColliderAction.cs.meta new file mode 100644 index 00000000..e2f04e76 --- /dev/null +++ b/Assets/Scripts/Actions/ColliderAction.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3b900729b5bb03b4db0c4b085843ffe4 +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 b643f5d3..8733f25e 100644 --- a/Assets/Scripts/Xml/XmlParser.cs +++ b/Assets/Scripts/Xml/XmlParser.cs @@ -897,6 +897,39 @@ namespace XMLTool newAction = act; } break; + case "Collider": + { + var act = new StringListAction(); + XAttribute deviceName = action.Attribute("deviceName"); + if (deviceName != null) + { + act.args.Add(deviceName.Value); + } + else + { + act.args.Add(""); + } + XAttribute colliderType = action.Attribute("colliderType"); + if (colliderType != null) + { + act.args.Add(colliderType.Value); + } + else + { + act.args.Add("空"); + } + XAttribute arg = action.Attribute("args"); + if (arg != null) + { + act.args.Add(arg.Value); + } + else + { + act.args.Add(""); + } + newAction = act; + } + break; default: newAction = new Action(); break;