?1.导入VRTK开发包 ,下方三个为基础控件,用于识别硬件设备以及相关配置
?2.移动功能简介?
?
?3.ui交互事件,将VRTK_UICanvas 组件添加到Canvas下可用ui所有事件
1.问题容易出现ui穿透,所以在做的时候要防止穿透,最好不存在遮挡,将不需要用的ui缩小为0
2.问题动态ui添加事件容易出问题(例如滚动ui的button点击事件会出现ui绑定事件错乱,原因为ui层级发生变动,所以应该提前添加事件)
4.物体抓取、碰撞反馈:重写VRTK_InteractableObject,例如碰到该物体执行事件或者将物体丢出执行事件
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using VRTK;
public enum Test_demo_chong_xie
{
黑板擦,
桌子
}
/// <summary>
/// 切记 此脚本重写VRTK_InteractableObject ,所以被抓取对象不应再挂载 VRTK_InteractableObject
/// </summary>
public class Hei_ban_ca_zhuozi : VRTK_InteractableObject
{
public Test_demo_chong_xie demo;
/// <summary>
/// 抓住物体 回调
/// </summary>
/// <param name="currentGrabbingObject"></param>
public override void Grabbed(VRTK_InteractGrab currentGrabbingObject = null)
{
base.Grabbed(currentGrabbingObject);
print("拿起东西");
if (demo == Test_demo_chong_xie.黑板擦)
{
transform.GetChild(0).gameObject.SetActive(false);
}
}
/// <summary>
/// 丢掉物体 回调
/// </summary>
/// <param name="previousGrabbingObject"></param>
public override void Ungrabbed(VRTK_InteractGrab previousGrabbingObject = null)
{
base.Ungrabbed(previousGrabbingObject);
print("丢掉东西");
if (demo == Test_demo_chong_xie.黑板擦)
{
transform.GetChild(0).gameObject.SetActive(true);
switch (UIEvent.instance.di_or_gao_number)
{
//di
case 1:
transform.GetComponent<Ray_VR_3d_di_ji_bie_event>().Diu_hei_ban();
break;
//gao
case 2:
transform.GetComponent<Ray_VR_3d_gao_ji_bie_event>().Diu_hei_ban_ca();
break;
default:
break;
}
}
}
/// <summary>
/// 接触物体 回调
/// </summary>
/// <param name="currentTouchingObject"></param>
public override void StartTouching(VRTK_InteractTouch currentTouchingObject = null)
{
base.StartTouching(currentTouchingObject);
print("正在被敲打");
if(demo== Test_demo_chong_xie.桌子)
{
switch (UIEvent.instance.di_or_gao_number)
{
//di
case 1:
transform.GetComponent<Ray_VR_3d_di_ji_bie_event>().Pai_zhuo_zi();
break;
//gao
case 2:
transform.GetComponent<Ray_VR_3d_gao_ji_bie_event>().Pai_zhuo_zi();
break;
default:
break;
}
}
}
}
|