diff --git a/Assets/Scripts/Interaction/ChanraoTuibuHandler.cs b/Assets/Scripts/Interaction/ChanraoTuibuHandler.cs index dea6f40..be9d9ae 100644 --- a/Assets/Scripts/Interaction/ChanraoTuibuHandler.cs +++ b/Assets/Scripts/Interaction/ChanraoTuibuHandler.cs @@ -11,31 +11,50 @@ public class ChanraoTuibuHandler : MonoBehaviour void OnEnable() { - if (GetComponent() == null) gameObject.AddComponent().radius = 0.5f; - foreach (var r in GetComponentsInChildren(true)) r.enabled = false; CreateOutlineMesh(); + // 自动添加并适配包裹该物体网格的 BoxCollider,保证鼠标可以点到 + var mesh = GetMesh(); + if (mesh != null) + { + var oldSph = GetComponent(); + if (oldSph != null) Destroy(oldSph); + + var col = GetComponent(); + if (col == null) col = gameObject.AddComponent(); + + col.center = mesh.bounds.center; + col.size = mesh.bounds.size * 1.2f; + col.enabled = true; + } + else + { + if (GetComponent() == null) gameObject.AddComponent().radius = 0.5f; + } + + foreach (var r in GetComponentsInChildren(true)) r.enabled = false; + CreateOutlineMesh(); _isFinished = false; StopAllCoroutines(); StartCoroutine(BlinkOutline()); Debug.Log($"[ChanraoTuibu] OnEnable outline={_outlineMesh!=null}"); } + private Mesh GetMesh() + { + var mf = GetComponent(); + if (mf == null) mf = GetComponentInChildren(); + if (mf != null && mf.sharedMesh != null) return mf.sharedMesh; + + var smr = GetComponent(); + if (smr == null) smr = GetComponentInChildren(); + if (smr != null && smr.sharedMesh != null) return smr.sharedMesh; + + return null; + } + void CreateOutlineMesh() { if (_outlineMesh != null) return; - var mf = GetComponent(); - if (mf == null) mf = GetComponentInChildren(); - Mesh mesh = null; - if (mf != null && mf.sharedMesh != null) - { - mesh = mf.sharedMesh; - } - else - { - var smr = GetComponent(); - if (smr == null) smr = GetComponentInChildren(); - if (smr != null && smr.sharedMesh != null) - mesh = smr.sharedMesh; - } + Mesh mesh = GetMesh(); if (mesh == null) { Debug.LogWarning("[ChanraoTuibu] 无Mesh数据"); return; } var shader = Shader.Find("Custom/OutlineUnlit"); if (shader == null) { Debug.LogWarning("[ChanraoTuibu] Shader缺失"); return; } @@ -76,15 +95,16 @@ public class ChanraoTuibuHandler : MonoBehaviour var mr = GetComponent(); if (mr != null) mr.enabled = true; foreach (var r in GetComponentsInChildren(true)) { if (_outlineMesh != null && r == _outlineMesh) continue; r.enabled = true; } // 显示模型 - // 播放最后一句语音 - var am = FindObjectOfType(); - if (am != null) + // 激活所有的 ping 进行第二轮包扎 + var allPings = Object.FindObjectsOfType(); + foreach (var p in allPings) { -#if UNITY_EDITOR - var finishClip = UnityEditor.AssetDatabase.LoadAssetAtPath("Assets/Audio/people/伤员一切正常,包扎完毕.mp3"); - if (finishClip != null) am.PlayVoice(finishClip); -#endif + if (p.gameObject.activeInHierarchy) // Wait, pings are still active, they just have _modelShown = true + { + p.ReEnableBorder(); + } } + Debug.Log("[ChanraoTuibu] chanraotuibu 已显示,所有 ping 边框已重新激活!"); } public void ResetState()