From 37618e6e39aa58130f4237995753bcf202da136a Mon Sep 17 00:00:00 2001 From: Weicao-CatilGrass <1992414357@qq.com> Date: Mon, 1 Jun 2026 15:24:23 +0800 Subject: 完成单向门,并且修复了门不能再次关闭的BUG MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/OneWayDoorBehaviour.cs | 14 ++++++-- .../SoulCoreGameLoop/UI/AreaHintGenerator.cs | 2 ++ .../SoulCoreGameLoop/UI/MessageGenerator.cs | 40 ++++++++++++++++++++++ .../SoulCoreGameLoop/UI/MessageGenerator.cs.meta | 11 ++++++ 4 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 Assets/Scripts/SoulCoreGameLoop/UI/MessageGenerator.cs create mode 100644 Assets/Scripts/SoulCoreGameLoop/UI/MessageGenerator.cs.meta (limited to 'Assets/Scripts') diff --git a/Assets/Scripts/OneWayDoorBehaviour.cs b/Assets/Scripts/OneWayDoorBehaviour.cs index a92d8cd..25a06ec 100644 --- a/Assets/Scripts/OneWayDoorBehaviour.cs +++ b/Assets/Scripts/OneWayDoorBehaviour.cs @@ -1,11 +1,19 @@ +using System; using UnityEngine; public class OneWayDoorBehaviour : MonoBehaviour { [Header("绑定")] public Transform door; + public GameObject messageHint; - public float Angle => door.localRotation.eulerAngles.y; - public float AnglePercent => Angle / 90; - public bool IsOpened => Angle > 75; + public float Angle => Mathf.Round(door.localRotation.eulerAngles.y); + public float AnglePercent => Mathf.Clamp01(Angle / 90); + public bool IsOpened => Angle > 25; + + private void FixedUpdate() + { + // 如果门打开,就关闭消息提示 + messageHint.SetActive(! IsOpened); + } } diff --git a/Assets/Scripts/SoulCoreGameLoop/UI/AreaHintGenerator.cs b/Assets/Scripts/SoulCoreGameLoop/UI/AreaHintGenerator.cs index efc5e5f..c016ad9 100644 --- a/Assets/Scripts/SoulCoreGameLoop/UI/AreaHintGenerator.cs +++ b/Assets/Scripts/SoulCoreGameLoop/UI/AreaHintGenerator.cs @@ -18,6 +18,8 @@ namespace SoulCoreGameLoop.UI private void OnTriggerEnter(Collider other) { + if (! other.CompareTag("Player")) return; + Debug.Log("AreaHintGenerator OnTriggerEnter"); // 向监听器发送消息 UIEventListener.Send(new AreaHintMessage(name)); diff --git a/Assets/Scripts/SoulCoreGameLoop/UI/MessageGenerator.cs b/Assets/Scripts/SoulCoreGameLoop/UI/MessageGenerator.cs new file mode 100644 index 0000000..a286273 --- /dev/null +++ b/Assets/Scripts/SoulCoreGameLoop/UI/MessageGenerator.cs @@ -0,0 +1,40 @@ +using UnityEngine; + +namespace SoulCoreGameLoop.UI +{ + [RequireComponent(typeof(BoxCollider))] + public class MessageGenerator : MonoBehaviour + { + [Header("消息")] + public new string message = "哈哈"; + + private BoxCollider _collider; + + private void Awake() + { + _collider = GetComponent(); + _collider.isTrigger = true; + } + + private void OnTriggerEnter(Collider other) + { + if (! other.CompareTag("Player")) return; + + // 向监听器发送消息 + UIEventListener.Send(new Message(message)); + } + + private void OnDrawGizmosSelected() + { + if (_collider == null) return; + + var cs = _collider.size; + var ts = transform.lossyScale; + var size = new Vector3(cs.x * ts.x, cs.y * ts.y, cs.z * ts.z); + + Gizmos.color = new Color(1f, 1f, 1f, 0.5f); + Gizmos.matrix = transform.localToWorldMatrix; + Gizmos.DrawCube(_collider.center, size); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/SoulCoreGameLoop/UI/MessageGenerator.cs.meta b/Assets/Scripts/SoulCoreGameLoop/UI/MessageGenerator.cs.meta new file mode 100644 index 0000000..6b8c065 --- /dev/null +++ b/Assets/Scripts/SoulCoreGameLoop/UI/MessageGenerator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b7e8b0c55f5e43f4da8dd4ab3c6eb639 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: -- cgit