using UnityEngine; public class ChanraoTuibuHandler : MonoBehaviour { public GameObject nextObject; private MeshRenderer _outlineMesh; void OnEnable() { if (GetComponent() == null) gameObject.AddComponent().radius = 0.5f; CreateOutlineMesh(); StopAllCoroutines(); StartCoroutine(BlinkOutline()); Debug.Log($"[ChanraoTuibu] OnEnable outline={_outlineMesh!=null}"); } void CreateOutlineMesh() { if (_outlineMesh != null) return; var mf = GetComponent(); if (mf == null) mf = GetComponentInChildren(); if (mf == null || mf.sharedMesh == null) { Debug.LogWarning("[ChanraoTuibu] 无MeshFilter"); return; } var shader = Shader.Find("Custom/OutlineUnlit"); if (shader == null) { Debug.LogWarning("[ChanraoTuibu] 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)); float s = transform.lossyScale.magnitude / Mathf.Sqrt(3); mat.SetFloat("_OutlineWidth", s > 0.001f ? OutlineConfig.Width / s : OutlineConfig.Width); var go = new GameObject("Outline"); go.transform.SetParent(transform, false); go.AddComponent().sharedMesh = mf.sharedMesh; _outlineMesh = go.AddComponent(); _outlineMesh.material = mat; } System.Collections.IEnumerator BlinkOutline() { if (_outlineMesh != null) _outlineMesh.enabled = true; yield return new WaitForSeconds(0.4f); while (true) { if (_outlineMesh != null) _outlineMesh.enabled = !_outlineMesh.enabled; yield return new WaitForSeconds(0.4f); } } void OnMouseDown() { Debug.Log($"[ChanraoTuibu] {name} 被点击"); StopAllCoroutines(); if (_outlineMesh != null) _outlineMesh.enabled = false; // 显示模型 var mr = GetComponent(); if (mr != null) mr.enabled = true; foreach (var r in GetComponentsInChildren(true)) r.enabled = true; // 激活下一个(ping.004) if (nextObject != null) { nextObject.SetActive(true); Debug.Log($"[ChanraoTuibu] → {nextObject.name}"); } } }