33 lines
1.1 KiB
C#
33 lines
1.1 KiB
C#
using UnityEngine;
|
|
using UnityEngine.XR.Interaction.Toolkit;
|
|
using BigSpace.XRCore.Event;
|
|
using BigSpace.Logic;
|
|
public class QuadCatchCtr : MonoBehaviour
|
|
{
|
|
private UnityEngine.XR.Interaction.Toolkit.Interactors.XRRayInteractor rayInteractor;
|
|
|
|
void Start()
|
|
{
|
|
rayInteractor = GetComponent<UnityEngine.XR.Interaction.Toolkit.Interactors.XRRayInteractor>();
|
|
rayInteractor.selectEntered.AddListener(OnSelectEntered);
|
|
rayInteractor.selectExited.AddListener(OnSelectExited);
|
|
}
|
|
|
|
// 握拳时射线命中 Quad → 抓到了
|
|
void OnSelectEntered(SelectEnterEventArgs args)
|
|
{
|
|
string name = args.interactableObject.transform.gameObject.name;
|
|
if (name.Length >= 4 && name.Substring(0, 4) == "Quad")
|
|
{
|
|
int fontIndex = int.Parse(name.Substring(4));
|
|
// 替换成新 SDK 的事件派发
|
|
GlobalEventMgr.Dispatch(GameEvent.EventRayQuadOk, true, 2, fontIndex);
|
|
}
|
|
}
|
|
|
|
// 松手
|
|
void OnSelectExited(SelectExitEventArgs args)
|
|
{
|
|
GlobalEventMgr.Dispatch(GameEvent.EventHandRelease, 2);
|
|
}
|
|
} |