Unity의 XR 개발은 사용자 지정 진동을 처리합니다.

유니티 새 버전을 사용하고 나서 VR 개발툴도 다시 변경하고 플러그인도 XRTookit으로 변환해줬습니다. Valem 튜토리얼의 코드. 다음과 같이:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.XR.Interaction.Toolkit;
[System.Serializable]
public class Haptic
{
    
    
    [Range(0, 1)]
    public float instensity;
    public float duration;
    public void TriggerHaptic(BaseInteractionEventArgs eventArgs)
    {
    
    
        if (eventArgs.interactableObject is XRBaseControllerInteractor controllerInteractor)
        {
    
    
            TriggerHaptic(controllerInteractor.xrController);
        }
    }
    public void TriggerHaptic(XRBaseController controller)
    {
    
    
        if (instensity > 0)
            controller.SendHapticImpulse(instensity, duration);
    }
}
/// <summary>
/// 挂载在物体上的,物体上还需要XRGrabInteractable.cs
/// </summary>
public class HapticInteractable : MonoBehaviour
{
    
    
    public Haptic hapticOnActivated;
    public Haptic hapticHoverEntered;
    public Haptic hapticHoverExited;
    public Haptic hapticSelectEntered;
    public Haptic hapticSelectExited;
    void Start()
    {
    
    
        XRBaseInteractable interactable = GetComponent<XRBaseInteractable>();
        interactable.activated.AddListener(hapticOnActivated.TriggerHaptic);
        interactable.hoverEntered.AddListener(hapticHoverEntered.TriggerHaptic);
        interactable.hoverExited.AddListener(hapticHoverExited.TriggerHaptic);
        interactable.selectEntered.AddListener(hapticSelectEntered.TriggerHaptic);
        interactable.selectExited.AddListener(hapticSelectExited.TriggerHaptic);
    }
}

추천

출처blog.csdn.net/kuilaurence/article/details/129496487