Files

146 lines
4.3 KiB
C#
Raw Permalink Normal View History

using UnityEngine;
public class Point2ClickHandler : MonoBehaviour
{
public GameObject nextObject; // This will be Shose
private bool _clicked;
public bool CanBeClicked() { return !_clicked; }
private MeshRenderer _meshRenderer;
private void OnDisable()
{
StopAllCoroutines();
if (_meshRenderer != null) _meshRenderer.enabled = false;
}
void OnEnable()
{
if (GetComponent<Collider>() == null) gameObject.AddComponent<SphereCollider>().radius = 0.5f;
_meshRenderer = GetComponent<MeshRenderer>();
if (_meshRenderer != null)
{
_meshRenderer.enabled = true;
var mat = _meshRenderer.material;
if (mat != null && mat.HasProperty("_MainColor"))
{
var c = mat.GetColor("_MainColor");
c.a = 0f;
mat.SetColor("_MainColor", c);
if (mat.HasProperty("_OutlineWidth"))
{
mat.SetFloat("_OutlineWidth", OutlineConfig.Width);
}
}
}
_clicked = false;
StopAllCoroutines();
2026-07-12 20:34:49 +08:00
bool isExam = GameManager.Instance != null && GameManager.Instance.CurrentMode == ExperimentMode.Exam;
if (!isExam) { StartCoroutine(BlinkOutline()); }
}
System.Collections.IEnumerator BlinkOutline()
{
yield return new WaitForSeconds(0.4f);
while (true)
{
if (_meshRenderer != null) _meshRenderer.enabled = !_meshRenderer.enabled;
yield return new WaitForSeconds(0.4f);
}
}
void OnMouseDown()
{
PerformClick();
}
public void PerformClick()
{
if (_clicked) return;
2026-07-17 05:42:52 +08:00
InteractionClickGuard.MarkHandled();
_clicked = true;
Debug.Log("[Point2Click] ★ 被点击 ★");
ActionHistory.Push(ActionHistory.ActionType.Point2, this);
2026-07-12 20:34:49 +08:00
var examMgr = FindObjectOfType<ExamFlowManager>(); if (examMgr != null) examMgr.OnObjectClicked(this);
StopAllCoroutines();
if (_meshRenderer != null) _meshRenderer.enabled = false;
var woman = GameObject.Find("woman");
if (woman != null)
{
var anim = woman.GetComponent<Animator>();
if (anim != null)
{
anim.SetBool("IsCheck", true);
}
}
// 播放语音
var am = FindObjectOfType<AudioManager>();
if (am != null)
{
#if UNITY_EDITOR
var fractureClip = UnityEditor.AssetDatabase.LoadAssetAtPath<AudioClip>("Assets/Audio/people/伤员左大腿疑似骨折,无伤口.mp3");
if (fractureClip != null) am.PlayVoice(fractureClip);
#endif
}
if (nextObject != null)
{
var shoseHandler = nextObject.GetComponent<ShoseClickHandler>();
if (shoseHandler != null) shoseHandler.enabled = true;
else nextObject.SetActive(true);
}
2026-07-17 05:42:52 +08:00
var uiManager = FindObjectOfType<UIManager>();
if (uiManager != null)
{
uiManager.ShowTip("伤情评估完成。下一步:点击伤侧鞋子,脱除鞋子并暴露观察伤肢。");
}
gameObject.SetActive(false);
}
public void ResetState()
{
ResetState(true);
}
public void ResetState(bool startBlink)
{
_clicked = false;
if (_meshRenderer != null) _meshRenderer.enabled = startBlink;
if (nextObject != null)
{
var shoseHandler = nextObject.GetComponent<ShoseClickHandler>();
if (shoseHandler != null) shoseHandler.enabled = false;
else nextObject.SetActive(false);
}
var woman = GameObject.Find("woman");
if (woman != null)
{
var anim = woman.GetComponent<Animator>();
if (anim != null)
{
anim.SetBool("IsCheck", false);
}
}
StopAllCoroutines();
gameObject.SetActive(startBlink);
2026-07-12 20:34:49 +08:00
bool isExam = GameManager.Instance != null && GameManager.Instance.CurrentMode == ExperimentMode.Exam;
if (startBlink && isActiveAndEnabled && !isExam)
{
StartCoroutine(BlinkOutline());
}
}
}