新增通用字符串通知

This commit is contained in:
shenjianxing 2024-12-31 17:06:00 +08:00
parent 448bab5f03
commit 1de8149678
6 changed files with 116 additions and 0 deletions

View File

@ -209,6 +209,10 @@ public class ActionHelper
var dictAction = (XMLTool.DictionaryAction)act; var dictAction = (XMLTool.DictionaryAction)act;
return TimeTipAction.Allocate(act.Value, dictAction.args); return TimeTipAction.Allocate(act.Value, dictAction.args);
} }
case "StrEvent":
{
return StrEventAction.Allocate(act.Name, act.Value);
}
default: default:
Debug.LogError($"没有找到此Action的类型{act.Type}"); Debug.LogError($"没有找到此Action的类型{act.Type}");
break; break;

View File

@ -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<StrEventAction> mPool =
new SimpleObjectPool<StrEventAction>(() => 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; }
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7a45244e92d067b4495241480cdec7b7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -23,6 +23,8 @@ public class Global : Singleton<Global>
public static string reportDemoPath = reportPath + "Demo.docx"; public static string reportDemoPath = reportPath + "Demo.docx";
public static APPSetting appSetting { get; } = new APPSetting(); public static APPSetting appSetting { get; } = new APPSetting();
public static string HighLightTrigger = "HighLightTrigger";
public enum AppType public enum AppType
{ {
UnKnow = 1 << 0, UnKnow = 1 << 0,
@ -33,4 +35,6 @@ public class Global : Singleton<Global>
public static AppType appTpe = AppType.UnKnow; public static AppType appTpe = AppType.UnKnow;
} }

View File

@ -1,6 +1,7 @@
using HighlightPlus; using HighlightPlus;
using QFramework; using QFramework;
using QFramework.Example; using QFramework.Example;
using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
@ -16,6 +17,7 @@ public class DeviceItem : MonoBehaviour
var effect = gameObject.GetOrAddComponent<HighlightEffect>(); var effect = gameObject.GetOrAddComponent<HighlightEffect>();
gameObject.GetOrAddComponent<HighlightTrigger>(); gameObject.GetOrAddComponent<HighlightTrigger>();
effect.outlineColor = Color.green; effect.outlineColor = Color.green;
StringEventSystem.Global.Register<string[]>(Global.HighLightTrigger, OnHighLightTriggerEvent).UnRegisterWhenGameObjectDestroyed(gameObject);
} }
if (device.MeshCollider) 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<HighlightTrigger>().enabled = isActive;
}
}
private void OnMouseUpAsButton() private void OnMouseUpAsButton()
{ {
var effect = gameObject.GetComponent<HighlightEffect>(); var effect = gameObject.GetComponent<HighlightEffect>();

View File

@ -121,6 +121,14 @@
<Action type="TimeTip" value="这里是文字描述&lt;color=#FF00FF&gt;{0}&lt;/color&gt;-{1}" time="5" values="5,10|50,100" format="{0:F1}" finishedEvent="close" needClick="false" reverse="false" ></Action> <Action type="TimeTip" value="这里是文字描述&lt;color=#FF00FF&gt;{0}&lt;/color&gt;-{1}" time="5" values="5,10|50,100" format="{0:F1}" finishedEvent="close" needClick="false" reverse="false" ></Action>
<!--通用事件通知
HighLightTriggervalue=false 关闭device悬浮高亮 value=true 开启
-->
<Action type="StrEvent" name="HighLightTrigger" value="false"></Action>
<!--预加载模块 要在app.xml的Data标签内--> <!--预加载模块 要在app.xml的Data标签内-->
<PreLoad> <PreLoad>
<Action type="Parallel"> <Action type="Parallel">