using UnityEngine; public class ShoseClickHandler : MonoBehaviour { private MeshRenderer _outlineMesh; private float _lastClickTime; private bool _isFinished; public bool CanBeClicked() { return !_isFinished; } void OnEnable() { // 确保有大号 BoxCollider,且千万不要 Destroy,以防出现 Unity 抛异常 var col = GetComponent(); if (col == null) { var bc = gameObject.AddComponent(); bc.size = new Vector3(0.5f, 0.5f, 0.5f); } foreach (var r in GetComponentsInChildren(true)) r.enabled = false; CreateOutlineMesh(); _isFinished = false; StopAllCoroutines(); StartCoroutine(BlinkOutline()); } private Mesh GetMesh() { var mf = GetComponent(); if (mf == null) mf = GetComponentInChildren(); if (mf != null && mf.sharedMesh != null) return mf.sharedMesh; var smr = GetComponent(); if (smr == null) smr = GetComponentInChildren(); if (smr != null && smr.sharedMesh != null) return smr.sharedMesh; return null; } void CreateOutlineMesh() { if (_outlineMesh != null) return; Mesh mesh = GetMesh(); if (mesh == 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().sharedMesh = mesh; _outlineMesh = go.AddComponent(); _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 (_isFinished) return; Debug.Log($"[ShoseClick] {name} 被点击"); ActionHistory.Push(ActionHistory.ActionType.Shose, this); _isFinished = true; StopAllCoroutines(); if (_outlineMesh != null) _outlineMesh.enabled = false; // 显示模型自身 var mr = GetComponent(); if (mr != null) mr.enabled = true; var smr = GetComponent(); if (smr != null) smr.enabled = true; foreach (var r in GetComponentsInChildren(true)) { if (_outlineMesh != null && r == _outlineMesh) continue; r.enabled = true; } // 隐藏鞋子后,激活 ping 序列的第一个 ping.004(反向逻辑中的第一步) // 之前的逻辑是寻找 ping.004 var ping004 = GameObject.Find("ping.004"); if (ping004 == null) { var mi = GameObject.Find("manInjury"); if (mi != null) { var t = mi.transform.Find("ping.004"); if (t != null) ping004 = t.gameObject; } } if (ping004 != null) ping004.SetActive(true); else Debug.LogWarning("[ShoseClick] 没找到 ping.004!"); var uiMgr = FindObjectOfType(); if (uiMgr != null) { uiMgr.ShowVideo(); } var sm = FindObjectOfType(); if (sm != null) sm.RecordShoseStep(); } public void ResetState() { _isFinished = false; var mr = GetComponent(); if (mr != null) mr.enabled = false; var smr = GetComponent(); if (smr != null) smr.enabled = false; foreach (var r in GetComponentsInChildren(true)) { if (_outlineMesh != null && r == _outlineMesh) continue; r.enabled = false; } if (_outlineMesh != null) _outlineMesh.enabled = true; StopAllCoroutines(); StartCoroutine(BlinkOutline()); } }