232 lines
8.0 KiB
C#
232 lines
8.0 KiB
C#
using UnityEngine;
|
|
|
|
public class ShoseClickHandler : MonoBehaviour
|
|
{
|
|
public GameObject nextObject;
|
|
public Transform targetPoint;
|
|
private MeshRenderer _outlineMesh;
|
|
private bool _clicked;
|
|
private float _lastClickTime;
|
|
|
|
public bool CanBeClicked() { return !_clicked; }
|
|
|
|
private Vector3 _initialPosition;
|
|
private Quaternion _initialRotation;
|
|
private bool _hasRecordedInitialTransform = false;
|
|
|
|
void OnEnable()
|
|
{
|
|
var mf = GetComponent<MeshFilter>();
|
|
if (mf == null) mf = GetComponentInChildren<MeshFilter>();
|
|
if (mf != null && mf.sharedMesh != null)
|
|
{
|
|
var mb = mf.sharedMesh.bounds;
|
|
Destroy(GetComponent<SphereCollider>());
|
|
var col = GetComponent<BoxCollider>();
|
|
if (col == null) col = gameObject.AddComponent<BoxCollider>();
|
|
// Unity 的 BoxCollider.size 处于本地坐标空间,会自动乘上 localScale,这里不能重复缩放
|
|
col.center = mb.center;
|
|
col.size = mb.size * 1.2f;
|
|
col.enabled = true;
|
|
}
|
|
else { if (GetComponent<Collider>() == null) gameObject.AddComponent<SphereCollider>().radius = 0.3f; }
|
|
|
|
if (!_hasRecordedInitialTransform)
|
|
{
|
|
_initialPosition = transform.position;
|
|
_initialRotation = transform.rotation;
|
|
_hasRecordedInitialTransform = true;
|
|
}
|
|
|
|
CreateOutlineMesh();
|
|
StopAllCoroutines();
|
|
StartCoroutine(BlinkOutline());
|
|
_clicked = false;
|
|
}
|
|
|
|
void CreateOutlineMesh()
|
|
{
|
|
if (_outlineMesh != null) return;
|
|
var mf = GetComponent<MeshFilter>();
|
|
if (mf == null) mf = GetComponentInChildren<MeshFilter>();
|
|
if (mf == null || mf.sharedMesh == null) return;
|
|
var shader = Shader.Find("Custom/OutlineUnlit");
|
|
if (shader == null) return;
|
|
var mat = new Material(shader);
|
|
mat.SetColor("_OutlineColor", new Color(0.2f, 0.5f, 1f, 1f));
|
|
mat.SetColor("_MainColor", new Color(0, 0, 0, 0));
|
|
mat.SetFloat("_OutlineWidth", OutlineConfig.Width);
|
|
var go = new GameObject("Outline");
|
|
go.transform.SetParent(transform, false);
|
|
go.AddComponent<MeshFilter>().sharedMesh = mf.sharedMesh;
|
|
_outlineMesh = go.AddComponent<MeshRenderer>();
|
|
_outlineMesh.material = mat;
|
|
}
|
|
|
|
System.Collections.IEnumerator BlinkOutline()
|
|
{
|
|
if (_outlineMesh != null) _outlineMesh.enabled = true;
|
|
yield return new WaitForSeconds(0.4f);
|
|
while (true) { if (_outlineMesh != null) _outlineMesh.enabled = !_outlineMesh.enabled; yield return new WaitForSeconds(0.4f); }
|
|
}
|
|
|
|
void OnMouseDown()
|
|
{
|
|
PerformClick();
|
|
}
|
|
|
|
public void PerformClick()
|
|
{
|
|
if (Time.time - _lastClickTime < 0.3f) return;
|
|
_lastClickTime = Time.time;
|
|
if (_clicked) return;
|
|
_clicked = true;
|
|
Debug.Log("[ShoseClick] ★ 被点击 ★");
|
|
ActionHistory.Push(ActionHistory.ActionType.Shose, this);
|
|
StopAllCoroutines();
|
|
if (_outlineMesh != null) _outlineMesh.enabled = false;
|
|
if (targetPoint != null) { transform.position = targetPoint.position; transform.rotation = targetPoint.rotation; }
|
|
if (nextObject != null) nextObject.SetActive(true);
|
|
|
|
var woman = GameObject.Find("woman");
|
|
if (woman != null)
|
|
{
|
|
var anim = woman.GetComponent<Animator>();
|
|
if (anim != null)
|
|
{
|
|
anim.SetBool("isCrouch", true);
|
|
anim.CrossFade("womanCrouch", 0.1f);
|
|
}
|
|
|
|
// 移动 woman 到 point3
|
|
var point3 = GameObject.Find("womanPointArray/point3");
|
|
if (point3 != null)
|
|
{
|
|
woman.transform.position = point3.transform.position;
|
|
woman.transform.rotation = point3.transform.rotation;
|
|
}
|
|
}
|
|
|
|
var manInjury = GameObject.Find("manInjury");
|
|
if (manInjury != null)
|
|
{
|
|
var anim = manInjury.GetComponent<Animator>();
|
|
if (anim != null)
|
|
{
|
|
anim.SetBool("CheckFoot", true);
|
|
anim.CrossFade("manInjuryFoot", 0.1f);
|
|
|
|
// 启动协程,在动画播放完后将 CheckFoot 重置为 false
|
|
StartCoroutine(ResetCheckFoot(anim));
|
|
}
|
|
}
|
|
|
|
// 隐藏 point3 的边框 (touchArray/point3)
|
|
var touchArray = GameObject.Find("touchArray");
|
|
if (touchArray != null)
|
|
{
|
|
var touchPoint3 = touchArray.transform.Find("point3");
|
|
if (touchPoint3 != null)
|
|
{
|
|
touchPoint3.gameObject.SetActive(false);
|
|
}
|
|
|
|
// 点击鞋子时播放原本挂在 point1 上的那段语音(伤员左大腿疑似骨折)
|
|
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
|
|
}
|
|
}
|
|
|
|
// 切换到摄像机3
|
|
var audioManager = FindObjectOfType<AudioManager>();
|
|
if (audioManager != null)
|
|
{
|
|
audioManager.SwitchToCamera3();
|
|
}
|
|
|
|
// 显示 VideoPanel 并播放视频
|
|
var uiMgr = FindObjectOfType<UIManager>();
|
|
if (uiMgr != null)
|
|
{
|
|
uiMgr.ShowVideo("tuoXieZi.mp4");
|
|
}
|
|
}
|
|
|
|
public void ResetState()
|
|
{
|
|
_clicked = false;
|
|
if (_outlineMesh != null) _outlineMesh.enabled = true;
|
|
|
|
if (_hasRecordedInitialTransform)
|
|
{
|
|
transform.position = _initialPosition;
|
|
transform.rotation = _initialRotation;
|
|
}
|
|
|
|
if (nextObject != null) nextObject.SetActive(false);
|
|
|
|
// --- 恢复相机2、隐藏视频并重新播放语音 ---
|
|
var uiMgr = FindObjectOfType<UIManager>();
|
|
if (uiMgr != null)
|
|
{
|
|
uiMgr.HideVideo();
|
|
}
|
|
|
|
var cam2 = GameObject.Find("camera2");
|
|
var cam3 = GameObject.Find("camera3");
|
|
if (cam2 == null)
|
|
{
|
|
var allT = Resources.FindObjectsOfTypeAll<Transform>();
|
|
foreach(var t in allT) { if (t.name == "camera2") { cam2 = t.gameObject; break; } }
|
|
}
|
|
if (cam2 != null) { var c = cam2.GetComponent<Camera>(); if (c != null) c.enabled = true; }
|
|
if (cam3 != null) { var c = cam3.GetComponent<Camera>(); if (c != null) c.enabled = false; }
|
|
|
|
var am = FindObjectOfType<AudioManager>();
|
|
if (am != null)
|
|
{
|
|
#if UNITY_EDITOR
|
|
var autoClip = UnityEditor.AssetDatabase.LoadAssetAtPath<AudioClip>("Assets/Audio/people/周围环境安全,我是救护志愿者,我可以帮助您吗.mp3");
|
|
if (autoClip != null)
|
|
{
|
|
am.PlayVoice(autoClip);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
// 把 woman 重置(取消蹲下)
|
|
var woman = GameObject.Find("woman");
|
|
if (woman != null)
|
|
{
|
|
var anim = woman.GetComponent<Animator>();
|
|
if (anim != null)
|
|
{
|
|
anim.SetBool("isCrouch", false);
|
|
|
|
|
|
}
|
|
// 移回原位?如果最初在某个位置,PageController里有记录。这里只要不穿帮即可
|
|
}
|
|
// ----------------------------------------
|
|
|
|
StopAllCoroutines();
|
|
StartCoroutine(BlinkOutline());
|
|
}
|
|
|
|
private System.Collections.IEnumerator ResetCheckFoot(Animator anim)
|
|
{
|
|
// 等待约 3.5 秒(根据实际检查脚动画长度),将 CheckFoot 设回 false
|
|
yield return new WaitForSeconds(3.5f);
|
|
if (anim != null)
|
|
{
|
|
anim.SetBool("CheckFoot", false);
|
|
Debug.Log("[ShoseClick] CheckFoot 已被重置为 false");
|
|
}
|
|
}
|
|
}
|