From 8aa9fa3086a967ff38bb8511a677eb91bfc73328 Mon Sep 17 00:00:00 2001 From: yangbear Date: Sun, 5 Jul 2026 21:29:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Shose=20collider=E5=BC=BA=E5=88=B6?= =?UTF-8?q?=E8=AE=BE1.2+=E5=B9=B2=E6=8E=89DraggableObject+=E5=A4=A7?= =?UTF-8?q?=E5=AD=97=E5=8F=B7=E7=82=B9=E5=87=BB=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scripts/Interaction/ShoseClickHandler.cs | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/Assets/Scripts/Interaction/ShoseClickHandler.cs b/Assets/Scripts/Interaction/ShoseClickHandler.cs index 9be0d80..f6e4a58 100644 --- a/Assets/Scripts/Interaction/ShoseClickHandler.cs +++ b/Assets/Scripts/Interaction/ShoseClickHandler.cs @@ -1,28 +1,25 @@ using UnityEngine; -/// -/// Shose 交互:模型可见 + 外圈蓝色描边闪烁,点击后移动到 ShosePoint -/// public class ShoseClickHandler : MonoBehaviour { public GameObject nextObject; public Transform targetPoint; - private MeshRenderer _outlineMesh; void OnEnable() { - // 不隐藏模型!只加描边子对象 - if (GetComponent() == null) - { - var sc = gameObject.AddComponent(); - sc.radius = 1.0f; - sc.isTrigger = false; - } + // 强制确保有足够大的 collider + var col = GetComponent(); + if (col == null) col = gameObject.AddComponent(); + if (col is SphereCollider sc) { sc.radius = 1.2f; sc.isTrigger = false; } + // 干掉可能拦截点击的旧组件 + var drag = GetComponent(); + if (drag != null) Destroy(drag); + CreateOutlineMesh(); StopAllCoroutines(); StartCoroutine(BlinkOutline()); - Debug.Log($"[ShoseClick] OnEnable outline={_outlineMesh!=null} collider={GetComponent()!=null}"); + Debug.Log($"[ShoseClick] OnEnable outline={_outlineMesh!=null} col radius={(col is SphereCollider sc2?sc2.radius:-1)}"); } void CreateOutlineMesh() @@ -30,9 +27,9 @@ public class ShoseClickHandler : MonoBehaviour if (_outlineMesh != null) return; var mf = GetComponent(); if (mf == null) mf = GetComponentInChildren(); - if (mf == null || mf.sharedMesh == null) { Debug.LogWarning("[ShoseClick] 无Mesh"); return; } + if (mf == null || mf.sharedMesh == null) return; var shader = Shader.Find("Custom/OutlineUnlit"); - if (shader == null) { Debug.LogWarning("[ShoseClick] Shader缺失"); return; } + if (shader == null) return; var mat = new Material(shader); mat.SetColor("_OutlineColor", new Color(0.2f, 0.5f, 1f, 1f)); mat.SetColor("_MainColor", new Color(0, 0, 0, 0)); @@ -57,10 +54,11 @@ public class ShoseClickHandler : MonoBehaviour void OnMouseDown() { - Debug.Log("[ShoseClick] 被点击"); + Debug.Log("[ShoseClick] ★ 被点击了 ★"); StopAllCoroutines(); if (_outlineMesh != null) _outlineMesh.enabled = false; - if (targetPoint != null) { transform.position = targetPoint.position; transform.rotation = targetPoint.rotation; } + if (targetPoint != null) { transform.position = targetPoint.position; transform.rotation = targetPoint.rotation; Debug.Log($"[ShoseClick] 移动到 {targetPoint.name}"); } + else Debug.LogWarning("[ShoseClick] targetPoint 为空!"); if (nextObject != null) nextObject.SetActive(true); } }