2026-07-02 16:07:02 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
public class PingClickHandler : MonoBehaviour
|
|
|
|
|
|
{
|
2026-07-05 02:53:50 +08:00
|
|
|
|
public GameObject chanraoObject, nextPing;
|
2026-07-03 00:59:20 +08:00
|
|
|
|
public int pingIndex;
|
2026-07-05 02:53:50 +08:00
|
|
|
|
private MeshRenderer _modelRenderer, _outlineMesh;
|
2026-07-06 04:49:03 +08:00
|
|
|
|
private bool _modelShown;
|
2026-07-09 06:14:48 +08:00
|
|
|
|
private bool _isBlinking;
|
2026-07-08 09:38:42 +08:00
|
|
|
|
|
2026-07-09 06:14:48 +08:00
|
|
|
|
public bool CanBeClicked() { return _isBlinking; }
|
2026-07-02 16:07:02 +08:00
|
|
|
|
|
|
|
|
|
|
void OnEnable()
|
|
|
|
|
|
{
|
2026-07-05 02:53:50 +08:00
|
|
|
|
_modelRenderer = GetComponent<MeshRenderer>();
|
|
|
|
|
|
if (_modelRenderer == null) _modelRenderer = GetComponentInChildren<MeshRenderer>();
|
|
|
|
|
|
foreach (var r in GetComponentsInChildren<Renderer>(true)) r.enabled = false;
|
2026-07-12 03:43:07 +08:00
|
|
|
|
|
|
|
|
|
|
// 确保碰撞体是打开的
|
2026-07-10 02:11:11 +08:00
|
|
|
|
var col = GetComponent<Collider>();
|
2026-07-12 03:43:07 +08:00
|
|
|
|
if (col == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var sphere = gameObject.AddComponent<SphereCollider>();
|
2026-07-12 03:45:35 +08:00
|
|
|
|
sphere.radius = 0.5f; // 可以适当增加,保证能点到
|
2026-07-12 03:43:07 +08:00
|
|
|
|
col = sphere;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (col is BoxCollider bc)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 如果是之前的 BoxCollider,把它改大一点,确保能点到
|
2026-07-12 03:45:35 +08:00
|
|
|
|
bc.size = new Vector3(Mathf.Max(bc.size.x, 0.8f), Mathf.Max(bc.size.y, 0.8f), Mathf.Max(bc.size.z, 0.8f));
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (col is SphereCollider sc)
|
|
|
|
|
|
{
|
|
|
|
|
|
sc.radius = Mathf.Max(sc.radius, 0.5f);
|
2026-07-12 03:43:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
col.enabled = true;
|
|
|
|
|
|
|
2026-07-05 02:53:50 +08:00
|
|
|
|
CreateOutlineMesh();
|
2026-07-06 04:49:03 +08:00
|
|
|
|
_modelShown = false;
|
2026-07-09 06:14:48 +08:00
|
|
|
|
_isBlinking = true;
|
2026-07-02 16:07:02 +08:00
|
|
|
|
StopAllCoroutines();
|
|
|
|
|
|
StartCoroutine(BlinkOutline());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-05 02:53:50 +08:00
|
|
|
|
void CreateOutlineMesh()
|
2026-07-02 16:22:17 +08:00
|
|
|
|
{
|
2026-07-05 02:53:50 +08:00
|
|
|
|
if (_outlineMesh != null) return;
|
|
|
|
|
|
var mf = GetComponent<MeshFilter>();
|
|
|
|
|
|
if (mf == null) mf = GetComponentInChildren<MeshFilter>();
|
|
|
|
|
|
if (mf == null || mf.sharedMesh == null) return;
|
2026-07-06 04:49:03 +08:00
|
|
|
|
var shader = Shader.Find("Custom/OutlineUnlit");
|
|
|
|
|
|
if (shader == null) return;
|
|
|
|
|
|
var mat = new Material(shader);
|
2026-07-05 02:53:50 +08:00
|
|
|
|
mat.SetColor("_OutlineColor", new Color(0.2f, 0.5f, 1f, 1f));
|
|
|
|
|
|
mat.SetColor("_MainColor", new Color(0, 0, 0, 0));
|
2026-07-08 09:38:42 +08:00
|
|
|
|
mat.SetFloat("_OutlineWidth", OutlineConfig.Width);
|
2026-07-05 02:53:50 +08:00
|
|
|
|
var go = new GameObject("Outline");
|
|
|
|
|
|
go.transform.SetParent(transform, false);
|
2026-07-08 09:38:42 +08:00
|
|
|
|
// 稍微往上偏移一点点,防止边框插进地里
|
|
|
|
|
|
go.transform.position += Vector3.up * 0.05f;
|
2026-07-05 02:53:50 +08:00
|
|
|
|
go.AddComponent<MeshFilter>().sharedMesh = mf.sharedMesh;
|
|
|
|
|
|
_outlineMesh = go.AddComponent<MeshRenderer>();
|
|
|
|
|
|
_outlineMesh.material = mat;
|
2026-07-02 16:22:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-02 16:07:02 +08:00
|
|
|
|
System.Collections.IEnumerator BlinkOutline()
|
|
|
|
|
|
{
|
2026-07-05 02:53:50 +08:00
|
|
|
|
if (_outlineMesh != null) _outlineMesh.enabled = true;
|
2026-07-05 02:32:58 +08:00
|
|
|
|
yield return new WaitForSeconds(0.4f);
|
2026-07-06 04:49:03 +08:00
|
|
|
|
while (true) { if (_outlineMesh != null) _outlineMesh.enabled = !_outlineMesh.enabled; yield return new WaitForSeconds(0.4f); }
|
2026-07-02 16:07:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OnMouseDown()
|
2026-07-08 09:38:42 +08:00
|
|
|
|
{
|
|
|
|
|
|
PerformClick();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void PerformClick()
|
2026-07-02 16:07:02 +08:00
|
|
|
|
{
|
2026-07-09 06:14:48 +08:00
|
|
|
|
if (!_isBlinking) return; // 防止重复点击
|
2026-07-09 03:51:55 +08:00
|
|
|
|
|
2026-07-05 02:53:50 +08:00
|
|
|
|
foreach (var c in Object.FindObjectsOfType<Camera>())
|
2026-07-03 00:59:20 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (!c.enabled) continue;
|
2026-07-05 02:53:50 +08:00
|
|
|
|
foreach (var h in Physics.RaycastAll(c.ScreenPointToRay(Input.mousePosition)))
|
2026-07-06 04:49:03 +08:00
|
|
|
|
if (h.collider?.transform.parent?.name == "touchArray") return;
|
2026-07-03 00:59:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-06 04:49:03 +08:00
|
|
|
|
if (!_modelShown)
|
2026-07-02 16:07:02 +08:00
|
|
|
|
{
|
2026-07-06 04:49:03 +08:00
|
|
|
|
_modelShown = true;
|
2026-07-09 06:14:48 +08:00
|
|
|
|
_isBlinking = false;
|
2026-07-09 03:16:00 +08:00
|
|
|
|
ActionHistory.Push(ActionHistory.ActionType.PingFirst, this);
|
2026-07-02 16:22:17 +08:00
|
|
|
|
StopAllCoroutines();
|
2026-07-05 02:53:50 +08:00
|
|
|
|
if (_modelRenderer != null) _modelRenderer.enabled = true;
|
2026-07-06 04:49:03 +08:00
|
|
|
|
foreach (var r in GetComponentsInChildren<Renderer>(true)) r.enabled = true;
|
2026-07-05 02:53:50 +08:00
|
|
|
|
if (_outlineMesh != null) _outlineMesh.enabled = false;
|
|
|
|
|
|
if (nextPing != null) nextPing.SetActive(true);
|
2026-07-08 09:38:42 +08:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// 如果 nextPing 是 null,说明我是最后一个 ping(也就是 ping.001)
|
2026-07-12 03:43:07 +08:00
|
|
|
|
// 此时第一阶段结束,激活 chanraotuibu
|
|
|
|
|
|
var chanraotuibu = GameObject.Find("chanraotuibu");
|
|
|
|
|
|
if (chanraotuibu == null)
|
2026-07-08 09:38:42 +08:00
|
|
|
|
{
|
2026-07-12 03:43:07 +08:00
|
|
|
|
var mi = GameObject.Find("manInjury");
|
|
|
|
|
|
if (mi != null)
|
2026-07-09 18:28:08 +08:00
|
|
|
|
{
|
2026-07-12 03:43:07 +08:00
|
|
|
|
var t = mi.transform.Find("chanraotuibu");
|
|
|
|
|
|
if (t != null) chanraotuibu = t.gameObject;
|
2026-07-09 18:28:08 +08:00
|
|
|
|
}
|
2026-07-08 09:38:42 +08:00
|
|
|
|
}
|
2026-07-12 03:43:07 +08:00
|
|
|
|
if (chanraotuibu != null) chanraotuibu.SetActive(true);
|
|
|
|
|
|
Debug.Log($"[PingClick] {name} 是最后一个 ping 模型,现已激活 chanraotuibu");
|
2026-07-08 09:38:42 +08:00
|
|
|
|
}
|
2026-07-09 18:28:08 +08:00
|
|
|
|
|
|
|
|
|
|
if (nextPing != null) Debug.Log($"[PingClick] {name} 模型显示, 激活 {nextPing.name}");
|
|
|
|
|
|
else Debug.Log($"[PingClick] {name} 模型显示, 激活下一个");
|
|
|
|
|
|
|
2026-07-06 04:49:03 +08:00
|
|
|
|
var sm = FindObjectOfType<StepManager>();
|
|
|
|
|
|
if (sm != null) sm.RecordPingStep(pingIndex, false);
|
2026-07-02 16:07:02 +08:00
|
|
|
|
}
|
2026-07-02 16:22:17 +08:00
|
|
|
|
else
|
|
|
|
|
|
{
|
2026-07-06 04:49:03 +08:00
|
|
|
|
if (chanraoObject != null) { chanraoObject.SetActive(true); Debug.Log($"[PingClick] {name} → {chanraoObject.name}"); }
|
2026-07-09 03:16:00 +08:00
|
|
|
|
HideSelf();
|
|
|
|
|
|
ActionHistory.Push(ActionHistory.ActionType.PingSecond, this);
|
2026-07-06 04:49:03 +08:00
|
|
|
|
var sm = FindObjectOfType<StepManager>();
|
|
|
|
|
|
if (sm != null) sm.RecordPingStep(pingIndex, true);
|
2026-07-08 09:38:42 +08:00
|
|
|
|
|
|
|
|
|
|
// 判断是否是真正的最后一步:检查所有的 PingClickHandler,看是否还有 activeInHierarchy 的。
|
|
|
|
|
|
// 注意当前 gameObject 刚刚被 SetActive(false),所以 FindObjectsOfType 获取不到当前的对象了。
|
|
|
|
|
|
var remainingPings = Object.FindObjectsOfType<PingClickHandler>();
|
|
|
|
|
|
int activePingCount = 0;
|
|
|
|
|
|
foreach (var p in remainingPings)
|
|
|
|
|
|
{
|
2026-07-10 02:51:52 +08:00
|
|
|
|
// In phase 2, finished pings have their collider disabled and _isBlinking set to false.
|
|
|
|
|
|
var col = p.GetComponent<Collider>();
|
|
|
|
|
|
if (col != null && col.enabled) activePingCount++;
|
2026-07-08 09:38:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (activePingCount == 0)
|
|
|
|
|
|
{
|
2026-07-12 03:43:07 +08:00
|
|
|
|
Debug.Log("[PingClick] 所有的 ping 都已经绑成 chanrao 了!播放完成语音。");
|
|
|
|
|
|
var am = FindObjectOfType<AudioManager>();
|
|
|
|
|
|
if (am != null)
|
2026-07-08 09:38:42 +08:00
|
|
|
|
{
|
2026-07-12 03:43:07 +08:00
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
|
var finishClip = UnityEditor.AssetDatabase.LoadAssetAtPath<AudioClip>("Assets/Audio/people/伤员一切正常,包扎完毕.mp3");
|
|
|
|
|
|
if (finishClip != null) am.PlayVoice(finishClip);
|
|
|
|
|
|
#endif
|
2026-07-08 09:38:42 +08:00
|
|
|
|
}
|
2026-07-10 03:50:39 +08:00
|
|
|
|
|
|
|
|
|
|
// 隐藏视频面板
|
2026-07-10 05:01:29 +08:00
|
|
|
|
var uiMgr = FindObjectOfType<UIManager>();
|
|
|
|
|
|
if (uiMgr != null)
|
2026-07-10 04:41:26 +08:00
|
|
|
|
{
|
2026-07-10 05:01:29 +08:00
|
|
|
|
uiMgr.HideVideo();
|
2026-07-10 03:50:39 +08:00
|
|
|
|
}
|
2026-07-08 09:38:42 +08:00
|
|
|
|
}
|
2026-07-05 02:30:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-09 18:28:08 +08:00
|
|
|
|
public void ReEnableBorder()
|
|
|
|
|
|
{
|
2026-07-12 03:45:35 +08:00
|
|
|
|
// 关键:在第二阶段被激活时,先检查我们是否已经被完成了
|
|
|
|
|
|
// 只有 _modelShown 为 true,并且没有被最终隐藏时,才能被激活
|
|
|
|
|
|
if (!_modelShown) return;
|
|
|
|
|
|
|
|
|
|
|
|
// 如果模型已经被替换成 chanrao 并且隐藏了自己,就不应该再被激活
|
2026-07-09 18:28:08 +08:00
|
|
|
|
var col = GetComponent<Collider>();
|
2026-07-12 03:45:35 +08:00
|
|
|
|
if (chanraoObject != null && chanraoObject.activeSelf)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (col != null) col.enabled = false;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2026-07-09 18:28:08 +08:00
|
|
|
|
|
|
|
|
|
|
_isBlinking = true;
|
2026-07-12 03:43:07 +08:00
|
|
|
|
|
|
|
|
|
|
// 【关键修复点】:确保即使在第二次激活时,碰撞体也被打开,且如果有的话,保证能被点到。
|
|
|
|
|
|
if (col != null) col.enabled = true;
|
|
|
|
|
|
|
2026-07-09 18:28:08 +08:00
|
|
|
|
if (_outlineMesh != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_outlineMesh.enabled = true;
|
|
|
|
|
|
StopAllCoroutines();
|
|
|
|
|
|
StartCoroutine(BlinkOutline());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void DisableBorder()
|
|
|
|
|
|
{
|
|
|
|
|
|
_isBlinking = false;
|
|
|
|
|
|
if (_outlineMesh != null) _outlineMesh.enabled = false;
|
|
|
|
|
|
StopAllCoroutines();
|
|
|
|
|
|
}
|
2026-07-09 06:14:48 +08:00
|
|
|
|
|
2026-07-08 09:38:42 +08:00
|
|
|
|
public void UndoSecondClick()
|
|
|
|
|
|
{
|
2026-07-09 03:41:50 +08:00
|
|
|
|
if (chanraoObject != null) chanraoObject.SetActive(false);
|
2026-07-09 03:16:00 +08:00
|
|
|
|
ShowSelf();
|
2026-07-08 09:38:42 +08:00
|
|
|
|
_modelShown = true;
|
2026-07-09 06:14:48 +08:00
|
|
|
|
_isBlinking = true;
|
|
|
|
|
|
if (_outlineMesh != null) _outlineMesh.enabled = true;
|
|
|
|
|
|
StopAllCoroutines();
|
|
|
|
|
|
StartCoroutine(BlinkOutline());
|
2026-07-09 03:16:00 +08:00
|
|
|
|
}
|
2026-07-10 02:11:11 +08:00
|
|
|
|
public void UndoShow()
|
|
|
|
|
|
{
|
|
|
|
|
|
_modelShown = false;
|
|
|
|
|
|
_isBlinking = false;
|
|
|
|
|
|
StopAllCoroutines();
|
|
|
|
|
|
if (chanraoObject != null) chanraoObject.SetActive(false);
|
|
|
|
|
|
foreach (var r in GetComponentsInChildren<Renderer>(true)) r.enabled = false;
|
|
|
|
|
|
var col = GetComponent<Collider>(); if (col != null) col.enabled = false;
|
|
|
|
|
|
gameObject.SetActive(false);
|
|
|
|
|
|
}
|
2026-07-09 03:16:00 +08:00
|
|
|
|
|
|
|
|
|
|
private void HideSelf()
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var r in GetComponentsInChildren<Renderer>(true)) r.enabled = false;
|
|
|
|
|
|
var col = GetComponent<Collider>(); if (col != null) col.enabled = false;
|
2026-07-09 06:14:48 +08:00
|
|
|
|
_isBlinking = false;
|
2026-07-09 02:35:28 +08:00
|
|
|
|
StopAllCoroutines();
|
2026-07-08 09:38:42 +08:00
|
|
|
|
}
|
2026-07-09 03:16:00 +08:00
|
|
|
|
|
|
|
|
|
|
private void ShowSelf()
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var r in GetComponentsInChildren<Renderer>(true)) r.enabled = true;
|
|
|
|
|
|
if (_outlineMesh != null) _outlineMesh.enabled = false;
|
|
|
|
|
|
var col = GetComponent<Collider>(); if (col != null) col.enabled = true;
|
|
|
|
|
|
}
|
2026-07-08 09:38:42 +08:00
|
|
|
|
|
|
|
|
|
|
public void ResetState()
|
|
|
|
|
|
{
|
|
|
|
|
|
_modelShown = false;
|
2026-07-10 02:11:11 +08:00
|
|
|
|
var col = GetComponent<Collider>();
|
|
|
|
|
|
if (col != null) col.enabled = true;
|
2026-07-09 06:14:48 +08:00
|
|
|
|
_isBlinking = true;
|
2026-07-08 09:38:42 +08:00
|
|
|
|
if (_modelRenderer != null) _modelRenderer.enabled = false;
|
|
|
|
|
|
// 隐藏自身模型
|
|
|
|
|
|
foreach (var r in GetComponentsInChildren<Renderer>(true)) { if (_outlineMesh != null && r == _outlineMesh) continue; r.enabled = false; }
|
|
|
|
|
|
if (_outlineMesh != null) _outlineMesh.enabled = true;
|
|
|
|
|
|
StopAllCoroutines();
|
|
|
|
|
|
StartCoroutine(BlinkOutline());
|
|
|
|
|
|
}
|
2026-07-06 04:52:27 +08:00
|
|
|
|
}
|