提交交互替换
This commit is contained in:
33
Assets/YOMOV Access/Scripts/QuadCatchCtr.cs
Normal file
33
Assets/YOMOV Access/Scripts/QuadCatchCtr.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
11
Assets/YOMOV Access/Scripts/QuadCatchCtr.cs.meta
Normal file
11
Assets/YOMOV Access/Scripts/QuadCatchCtr.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c81c43c17da9e974196f131ea1b8a417
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,10 +1,8 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR.Interaction.Toolkit;
|
||||
|
||||
// 假设命名空间是 LevelUp.GrabInteractions
|
||||
namespace LevelUp.GrabInteractions
|
||||
{
|
||||
// 基础类,负责事件监听和延迟调用
|
||||
[RequireComponent(typeof(UnityEngine.XR.Interaction.Toolkit.Interactables.XRGrabInteractable))]
|
||||
public class ResetObject : MonoBehaviour
|
||||
{
|
||||
@@ -12,24 +10,25 @@ namespace LevelUp.GrabInteractions
|
||||
[Tooltip("物体返回原位之前的延迟时间 (秒)。")]
|
||||
[SerializeField]
|
||||
protected float resetDelayTime = 3f;
|
||||
|
||||
// 核心字段
|
||||
protected UnityEngine.XR.Interaction.Toolkit.Interactables.XRGrabInteractable m_GrabInteractable;
|
||||
protected Vector3 returnToPosition;
|
||||
|
||||
protected Quaternion returnToRotation;
|
||||
protected Rigidbody m_Rigidbody;
|
||||
|
||||
[Tooltip("指示物体是否应该被重置。子类可用于逻辑判断。")]
|
||||
public bool shouldReturnHome { get; protected set; } = true;
|
||||
public AudioSource downAudio;
|
||||
|
||||
protected void Awake()
|
||||
protected void Awake()
|
||||
{
|
||||
m_GrabInteractable = GetComponent<UnityEngine.XR.Interaction.Toolkit.Interactables.XRGrabInteractable>();
|
||||
m_Rigidbody = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
protected void Start()
|
||||
protected void Start()
|
||||
{
|
||||
// 记录物体在场景中的初始位置
|
||||
returnToPosition = this.transform.position;
|
||||
returnToRotation = this.transform.rotation;
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
@@ -53,28 +52,31 @@ namespace LevelUp.GrabInteractions
|
||||
|
||||
protected virtual void OnSelect(SelectEnterEventArgs arg0)
|
||||
{
|
||||
// 抓取时取消任何待执行的 ReturnHome 调用
|
||||
CancelInvoke(nameof(ReturnHome));
|
||||
}
|
||||
|
||||
protected virtual void OnSelectExit(SelectExitEventArgs arg0)
|
||||
{
|
||||
// 松手时延迟调用 ReturnHome
|
||||
Invoke(nameof(ReturnHome), resetDelayTime);
|
||||
if (downAudio != null)
|
||||
downAudio.Play();
|
||||
downAudio.Play();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 核心重置函数。设置为 virtual 以便子类重写。
|
||||
/// 默认实现为瞬移。
|
||||
/// </summary>
|
||||
protected virtual void ReturnHome()
|
||||
{
|
||||
if (shouldReturnHome)
|
||||
{
|
||||
// 父类的默认实现是瞬移
|
||||
|
||||
if (m_Rigidbody != null && !m_Rigidbody.isKinematic)
|
||||
{
|
||||
m_Rigidbody.velocity = Vector3.zero;
|
||||
m_Rigidbody.angularVelocity = Vector3.zero;
|
||||
}
|
||||
|
||||
|
||||
transform.position = returnToPosition;
|
||||
transform.rotation = returnToRotation;
|
||||
|
||||
Debug.Log($"物体 '{gameObject.name}' 已瞬移重置到原点。", this);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user