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} 已激活"); } }