using UnityEngine; public class ChanraoTuibuHandler : MonoBehaviour { 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)); mat.SetFloat("_OutlineWidth", 0.12f); 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; // 亮起所有 ping 的边框进入第二轮 var mi = GameObject.Find("manInjury"); if (mi != null) { for (int i = 4; i >= 1; i--) { var pt = mi.transform.Find("ping." + i.ToString("D3")); if (pt != null && pt.gameObject.activeSelf) { var h = pt.gameObject.GetComponent(); if (h != null) h.ReEnableBorder(); } } Debug.Log("[ChanraoTuibu] ping边框第二轮已亮起"); } } }