131 lines
4.2 KiB
C#
131 lines
4.2 KiB
C#
using UnityEngine;
|
||
|
||
/// <summary>
|
||
/// 挂在 touchArray 子球体上。球体用双Pass膨胀描边shader(Custom/OutlineUnlit),
|
||
/// 闪烁提示用户点击。点击后移动到对应位置并顺序显示下一个。
|
||
/// </summary>
|
||
public class TouchPositionHandler : MonoBehaviour
|
||
{
|
||
public Transform targetPosition;
|
||
public GameObject womanObject;
|
||
public GameObject nextTouchObject;
|
||
public AudioClip voiceClip;
|
||
|
||
private MeshRenderer _meshRenderer;
|
||
|
||
private void Start()
|
||
{
|
||
_meshRenderer = GetComponent<MeshRenderer>();
|
||
}
|
||
|
||
private void OnEnable()
|
||
{
|
||
_meshRenderer = GetComponent<MeshRenderer>();
|
||
if (_meshRenderer != null)
|
||
{
|
||
_meshRenderer.enabled = true;
|
||
var col = GetComponent<Collider>(); if (col == null) { var sc = gameObject.AddComponent<SphereCollider>(); sc.radius = 0.3f; } // 只显示描边,填充透明
|
||
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);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
private System.Collections.IEnumerator BlinkMesh()
|
||
{
|
||
yield break;
|
||
}
|
||
|
||
public bool CanBeClicked()
|
||
{
|
||
return gameObject.activeInHierarchy && _meshRenderer != null && _meshRenderer.enabled;
|
||
}
|
||
|
||
public void PerformClick()
|
||
{
|
||
OnMouseDown();
|
||
}
|
||
|
||
private void OnMouseDown()
|
||
{
|
||
Debug.Log($"[TouchPosition] {name}: 被点击");
|
||
|
||
if (womanObject != null && targetPosition != null)
|
||
{
|
||
womanObject.transform.position = targetPosition.position;
|
||
womanObject.transform.rotation = targetPosition.rotation;
|
||
Debug.Log($"[TouchPosition] woman 移动到 {targetPosition.name}");
|
||
}
|
||
|
||
if (voiceClip != null)
|
||
{
|
||
PlaySharedVoice();
|
||
Debug.Log($"[TouchPosition] 播放语音: {voiceClip.name}");
|
||
}
|
||
|
||
// 点击point1时平滑切换到camera3
|
||
if (transform.GetSiblingIndex() == 0)
|
||
{
|
||
var amCam = FindObjectOfType<AudioManager>();
|
||
if (amCam != null) amCam.SwitchToCamera3();
|
||
}
|
||
|
||
int stepIndex = transform.GetSiblingIndex() + 1;
|
||
var sm = FindObjectOfType<StepManager>();
|
||
if (sm != null) sm.RecordWomanStep(stepIndex);
|
||
ActionHistory.Push(ActionHistory.ActionType.Woman, this);
|
||
|
||
// point1 点击后先激活 Shose
|
||
if (stepIndex == 1)
|
||
{
|
||
var shose = GameObject.Find("Shose");
|
||
if (shose != null)
|
||
{
|
||
var h = shose.GetComponent<ShoseClickHandler>();
|
||
if (h == null) h = shose.AddComponent<ShoseClickHandler>();
|
||
h.targetPoint = GameObject.Find("ShosePoint")?.transform;
|
||
if (h.nextObject == null)
|
||
h.nextObject = GameObject.Find("manInjury")?.transform.Find("ping.004")?.gameObject;
|
||
shose.SetActive(false);
|
||
shose.SetActive(true);
|
||
Debug.Log("[TouchPosition] Shose 已激活");
|
||
}
|
||
}
|
||
|
||
if (_meshRenderer != null) _meshRenderer.enabled = false;
|
||
|
||
gameObject.SetActive(false);
|
||
if (nextTouchObject != null)
|
||
{
|
||
nextTouchObject.SetActive(true);
|
||
Debug.Log($"[TouchPosition] {name} → {nextTouchObject.name} 显示");
|
||
}
|
||
}
|
||
|
||
private static AudioSource _sharedVoice;
|
||
|
||
private void PlaySharedVoice()
|
||
{
|
||
if (voiceClip == null) return;
|
||
if (_sharedVoice == null)
|
||
{
|
||
var go = GameObject.Find("[Managers]");
|
||
if (go != null) _sharedVoice = go.AddComponent<AudioSource>();
|
||
else { var g = new GameObject("SharedVoice"); _sharedVoice = g.AddComponent<AudioSource>(); }
|
||
}
|
||
_sharedVoice.Stop();
|
||
_sharedVoice.clip = voiceClip;
|
||
_sharedVoice.Play();
|
||
}
|
||
}
|