From 1de81496789dac40195da122ec4d996474783648 Mon Sep 17 00:00:00 2001 From: shenjianxing <”315615051@qq.com“> Date: Tue, 31 Dec 2024 17:06:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=80=9A=E7=94=A8=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B8=B2=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Actions/ActionHelper.cs | 4 + Assets/Scripts/Actions/StrEventAction.cs | 77 +++++++++++++++++++ Assets/Scripts/Actions/StrEventAction.cs.meta | 11 +++ Assets/Scripts/Global/Global.cs | 4 + Assets/Scripts/Item/DeviceItem.cs | 12 +++ Doc/Xml配置文档.xml | 8 ++ 6 files changed, 116 insertions(+) create mode 100644 Assets/Scripts/Actions/StrEventAction.cs create mode 100644 Assets/Scripts/Actions/StrEventAction.cs.meta diff --git a/Assets/Scripts/Actions/ActionHelper.cs b/Assets/Scripts/Actions/ActionHelper.cs index 8c6c6110..ebd121cd 100644 --- a/Assets/Scripts/Actions/ActionHelper.cs +++ b/Assets/Scripts/Actions/ActionHelper.cs @@ -209,6 +209,10 @@ public class ActionHelper var dictAction = (XMLTool.DictionaryAction)act; return TimeTipAction.Allocate(act.Value, dictAction.args); } + case "StrEvent": + { + return StrEventAction.Allocate(act.Name, act.Value); + } default: Debug.LogError($"ûҵAction{act.Type}"); break; diff --git a/Assets/Scripts/Actions/StrEventAction.cs b/Assets/Scripts/Actions/StrEventAction.cs new file mode 100644 index 00000000..89c7cea2 --- /dev/null +++ b/Assets/Scripts/Actions/StrEventAction.cs @@ -0,0 +1,77 @@ +using System; +using System.Runtime.CompilerServices; +using UnityEngine; + +namespace QFramework +{ + internal class StrEventAction : IAction + { + public string txt; + + + public System.Action OnFinished { get; set; } + + + private StrEventAction() + { + } + + private static readonly SimpleObjectPool mPool = + new SimpleObjectPool(() => new StrEventAction(), null, 10); + + string key = string.Empty; + string arg = string.Empty; + public static StrEventAction Allocate(string key, string arg, System.Action OnFinished = null) + { + var retNode = mPool.Allocate(); + retNode.ActionID = ActionKit.ID_GENERATOR++; + retNode.Deinited = false; + retNode.Reset(); + retNode.OnFinished = OnFinished; + retNode.key = key; + retNode.arg = arg; + return retNode; + } + + + public ulong ActionID { get; set; } + public ActionStatus Status { get; set; } + + public void OnStart() + { + StringEventSystem.Global.Send(key, arg.Split(",")); + 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/StrEventAction.cs.meta b/Assets/Scripts/Actions/StrEventAction.cs.meta new file mode 100644 index 00000000..d09f31f6 --- /dev/null +++ b/Assets/Scripts/Actions/StrEventAction.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7a45244e92d067b4495241480cdec7b7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Global/Global.cs b/Assets/Scripts/Global/Global.cs index 7c9cf1f6..339953fd 100644 --- a/Assets/Scripts/Global/Global.cs +++ b/Assets/Scripts/Global/Global.cs @@ -23,6 +23,8 @@ public class Global : Singleton public static string reportDemoPath = reportPath + "Demo.docx"; public static APPSetting appSetting { get; } = new APPSetting(); + public static string HighLightTrigger = "HighLightTrigger"; + public enum AppType { UnKnow = 1 << 0, @@ -33,4 +35,6 @@ public class Global : Singleton public static AppType appTpe = AppType.UnKnow; + + } diff --git a/Assets/Scripts/Item/DeviceItem.cs b/Assets/Scripts/Item/DeviceItem.cs index 0821ed95..2d9a2399 100644 --- a/Assets/Scripts/Item/DeviceItem.cs +++ b/Assets/Scripts/Item/DeviceItem.cs @@ -1,6 +1,7 @@ using HighlightPlus; using QFramework; using QFramework.Example; +using System; using System.Collections; using System.Collections.Generic; using UnityEngine; @@ -16,6 +17,7 @@ public class DeviceItem : MonoBehaviour var effect = gameObject.GetOrAddComponent(); gameObject.GetOrAddComponent(); effect.outlineColor = Color.green; + StringEventSystem.Global.Register(Global.HighLightTrigger, OnHighLightTriggerEvent).UnRegisterWhenGameObjectDestroyed(gameObject); } if (device.MeshCollider) { @@ -40,6 +42,16 @@ public class DeviceItem : MonoBehaviour } } + private void OnHighLightTriggerEvent(string[] obj) + { + if (obj.Length > 0) + { + bool isActive = true; + bool.TryParse(obj[0], out isActive); + gameObject.GetComponent().enabled = isActive; + } + } + private void OnMouseUpAsButton() { var effect = gameObject.GetComponent(); diff --git a/Doc/Xml配置文档.xml b/Doc/Xml配置文档.xml index 3e3e6975..080cfa82 100644 --- a/Doc/Xml配置文档.xml +++ b/Doc/Xml配置文档.xml @@ -121,6 +121,14 @@ + + + +