更新S2交互

This commit is contained in:
YXY
2026-03-06 18:51:18 +08:00
parent 3e39007e2c
commit 6465387a45
281 changed files with 86957 additions and 206 deletions

View File

@@ -1,33 +1,74 @@
using System.Collections;
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);
}
public class QuadCatchCtr : MonoBehaviour
{
[Header("检测设置")]
[SerializeField] private float rayLength = 50f;
[SerializeField] private LayerMask detectionLayer;
// 握拳时射线命中 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);
}
}
[Tooltip("张开手丢失后保持就绪的宽限时间(秒),避免手势过渡时漏判")]
[SerializeField] private float readyGracePeriod = 0.3f;
// 松手
void OnSelectExited(SelectExitEventArgs args)
{
GlobalEventMgr.Dispatch(GameEvent.EventHandRelease, 2);
}
}
private bool m_isReady = false;
private bool m_isCatching = false;
private Coroutine m_graceCoroutine;
// ── 张开手 StaticHandGesture ────────────────────────────────
public void OnOpenHandDetected()
{
// 取消正在倒计时的宽限期
if (m_graceCoroutine != null)
{
StopCoroutine(m_graceCoroutine);
m_graceCoroutine = null;
}
m_isReady = true;
}
public void OnOpenHandLost()
{
// 不立即清除,给握拳手势留过渡窗口
m_graceCoroutine = StartCoroutine(ClearReadyAfterDelay());
}
private IEnumerator ClearReadyAfterDelay()
{
yield return new WaitForSeconds(readyGracePeriod);
if (!m_isCatching)
m_isReady = false;
m_graceCoroutine = null;
}
// ── 握拳 StaticHandGesture ──────────────────────────────────
public void OnFistDetected()
{
if (!m_isReady || m_isCatching) return;
// 相机视线射线验证
Camera cam = Camera.main;
Ray ray = new Ray(cam.transform.position, cam.transform.forward);
if (!Physics.Raycast(ray, out RaycastHit hit, rayLength, detectionLayer))
return;
string hitName = hit.collider.gameObject.name;
if (hitName.Length < 5 || hitName.Substring(0, 4) != "Quad") return;
if (!int.TryParse(hitName.Substring(4), out int fontIndex)) return;
m_isCatching = true;
GlobalEventMgr.Dispatch(GameEvent.EventRayQuadOk, true, 2, fontIndex);
}
public void OnFistLost()
{
if (!m_isCatching) return;
m_isCatching = false;
m_isReady = false;
GlobalEventMgr.Dispatch(GameEvent.EventHandRelease, 2);
}
}