aboutsummaryrefslogtreecommitdiff
path: root/Assets/Scripts/SoulCoreGameLoop/UI
diff options
context:
space:
mode:
authorWeicao-CatilGrass <1992414357@qq.com>2026-05-12 11:30:53 +0800
committerWeicao-CatilGrass <1992414357@qq.com>2026-05-12 11:30:53 +0800
commit7d000eb31b39c737a798057b15139f37a633530b (patch)
tree4d0b5c4254ace847c65830e6b49b6206ed27ee17 /Assets/Scripts/SoulCoreGameLoop/UI
parent08c53d1525c9a766ac86b31bf31f502d09a28b5f (diff)
增加区域提示 UI
Diffstat (limited to 'Assets/Scripts/SoulCoreGameLoop/UI')
-rw-r--r--Assets/Scripts/SoulCoreGameLoop/UI/AreaHint.cs41
-rw-r--r--Assets/Scripts/SoulCoreGameLoop/UI/AreaHint.cs.meta11
-rw-r--r--Assets/Scripts/SoulCoreGameLoop/UI/UIEventListener.cs52
-rw-r--r--Assets/Scripts/SoulCoreGameLoop/UI/UIEventListener.cs.meta11
4 files changed, 115 insertions, 0 deletions
diff --git a/Assets/Scripts/SoulCoreGameLoop/UI/AreaHint.cs b/Assets/Scripts/SoulCoreGameLoop/UI/AreaHint.cs
new file mode 100644
index 0000000..ab03647
--- /dev/null
+++ b/Assets/Scripts/SoulCoreGameLoop/UI/AreaHint.cs
@@ -0,0 +1,41 @@
+using System;
+using TMPro;
+using UnityEditor;
+using UnityEngine;
+
+namespace SoulCoreGameLoop.UI
+{
+ [RequireComponent(typeof(Animator))]
+ public class AreaHint : MonoBehaviour, IUIEventSender<AreaHintMessage>
+ {
+ private const String TriggerPlay = "Play";
+
+ public TMP_Text areaName;
+ private Animator _animator;
+
+ [InitializeOnLoadMethod]
+ public static void RegisterListener ()
+ => UIEventListener.JoinListener<AreaHintMessage>();
+
+ public void OnReceive(AreaHintMessage evt)
+ {
+ areaName.text = evt.AreaName;
+ _animator.Play(TriggerPlay);
+ }
+
+ private void Start()
+ {
+ _animator = GetComponent<Animator>();
+ }
+ }
+
+ public struct AreaHintMessage
+ {
+ public readonly string AreaName;
+
+ public AreaHintMessage(string areaName)
+ {
+ AreaName = areaName;
+ }
+ }
+}
diff --git a/Assets/Scripts/SoulCoreGameLoop/UI/AreaHint.cs.meta b/Assets/Scripts/SoulCoreGameLoop/UI/AreaHint.cs.meta
new file mode 100644
index 0000000..ac152c3
--- /dev/null
+++ b/Assets/Scripts/SoulCoreGameLoop/UI/AreaHint.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: bad4905764b2bf444bb53c3b0c619d91
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/SoulCoreGameLoop/UI/UIEventListener.cs b/Assets/Scripts/SoulCoreGameLoop/UI/UIEventListener.cs
new file mode 100644
index 0000000..2d33a9b
--- /dev/null
+++ b/Assets/Scripts/SoulCoreGameLoop/UI/UIEventListener.cs
@@ -0,0 +1,52 @@
+using System;
+using System.Collections.Generic;
+using Object = System.Object;
+
+namespace SoulCoreGameLoop.UI
+{
+ /// <summary>
+ /// UI 事件监听器
+ /// </summary>
+ public static class UIEventListener
+ {
+ private static readonly Dictionary<TypeCode, Object> TypeSets = new ();
+
+ /// <summary>
+ /// 向 UI 事件监听器添加发送器实例
+ /// </summary>
+ /// <typeparam name="T"> 发送器绑定类型 </typeparam>
+ public static void JoinListener<T>() where T : new()
+ {
+ var typeCode = Type.GetTypeCode(typeof(T));
+ TypeSets.Add(typeCode, new T());
+ }
+
+ /// <summary>
+ /// 向 UI 事件监听器发送消息
+ /// </summary>
+ /// <param name="message"> 发送器 </param>
+ /// <typeparam name="T"> 消息类型 </typeparam>
+ public static void Send<T>(T message)
+ {
+ var typeCode = Type.GetTypeCode(typeof(T));
+ if (TypeSets.TryGetValue(typeCode, out var set))
+ {
+ var sender = (IUIEventSender<T>) set;
+ sender.OnReceive(message);
+ }
+ }
+ }
+
+ /// <summary>
+ /// UI 事件发送器
+ /// </summary>
+ /// <typeparam name="TEvent"></typeparam>
+ public interface IUIEventSender<in TEvent>
+ {
+ /// <summary>
+ /// 当接收到 UI 事件时的处理
+ /// </summary>
+ /// <param name="evt"></param>
+ public void OnReceive(TEvent evt);
+ }
+}
diff --git a/Assets/Scripts/SoulCoreGameLoop/UI/UIEventListener.cs.meta b/Assets/Scripts/SoulCoreGameLoop/UI/UIEventListener.cs.meta
new file mode 100644
index 0000000..277f53b
--- /dev/null
+++ b/Assets/Scripts/SoulCoreGameLoop/UI/UIEventListener.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 4c0f577ae0bc33c498d7bf73ba7838f7
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: