Fix ping clickable issue on second phase
This commit is contained in:
@@ -15,9 +15,23 @@ public class PingClickHandler : MonoBehaviour
|
|||||||
_modelRenderer = GetComponent<MeshRenderer>();
|
_modelRenderer = GetComponent<MeshRenderer>();
|
||||||
if (_modelRenderer == null) _modelRenderer = GetComponentInChildren<MeshRenderer>();
|
if (_modelRenderer == null) _modelRenderer = GetComponentInChildren<MeshRenderer>();
|
||||||
foreach (var r in GetComponentsInChildren<Renderer>(true)) r.enabled = false;
|
foreach (var r in GetComponentsInChildren<Renderer>(true)) r.enabled = false;
|
||||||
if (GetComponent<Collider>() == null) gameObject.AddComponent<SphereCollider>().radius = 0.5f;
|
|
||||||
|
// 确保碰撞体是打开的
|
||||||
var col = GetComponent<Collider>();
|
var col = GetComponent<Collider>();
|
||||||
if (col != null) col.enabled = true;
|
if (col == null)
|
||||||
|
{
|
||||||
|
var sphere = gameObject.AddComponent<SphereCollider>();
|
||||||
|
sphere.radius = 0.5f;
|
||||||
|
col = sphere;
|
||||||
|
}
|
||||||
|
else if (col is BoxCollider bc)
|
||||||
|
{
|
||||||
|
// 如果是之前的 BoxCollider,把它改大一点,确保能点到
|
||||||
|
bc.size = new Vector3(Mathf.Max(bc.size.x, 0.5f), Mathf.Max(bc.size.y, 0.5f), Mathf.Max(bc.size.z, 0.5f));
|
||||||
|
}
|
||||||
|
|
||||||
|
col.enabled = true;
|
||||||
|
|
||||||
CreateOutlineMesh();
|
CreateOutlineMesh();
|
||||||
_modelShown = false;
|
_modelShown = false;
|
||||||
_isBlinking = true;
|
_isBlinking = true;
|
||||||
@@ -82,17 +96,19 @@ public class PingClickHandler : MonoBehaviour
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// 如果 nextPing 是 null,说明我是最后一个 ping(也就是 ping.001)
|
// 如果 nextPing 是 null,说明我是最后一个 ping(也就是 ping.001)
|
||||||
// 此时所有的 ping 都已经显示了模型,进入阶段二:重新点亮所有的 ping 边框
|
// 此时第一阶段结束,激活 chanraotuibu
|
||||||
var allPings = Object.FindObjectsOfType<PingClickHandler>();
|
var chanraotuibu = GameObject.Find("chanraotuibu");
|
||||||
foreach (var p in allPings)
|
if (chanraotuibu == null)
|
||||||
{
|
{
|
||||||
// 只有未被包扎过的 ping 才能重新亮起边框
|
var mi = GameObject.Find("manInjury");
|
||||||
if (p._modelShown)
|
if (mi != null)
|
||||||
{
|
{
|
||||||
p.ReEnableBorder();
|
var t = mi.transform.Find("chanraotuibu");
|
||||||
|
if (t != null) chanraotuibu = t.gameObject;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Debug.Log($"[PingClick] {name} 是最后一个 ping,所有边框已重新激活!");
|
if (chanraotuibu != null) chanraotuibu.SetActive(true);
|
||||||
|
Debug.Log($"[PingClick] {name} 是最后一个 ping 模型,现已激活 chanraotuibu");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nextPing != null) Debug.Log($"[PingClick] {name} 模型显示, 激活 {nextPing.name}");
|
if (nextPing != null) Debug.Log($"[PingClick] {name} 模型显示, 激活 {nextPing.name}");
|
||||||
@@ -122,22 +138,14 @@ public class PingClickHandler : MonoBehaviour
|
|||||||
|
|
||||||
if (activePingCount == 0)
|
if (activePingCount == 0)
|
||||||
{
|
{
|
||||||
Debug.Log("[PingClick] 所有的 ping 都已经绑成 chanrao 了!现在激活 chanraotuibu。");
|
Debug.Log("[PingClick] 所有的 ping 都已经绑成 chanrao 了!播放完成语音。");
|
||||||
|
var am = FindObjectOfType<AudioManager>();
|
||||||
var chanraotuibu = GameObject.Find("chanraotuibu");
|
if (am != null)
|
||||||
if (chanraotuibu == null)
|
|
||||||
{
|
{
|
||||||
var mi = GameObject.Find("manInjury");
|
#if UNITY_EDITOR
|
||||||
if (mi != null)
|
var finishClip = UnityEditor.AssetDatabase.LoadAssetAtPath<AudioClip>("Assets/Audio/people/伤员一切正常,包扎完毕.mp3");
|
||||||
{
|
if (finishClip != null) am.PlayVoice(finishClip);
|
||||||
var t = mi.transform.Find("chanraotuibu");
|
#endif
|
||||||
if (t != null) chanraotuibu = t.gameObject;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (chanraotuibu != null)
|
|
||||||
{
|
|
||||||
chanraotuibu.SetActive(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 隐藏视频面板
|
// 隐藏视频面板
|
||||||
@@ -157,6 +165,10 @@ public class PingClickHandler : MonoBehaviour
|
|||||||
if (col != null && !col.enabled) return;
|
if (col != null && !col.enabled) return;
|
||||||
|
|
||||||
_isBlinking = true;
|
_isBlinking = true;
|
||||||
|
|
||||||
|
// 【关键修复点】:确保即使在第二次激活时,碰撞体也被打开,且如果有的话,保证能被点到。
|
||||||
|
if (col != null) col.enabled = true;
|
||||||
|
|
||||||
if (_outlineMesh != null)
|
if (_outlineMesh != null)
|
||||||
{
|
{
|
||||||
_outlineMesh.enabled = true;
|
_outlineMesh.enabled = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user