From 7d000eb31b39c737a798057b15139f37a633530b Mon Sep 17 00:00:00 2001 From: Weicao-CatilGrass <1992414357@qq.com> Date: Tue, 12 May 2026 11:30:53 +0800 Subject: 增加区域提示 UI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/SoulCoreGameLoop/UI/AreaHint.cs | 41 +++++++++++++++++ .../Scripts/SoulCoreGameLoop/UI/AreaHint.cs.meta | 11 +++++ .../Scripts/SoulCoreGameLoop/UI/UIEventListener.cs | 52 ++++++++++++++++++++++ .../SoulCoreGameLoop/UI/UIEventListener.cs.meta | 11 +++++ 4 files changed, 115 insertions(+) create mode 100644 Assets/Scripts/SoulCoreGameLoop/UI/AreaHint.cs create mode 100644 Assets/Scripts/SoulCoreGameLoop/UI/AreaHint.cs.meta create mode 100644 Assets/Scripts/SoulCoreGameLoop/UI/UIEventListener.cs create mode 100644 Assets/Scripts/SoulCoreGameLoop/UI/UIEventListener.cs.meta (limited to 'Assets/Scripts/SoulCoreGameLoop/UI') 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 + { + private const String TriggerPlay = "Play"; + + public TMP_Text areaName; + private Animator _animator; + + [InitializeOnLoadMethod] + public static void RegisterListener () + => UIEventListener.JoinListener(); + + public void OnReceive(AreaHintMessage evt) + { + areaName.text = evt.AreaName; + _animator.Play(TriggerPlay); + } + + private void Start() + { + _animator = GetComponent(); + } + } + + 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 +{ + /// + /// UI 事件监听器 + /// + public static class UIEventListener + { + private static readonly Dictionary TypeSets = new (); + + /// + /// 向 UI 事件监听器添加发送器实例 + /// + /// 发送器绑定类型 + public static void JoinListener() where T : new() + { + var typeCode = Type.GetTypeCode(typeof(T)); + TypeSets.Add(typeCode, new T()); + } + + /// + /// 向 UI 事件监听器发送消息 + /// + /// 发送器 + /// 消息类型 + public static void Send(T message) + { + var typeCode = Type.GetTypeCode(typeof(T)); + if (TypeSets.TryGetValue(typeCode, out var set)) + { + var sender = (IUIEventSender) set; + sender.OnReceive(message); + } + } + } + + /// + /// UI 事件发送器 + /// + /// + public interface IUIEventSender + { + /// + /// 当接收到 UI 事件时的处理 + /// + /// + 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: -- cgit