Files
PrinceOfGlory/Assets/Scripts/Scene_04/PlayJiaGuAnimator.cs
kridoo ff5f7d36ec 1
2025-11-14 19:01:46 +08:00

105 lines
2.9 KiB
C#

using System.Collections;
using System.Collections.Generic;
using BigSpace.Logic;
using BigSpace.XRCore.Event;
using BigSpace.XRCore.RunningScene;
using Unity.XR.PXR;
using UnityEngine;
using static Unity.VisualScripting.Member;
using UnityEngine.UIElements;
public class PlayJiaGuAnimator : MonoBehaviour
{
public List<Animator> listAnimator;
public GameObject handObj;
public int HandType;
public HandFontSelfCtr font;
public GameObject catchJiaGu;
public GameObject animatorJiaGu;
public AudioSource audio_HuiDa;
public GameObject audio_Wen;
//控制文字显示时机
bool oneIsRun = false;
float oneWaitTime = 26f;
float oneRunTime = 0;
// Start is called before the first frame update
void Start()
{
GlobalEventMgr.Listen(GameEvent.EventHideTuchJiaGu, GameDataManage_EventHideTuchJiaGu);
}
private void Update()
{
if (oneIsRun)
{
oneRunTime += Time.deltaTime;
if (oneRunTime >= oneWaitTime)
{
oneIsRun = false;
oneRunTime = 0;
if (font != null) //显示字
font.PlayShowJGWFont();
if (animatorJiaGu != null)
animatorJiaGu.SetActive(false);
if (catchJiaGu != null)
catchJiaGu.SetActive(true);
}
}
}
[Header("动画控制")]
[SerializeField] private List<Animator> childAnimator; // 直接拖动绑定
public void SetTriggerParameter(string parameterName)
{
for (int i = 0; i < childAnimator.Count; i++)
{
childAnimator[i].SetTrigger(parameterName);
}
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.name == "PalmBox_L" || other.gameObject.name == "PalmBox_R")
{
if (listAnimator != null)
{
SetTriggerParameter("DisTrigger");
for (int i = 0; i < listAnimator.Count; i++)
{
if (HandType == 1)
{
listAnimator[i].Play("shaohuo_L");
}
else
{
listAnimator[i].Play("shaohuo_R");
}
}
}
oneIsRun = true;
GlobalEventMgr.Dispatch(GameEvent.EventHideTuchJiaGu); //只能摸一次,关闭所有的可触摸甲骨碰撞
if (audio_HuiDa != null)
{
audio_HuiDa.Play();
}
}
}
void GameDataManage_EventHideTuchJiaGu()
{
this.GetComponent<BoxCollider>().enabled = false;
if (handObj != null)
{
handObj.SetActive(false);
}
if (audio_Wen != null)
audio_Wen.SetActive(false);
}
}