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-12 03:48:49 +08:00
|
|
|
var col = GetComponent<Collider>();
|
|
|
|
|
if (col == null)
|
2026-07-12 03:43:07 +08:00
|
|
|
{
|
2026-07-12 04:46:14 +08:00
|
|
|
var box = gameObject.AddComponent<BoxCollider>();
|
2026-07-12 04:50:06 +08:00
|
|
|
box.size = new Vector3(2f, 2f, 2f);
|
2026-07-12 04:46:14 +08:00
|
|
|
col = box;
|
2026-07-12 03:43:07 +08:00
|
|
|
}
|
2026-07-12 04:10:53 +08:00
|
|
|
|
2026-07-12 03:48:49 +08:00
|
|
|
if (col is SphereCollider sphere)
|
2026-07-12 03:43:07 +08:00
|
|
|
{
|
2026-07-12 04:46:14 +08:00
|
|
|
sphere.radius = 1.0f;
|
2026-07-12 04:10:53 +08:00
|
|
|
}
|
|
|
|
|
else if (col is BoxCollider box)
|
|
|
|
|
{
|
2026-07-12 04:46:14 +08:00
|
|
|
box.size = new Vector3(2f, 2f, 2f);
|
2026-07-12 03:43:07 +08:00
|
|
|
}
|
2026-07-12 04:10:53 +08:00
|
|
|
else if (col is CapsuleCollider cap)
|
|
|
|
|
{
|
2026-07-12 04:46:14 +08:00
|
|
|
cap.radius = 1.0f;
|
|
|
|
|
cap.height = 2.0f;
|
2026-07-12 04:10:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
col.isTrigger = false;
|
2026-07-12 03:48:49 +08:00
|
|
|
col.enabled = true;
|
2026-07-12 03:43:07 +08:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2026-07-12 04:10:53 +08:00
|
|
|
void OnMouseDown()
|
2026-07-08 09:38:42 +08:00
|
|
|
{
|
2026-07-12 04:10:53 +08:00
|
|
|
Debug.Log($"[PingClick] OnMouseDown 触发: {name}");
|
|
|
|
|
PerformClick();
|
2026-07-08 09:38:42 +08:00
|
|
|
}
|
|
|
|
|
|
2026-07-12 04:46:14 +08:00
|
|
|
void Update()
|
|
|
|
|
{
|
|
|
|
|
if (Input.GetMouseButtonDown(0))
|
|
|
|
|
{
|
|
|
|
|
if (!_isBlinking) return;
|
|
|
|
|
|
2026-07-12 04:50:06 +08:00
|
|
|
// 遍历所有激活的相机发射射线(解决 camera3 不是主相机导致点不到的问题!)
|
|
|
|
|
foreach (var c in Camera.allCameras)
|
2026-07-12 04:46:14 +08:00
|
|
|
{
|
2026-07-12 04:50:06 +08:00
|
|
|
if (!c.enabled) continue;
|
|
|
|
|
|
|
|
|
|
Ray ray = c.ScreenPointToRay(Input.mousePosition);
|
|
|
|
|
RaycastHit[] hits = Physics.RaycastAll(ray, 100f);
|
|
|
|
|
foreach (var hit in hits)
|
2026-07-12 04:46:14 +08:00
|
|
|
{
|
2026-07-12 04:50:06 +08:00
|
|
|
if (hit.collider != null && hit.collider.gameObject == gameObject)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log($"[PingClick] Update手动射线贯穿点中 (使用相机: {c.name}): {name}");
|
|
|
|
|
PerformClick();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-07-12 04:46:14 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-08 09:38:42 +08:00
|
|
|
public void PerformClick()
|
2026-07-02 16:07:02 +08:00
|
|
|
{
|
2026-07-12 04:10:53 +08:00
|
|
|
if (!_isBlinking)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log($"[PingClick] {name} 忽略点击,因为 _isBlinking=false");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
{
|
2026-07-12 03:43:07 +08:00
|
|
|
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
|
|
|
|
|
|
|
|
var remainingPings = Object.FindObjectsOfType<PingClickHandler>();
|
|
|
|
|
int activePingCount = 0;
|
|
|
|
|
foreach (var p in remainingPings)
|
|
|
|
|
{
|
2026-07-10 02:51:52 +08:00
|
|
|
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
|
|
|
if (!_modelShown) return;
|
|
|
|
|
|
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-12 03:47:42 +08:00
|
|
|
|
2026-07-10 02:11:11 +08:00
|
|
|
var col = GetComponent<Collider>();
|
2026-07-12 04:46:14 +08:00
|
|
|
if (col != null) col.enabled = true;
|
2026-07-12 03:47:42 +08:00
|
|
|
|
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
|
|
|
}
|