HTC Vive 交互开发——手部模型替换和抓取实现

手部模型替换和抓取实现

    可以在BasicVRHand.unitypackage包中中获取手部模型。


HTC Vive 交互开发——手部模型替换和抓取实现_第1张图片

Hierarchy面板的VRTK_SDK配置


HTC Vive 交互开发——手部模型替换和抓取实现_第2张图片

左右控制器Inspector面板设置


HTC Vive 交互开发——手部模型替换和抓取实现_第3张图片

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using VRTK;

public class HandRe : MonoBehaviour
{
    /// 
    /// 手柄控制器
    /// 
    public GameObject controller;
    /// 
    /// 动画控制器
    /// 
    private Animator ani;
    // Use this for initialization
    void Start ()
    {
        ani = GetComponent();
        //controller.GetComponent().UseButtonPressed += Hand_UseButtonPressed;
        //controller.GetComponent().UseButtonReleased += Hand_UseButtonReleased;
        controller.GetComponent().TriggerAxisChanged += HandRe_TriggerAxisChanged;
    }

    private void HandRe_TriggerAxisChanged(object sender, ControllerInteractionEventArgs e)
    {
        ani.Play("grab",0,e.buttonPressure);
        ani.speed = 0;
    }

    /// 
    /// trigger键松开处理函数
    /// 
    /// 
    /// 
    private void Hand_UseButtonReleased(object sender, ControllerInteractionEventArgs e)
    {
        ani.SetTrigger("Release");
    }
    /// 
    /// trigger按下处理函数
    /// 
    /// 
    /// 
    private void Hand_UseButtonPressed(object sender, ControllerInteractionEventArgs e)
    {
        ani.SetTrigger("Grab");
    }

    // Update is called once per frame
    void Update ()
    {

    }
}

你可能感兴趣的:(C#,Unity3D,HTC,Vive开发,游戏开发,AR/VR,游戏开发学习,VRTK交互开发)