手部模型替换和抓取实现
可以在BasicVRHand.unitypackage包中中获取手部模型。
Hierarchy面板的VRTK_SDK配置
左右控制器Inspector面板设置
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using VRTK;
public class HandRe : MonoBehaviour
{
/// <summary>
/// 手柄控制器
/// </summary>
public GameObject controller;
/// <summary>
/// 动画控制器
/// </summary>
private Animator ani;
// Use this for initialization
void Start ()
{
ani = GetComponent<Animator>();
//controller.GetComponent<VRTK_InteractUse>().UseButtonPressed += Hand_UseButtonPressed;
//controller.GetComponent<VRTK_InteractUse>().UseButtonReleased += Hand_UseButtonReleased;
controller.GetComponent<VRTK_ControllerEvents>().TriggerAxisChanged += HandRe_TriggerAxisChanged;
}
private void HandRe_TriggerAxisChanged(object sender, ControllerInteractionEventArgs e)
{
ani.Play("grab",0,e.buttonPressure);
ani.speed = 0;
}
/// <summary>
/// trigger键松开处理函数
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Hand_UseButtonReleased(object sender, ControllerInteractionEventArgs e)
{
ani.SetTrigger("Release");
}
/// <summary>
/// trigger按下处理函数
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Hand_UseButtonPressed(object sender, ControllerInteractionEventArgs e)
{
ani.SetTrigger("Grab");
}
// Update is called once per frame
void Update ()
{
}
}