如何在VR场景中角度位移传感器与行走Unity VRTK

VRTK - SteamVR Unity Toolkit 1.1.0 (Jun 13, 2016)
726 || this.offsetHeight>700){if(this.offsetWidth/726 > this.offsetHeight/700){this.width=726;}else{this.height=700;}}" style="max-width:726max-height:700" title="点击查看原图" onclick="if(this.parentNode.tagName!='A') window.open('/forum/attachment/1607/thread/39_1_fcc209bf262414f.jpg');" />
A collection of useful scripts and prefabs for building SteamVR titles in Unity 5. This toolkit provides many common VR functionality within Unity3d such as (but not limited to): Controller button events with common aliases Controller world pointers (e.g. laser pointers) Player teleportation Grabbing/holding objects using the controllers Interacting with objects using the controllers The toolkit is heavily inspired and based upon the SteamVR Plugin for Unity3d Github Repo. The reason this toolkit exists is because I found the SteamVR plugin to contain confusing to use or broken code and I decided to build a collection of scripts/assets that I would find useful when building for VR within Unity3d.
VRTK - SteamVR Unity Toolkit 1.1.0 (Jun 13, 2016)
链接: 密码:vm9k
要评论请先&或者&
这么好的工具居然没人来顶?抢发沙
Simple Pointer功能打包后失效(没反应)是怎么回事,望高手指点/ JoeWorkspace
项目语言:None
权限:read-only(如需更高权限请先加入项目)
JoeWorkspace/
//====================================================================================
// Purpose: Provide basic laser pointer to VR Controller
// This script must be attached to a Controller within the [CameraRig] Prefab
// The VRTK_ControllerEvents script must also be attached to the Controller
// Press the default 'Grip' button on the controller to activate the beam
// Released the default 'Grip' button on the controller to deactivate the beam
// This script is an implementation of the VRTK_WorldPointer.
//====================================================================================
namespace VRTK
using UnityE
//从控制器尾部发出一个有色光束来模拟激光束。这在场景中指向对象很有用,它能判断所指向的对象以及对象距控制器发出光束位置的距离。
public class VRTK_SimplePointer : VRTK_WorldPointer
public float pointerThickness = 0.002f;
public float pointerLength = 100f;
public bool showPointerTip =
public GameObject customPointerC
public LayerMask layersToIgnore = Physics.IgnoreRaycastL
private GameObject pointerH
private GameO
private GameObject pointerT
private Vector3 pointerTipScale = new Vector3(0.05f, 0.05f, 0.05f);
// material of customPointerCursor (if defined)
private Material customPointerM
protected override void OnEnable()
base.OnEnable();
InitPointer();
protected override void OnDisable()
base.OnDisable();
if (pointerHolder != null)
Destroy(pointerHolder);
protected override void Update()
base.Update();
if (pointer.gameObject.activeSelf)
Ray pointerRaycast = new Ray(transform.position, transform.forward);
RaycastHit pointerCollidedW
var rayHit = Physics.Raycast(pointerRaycast, out pointerCollidedWith, pointerLength, ~layersToIgnore);
var pointerBeamLength = GetPointerBeamLength(rayHit, pointerCollidedWith);
SetPointerTransform(pointerBeamLength, pointerThickness);
protected override void InitPointer()
pointerHolder = new GameObject(string.Format(&[{0}]WorldPointer_SimplePointer_Holder&, gameObject.name));
Utilities.SetPlayerObject(pointerHolder, VRTK_PlayerObject.ObjectTypes.Pointer);
pointerHolder.transform.parent =
pointerHolder.transform.localPosition = Vector3.
pointer = GameObject.CreatePrimitive(PrimitiveType.Cube);
pointer.transform.name = string.Format(&[{0}]WorldPointer_SimplePointer_Pointer&, gameObject.name);
Utilities.SetPlayerObject(pointer, VRTK_PlayerObject.ObjectTypes.Pointer);
pointer.transform.parent = pointerHolder.
pointer.GetComponent&BoxCollider&().isTrigger =
pointer.AddComponent&Rigidbody&().isKinematic =
pointer.layer = LayerMask.NameToLayer(&Ignore Raycast&);
if (customPointerCursor == null)
pointerTip = GameObject.CreatePrimitive(PrimitiveType.Sphere);
pointerTip.transform.localScale = pointerTipS
Renderer renderer = customPointerCursor.GetComponentInChildren&MeshRenderer&();
if (renderer)
customPointerMaterial = Material.Instantiate(renderer.sharedMaterial);
pointerTip = Instantiate(customPointerCursor);
foreach (Renderer mr in pointerTip.GetComponentsInChildren&Renderer&())
mr.material = customPointerM
pointerTip.transform.name = string.Format(&[{0}]WorldPointer_SimplePointer_PointerTip&, gameObject.name);
Utilities.SetPlayerObject(pointerTip, VRTK_PlayerObject.ObjectTypes.Pointer);
pointerTip.transform.parent = pointerHolder.
pointerTip.GetComponent&Collider&().isTrigger =
pointerTip.AddComponent&Rigidbody&().isKinematic =
pointerTip.layer = LayerMask.NameToLayer(&Ignore Raycast&);
base.InitPointer();
SetPointerTransform(pointerLength, pointerThickness);
TogglePointer(false);
protected override void SetPointerMaterial()
base.SetPointerMaterial();
pointer.GetComponent&Renderer&().material = pointerM
if (customPointerMaterial != null)
customPointerMaterial.color = pointerMaterial.
pointerTip.GetComponent&Renderer&().material = pointerM
protected override void TogglePointer(bool state)
state = (pointerVisibility == pointerVisibilityStates.Always_On ? true : state);
base.TogglePointer(state);
pointer.gameObject.SetActive(state);
var tipState = (showPointerTip ? state : false);
pointerTip.gameObject.SetActive(tipState);
if (pointer.GetComponent&Renderer&() && pointerVisibility == pointerVisibilityStates.Always_Off)
pointer.GetComponent&Renderer&().enabled =
private void SetPointerTransform(float setLength, float setThicknes)
//if the additional decimal isn't added then the beam position glitches
var beamPosition = setLength / (2 + 0.00001f);
pointer.transform.localScale = new Vector3(setThicknes, setThicknes, setLength);
pointer.transform.localPosition = new Vector3(0f, 0f, beamPosition);
pointerTip.transform.localPosition = new Vector3(0f, 0f, setLength - (pointerTip.transform.localScale.z / 2));
pointerHolder.transform.localRotation = Quaternion.
base.SetPlayAreaCursorTransform(pointerTip.transform.position);
private float GetPointerBeamLength(bool hasRayHit, RaycastHit collidedWith)
var actualLength = pointerL
//reset if beam not hitting or hitting new target
if (!hasRayHit || (pointerContactTarget && pointerContactTarget != collidedWith.transform))
if (pointerContactTarget != null)
base.PointerOut();
pointerContactDistance = 0f;
pointerContactTarget =
destinationPosition = Vector3.
UpdatePointerMaterial(pointerMissColor);
//check if beam has hit a new target
if (hasRayHit)
pointerContactDistance = collidedWith.
pointerContactTarget = collidedWith.
destinationPosition = pointerTip.transform.
UpdatePointerMaterial(pointerHitColor);
base.PointerIn();
//adjust beam length if something is blocking it
if (hasRayHit && pointerContactDistance & pointerLength)
actualLength = pointerContactD
return actualL
(C)&&2013&&Alibaba&&Inc.&&All&&rights&&resvered.
Powered by 上传我的文档
 下载
 收藏
该文档贡献者很忙,什么也没留下。
 下载此文档
正在努力加载中...
1、Unity Steam_VR 开发工具插件 VRTK自带案例分析(第一部分)
下载积分:2888
内容提示:1、Unity Steam_VR 开发工具插件 VRTK自带案例分析(第一部分)
文档格式:DOCX|
浏览次数:0|
上传日期: 12:48:17|
文档星级:
全文阅读已结束,如果下载本文需要使用
 2888 积分
下载此文档
该用户还上传了这些文档
1、Unity Steam_VR 开发工具插件 VRTK自带案例分析(第
官方公共微信}

我要回帖

更多关于 化学位移 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信