VRTK中的物体和手柄高亮以及手柄振动设置

VRTK设计到的相关类

  • 控制器高亮:VRTK_ControllerHighlighter
  • 物体/控制器(边缘)高亮:VRTK_OutlineObjectCopyHighLighter
  • 控制器振动:VRTK_ControllerHaptics

脚本控制实现细节

  • 控制器整体高亮:
highLighter.HighlightController(Color.red);
  • 控制器透明:
 VRTK_ObjectAppearance.SetOpacity(VRTK_DeviceFinder.GetModelAliasController(gameObject),0.5f);
  • 控制器某个按钮高亮(开/关):
 highLighter.HighlightElement(SDK_BaseController.ControllerElements.Trigger,Color.yellow);
  • 控制器振动
VRTK_ControllerHaptics.TriggerHapticPulse(VRTK_ControllerReference.GetControllerReference(gameObject),0.1f);

Unity中VRTK_SDK配置


VRTK中的物体和手柄高亮以及手柄振动设置_第1张图片

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

public class ControllerHighlight : MonoBehaviour
{
    /// 
    /// 高亮组件
    /// 
    private VRTK_ControllerHighlighter highLighter;
    /// 
    /// 控制器事件
    /// 
    private VRTK_ControllerEvents events;
    // Use this for initialization
    void Start ()
    {
        highLighter = GetComponent();
        events = GetComponent();
        events.TriggerPressed += Events_TriggerPressed;
        events.TriggerReleased += Events_TriggerReleased;
    }

    private void Events_TriggerReleased(object sender, ControllerInteractionEventArgs e)
    {
        highLighter.UnhighlightElement(SDK_BaseController.ControllerElements.Trigger);
        VRTK_ObjectAppearance.SetOpacity(VRTK_DeviceFinder.GetModelAliasController(gameObject), 1f);
    }

    private void Events_TriggerPressed(object sender, ControllerInteractionEventArgs e)
    {
        highLighter.HighlightElement(SDK_BaseController.ControllerElements.Trigger,Color.yellow);
        VRTK_ObjectAppearance.SetOpacity(VRTK_DeviceFinder.GetModelAliasController(gameObject),0.5f);
    }

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

    }

    private void OnTriggerStay(Collider other)
    {
        //highLighter.HighlightController(Color.yellow);
        highLighter.HighlightElement(SDK_BaseController.ControllerElements.Body,Color.yellow);
        VRTK_ControllerHaptics.TriggerHapticPulse(VRTK_ControllerReference.GetControllerReference(gameObject),0.1f);
    }

    private void OnTriggerExit(Collider other)
    {
        //highLighter.UnhighlightController();
        highLighter.UnhighlightElement(SDK_BaseController.ControllerElements.Body);
    }
}

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