From 25b383a769d5c8c212a55f6ecdd05a3485d87103 Mon Sep 17 00:00:00 2001 From: yangbear Date: Sun, 5 Jul 2026 19:59:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20ShoseClickHandler=E5=8A=A0=E5=9B=BA?= =?UTF-8?q?=E2=80=94=E7=A9=BA=E6=8C=87=E9=92=88=E9=98=B2=E6=8A=A4+debug?= =?UTF-8?q?=E6=97=A5=E5=BF=97+=E8=87=AA=E5=8A=A8=E8=A1=A5collider?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scripts/Interaction/ShoseClickHandler.cs | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/Assets/Scripts/Interaction/ShoseClickHandler.cs b/Assets/Scripts/Interaction/ShoseClickHandler.cs index 2812982..574718a 100644 --- a/Assets/Scripts/Interaction/ShoseClickHandler.cs +++ b/Assets/Scripts/Interaction/ShoseClickHandler.cs @@ -1,43 +1,47 @@ using UnityEngine; -/// -/// Shose 鞋子交互:shader 模型描边闪烁,点击后显示模型+移动到ShosePoint -/// public class ShoseClickHandler : MonoBehaviour { public GameObject nextObject; public Transform targetPoint; - private MeshRenderer _modelRenderer; - private MeshRenderer _outlineMesh; + private MeshRenderer _modelRenderer, _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; } CreateOutlineMesh(); StopAllCoroutines(); StartCoroutine(BlinkOutline()); + Debug.Log($"[ShoseClick] OnEnable modelRenderer={_modelRenderer!=null} outlineMesh={_outlineMesh!=null}"); } void CreateOutlineMesh() { if (_outlineMesh != null) return; var mf = GetComponent(); - if (mf == null || mf.sharedMesh == null) return; - - var mat = new Material(Shader.Find("Custom/OutlineUnlit")); + if (mf == null) mf = GetComponentInChildren(); + if (mf == null || mf.sharedMesh == null) + { + Debug.LogWarning("[ShoseClick] 无 MeshFilter 或 sharedMesh,无法创建描边"); + return; + } + var shader = Shader.Find("Custom/OutlineUnlit"); + if (shader == null) { Debug.LogWarning("[ShoseClick] Custom/OutlineUnlit 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)); mat.SetFloat("_OutlineWidth", 0.03f); - var go = new GameObject("Outline"); go.transform.SetParent(transform, false); - var omf = go.AddComponent(); - omf.sharedMesh = mf.sharedMesh; + go.AddComponent().sharedMesh = mf.sharedMesh; _outlineMesh = go.AddComponent(); _outlineMesh.material = mat; + Debug.Log("[ShoseClick] 描边已创建"); } System.Collections.IEnumerator BlinkOutline() @@ -53,17 +57,11 @@ public class ShoseClickHandler : MonoBehaviour void OnMouseDown() { + 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 (targetPoint != null) { transform.position = targetPoint.position; transform.rotation = targetPoint.rotation; } if (nextObject != null) nextObject.SetActive(true); - Debug.Log($"[ShoseClick] 已移动到{targetPoint?.name}, {nextObject?.name} 已激活"); } }