From fa5c096b6e7e0bfca8b77ff13419ff1373040cd4 Mon Sep 17 00:00:00 2001 From: yangbear Date: Sun, 5 Jul 2026 21:11:47 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20ShoseClickHandler=E2=80=94=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E4=BF=9D=E6=8C=81=E5=8F=AF=E8=A7=81+=E5=A4=96?= =?UTF-8?q?=E5=9C=88=E6=8F=8F=E8=BE=B9+sphereCollider=E9=9D=9Etrigger?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scripts/Interaction/ShoseClickHandler.cs | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/Assets/Scripts/Interaction/ShoseClickHandler.cs b/Assets/Scripts/Interaction/ShoseClickHandler.cs index 574718a..fa7ec8e 100644 --- a/Assets/Scripts/Interaction/ShoseClickHandler.cs +++ b/Assets/Scripts/Interaction/ShoseClickHandler.cs @@ -1,23 +1,28 @@ using UnityEngine; +/// +/// Shose 交互:模型可见 + 外圈蓝色描边闪烁,点击后移动到 ShosePoint +/// public class ShoseClickHandler : MonoBehaviour { public GameObject nextObject; public Transform targetPoint; - private MeshRenderer _modelRenderer, _outlineMesh; + private MeshRenderer _outlineMesh; void OnEnable() { - _modelRenderer = GetComponent(); - if (_modelRenderer == null) _modelRenderer = GetComponentInChildren(); - if (_modelRenderer != null) _modelRenderer.enabled = false; - // 确保有 collider - if (GetComponent() == null) { var sc = gameObject.AddComponent(); sc.radius = 0.5f; } + // 不隐藏模型!只加描边子对象 + if (GetComponent() == null) + { + var sc = gameObject.AddComponent(); + sc.radius = 0.5f; + sc.isTrigger = false; + } CreateOutlineMesh(); StopAllCoroutines(); StartCoroutine(BlinkOutline()); - Debug.Log($"[ShoseClick] OnEnable modelRenderer={_modelRenderer!=null} outlineMesh={_outlineMesh!=null}"); + Debug.Log($"[ShoseClick] OnEnable outline={_outlineMesh!=null} collider={GetComponent()!=null}"); } void CreateOutlineMesh() @@ -25,13 +30,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] 无 MeshFilter 或 sharedMesh,无法创建描边"); - return; - } + if (mf == null || mf.sharedMesh == null) { Debug.LogWarning("[ShoseClick] 无Mesh"); return; } var shader = Shader.Find("Custom/OutlineUnlit"); - if (shader == null) { Debug.LogWarning("[ShoseClick] Custom/OutlineUnlit shader 未找到"); return; } + if (shader == null) { Debug.LogWarning("[ShoseClick] Shader缺失"); 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)); @@ -41,7 +42,6 @@ public class ShoseClickHandler : MonoBehaviour go.AddComponent().sharedMesh = mf.sharedMesh; _outlineMesh = go.AddComponent(); _outlineMesh.material = mat; - Debug.Log("[ShoseClick] 描边已创建"); } System.Collections.IEnumerator BlinkOutline() @@ -59,7 +59,6 @@ public class ShoseClickHandler : MonoBehaviour { Debug.Log("[ShoseClick] 被点击"); StopAllCoroutines(); - if (_modelRenderer != null) _modelRenderer.enabled = true; if (_outlineMesh != null) _outlineMesh.enabled = false; if (targetPoint != null) { transform.position = targetPoint.position; transform.rotation = targetPoint.rotation; } if (nextObject != null) nextObject.SetActive(true);