VRTK官方示例 |
版本面试 |
做者数据库 |
参与者编程 |
完成日期设计模式 |
备注网络 |
VRTK_LegacyExample_V01_1.0数据结构 |
严立钻app |
|
2018.10.05框架 |
|
|
|
|
|
|
#《VRTK官方示例》发布说明:ide
++++“VRTK官方示例”,VRTK做为立钻哥哥2018年度重点打造的技术突破点,因此对VRTK的各类尝试,也产生了各类对VRTK的研究剖析,这里咱们对官方示例进行剖析;学习
++++“VRTK官方示例”,定位是初级阶段的探索,经过剖析学习官方示例,达到熟悉VRTK的应用;
#《VRTK官方示例》目录:
++++00、立钻哥哥带您VRTK官方示例
++++0一、001_CameraRig_VRPlayArea
++++0二、002_Controller_Events
++++0三、003_Controller_SimplePointer
++++0四、004_CameraRig_BasicTeleport
++++0五、005_Controller_BasicObjectGrabbing
++++0六、006_Controller_UsingADoor
++++0七、007_CameraRig_HeightAdjustTeleport
++++0八、008_Controller_UsingAGrabbedObject
++++0九、009_Controller_BezierPointer
++++十、010_CameraRig_TerrainTeleporting
++++十一、011_Camera_HeadSetCollisionFading
++++十二、012_Controller_PointerWithAreaCollision
++++1三、013_Controller_UsingAndGrabbingMultipleObjects
++++1四、014_Controller_SnappingObjectsOnGrab
++++1五、015_Controller_TouchpadAxisControl
++++1六、016_Controller_HapticRumble
++++1七、017_CameraRig_TouchpadWalking
++++1八、018_CameraRig_FramesPerSecondCounter
++++1九、019_Controller_InteractingWithPointer
++++20、020_CameraRig_MeshTeleporting
++++2一、021_Controller_GrabbingObjectsWithJoints
++++2二、022_Controller_CustomBezierPointer
++++2三、023_Controller_ChildOfControllerOnGrab
++++2四、024_CameraRig_ExcludeTeleportLocations
++++2五、025_Controls_Overview
++++2六、026_Controller_ForceHoldObject
++++2七、027_CameraRig_TeleportByModelVillage
++++2八、028_CameraRig_RoomExtender
++++2九、029_Controller_Tooltips
++++30、030_Controls_RadialTouchpadMenu
++++3一、031_CameraRig_HeadsetGazePointer
++++3二、032_Controller_CustomControllerModel
++++3三、033_CameraRig_TeleportingInNavMesh
++++3四、034_Controls_InteractingWithUnityUI
++++3五、035_Controller_OpacityAndHighlighting
++++3六、036_Controller_CustomCompoundPointer
++++3七、037_CameraRig_ClimbingFalling
++++3八、038_CameraRig_DashTeleport
++++3九、039_CameraRig_AdaptiveQuality
++++40、040_Controls_PanelMenu
++++4一、041_Controller_ObjectSnappingToDropZones
++++4二、042_CameraRig_MoveInPlace
++++4三、043_Controller_SecondaryControllerActions
++++4四、044_CameraRig_RestrictedTeleportZones
#00、立钻哥哥带您VRTK官方示例 |
++00、立钻哥哥带您VRTK官方示例
++++001_CameraRig_VRPlayArea
++++002_Controller_Events
++++003_Controller_SimplePointer
++++004_CameraRig_BasicTeleport
++++005_Controller_BasicObjectGrabbing
++++006_Controller_UsingADoor
++++007_CameraRig_HeightAdjustTeleport
++++008_Controller_UsingAGrabbedObject
++++009_Controller_BezierPointer
++++010_CameraRig_TerrainTeleporting
++++011_Camera_HeadSetCollisionFading
++++012_Controller_PointerWithAreaCollision
++++013_Controller_UsingAndGrabbingMultipleObjects
++++014_Controller_SnappingObjectsOnGrab
++++015_Controller_TouchpadAxisControl
++++016_Controller_HapticRumble
++++017_CameraRig_TouchpadWalking
++++018_CameraRig_FramesPerSecondCounter
++++019_Controller_InteractingWithPointer
++++020_CameraRig_MeshTeleporting
++++021_Controller_GrabbingObjectsWithJoints
++++022_Controller_CustomBezierPointer
++++023_Controller_ChildOfControllerOnGrab
++++024_CameraRig_ExcludeTeleportLocations
++++025_Controls_Overview
++++026_Controller_ForceHoldObject
++++027_CameraRig_TeleportByModelVillage
++++028_CameraRig_RoomExtender
++++029_Controller_Tooltips
++++030_Controls_RadialTouchpadMenu
++++031_CameraRig_HeadsetGazePointer
++++032_Controller_CustomControllerModel
++++033_CameraRig_TeleportingInNavMesh
++++034_Controls_InteractingWithUnityUI
++++035_Controller_OpacityAndHighlighting
++++036_Controller_CustomCompoundPointer
++++037_CameraRig_ClimbingFalling
++++038_CameraRig_DashTeleport
++++039_CameraRig_AdaptiveQuality
++++040_Controls_PanelMenu
++++041_Controller_ObjectSnappingToDropZones
++++042_CameraRig_MoveInPlace
++++043_Controller_SecondaryControllerActions
++++044_CameraRig_RestrictedTeleportZones
###001_CameraRig_VRPlayArea |
++001_CameraRig_VRPlayArea
++++立钻哥哥:Assets/VRTK/LegacyExampleFiles/001_CameraRig_VRPlayArea.unity
###002_Controller_Events |
++002_Controller_Events
++++立钻哥哥:Assets/VRTK/LegacyExampleFiles/002_Controller_Events.unity
++002_Controller_Events
++++立钻哥哥:做用:监测手柄的各类输入:扳机、触摸板、侧键等等;
++示例
++++立钻哥哥:手柄挂上[VRTK_ControllerEvents.cs];
++++[pointerToggleButton]:激光指示器打开/关闭的操做的按钮;
++++[pointerSetButton]:用于从指针的光标位置设置目标标记的操做的按钮;
++++例如按下扳机键:注册按下扳机键的事件,按下扳机键注册的方法便可执行,还能够拿到一些具体的参数:
GetComponent<VRTK_ControllerEvents>().TriggerPressed += new ControllerInteractionEventHandlder(DoTriggerPressed);
private void DoTriggerPressed(object sender, ControllerInteractionEventArgs e){ Debug.Logger(VRTK_ControllerReference.GetRealIndex(e.controllerReference), “TRIGGER”, “pressed”, e); } |
###003_Controller_SimplePointer |
++003_Controller_SimplePointer
++++立钻哥哥:Assets/VRTK/LegacyExampleFiles/003_Controller_SimplePointer.unity
++003_Controller_SimplePointer
++++立钻哥哥:做用:射线;
++示例
++++立钻哥哥:手柄挂上[VRTK_Pointer.cs]和[VRTK_StraightPointerRenderer.cs]就能够摁下按键发出射线,而且把对应的手柄拖进来;
++++能够经过[VRTK_DestinationMarker]拿到射线指向的点的信息,包括距离、目标点的Transform、射线、目标点的世界坐标、是否传送等等;
//立钻哥哥:\Assets\VRTK\Source\Scripts\Pointers\VRTK_DestinationMarker.cs public struct DestinationMarkerEventArgs{ public float distance; public Transform target; public RaycastHit raycastHit; public Vector3 destinationPosition; public Quaternion? destinationRotation; public bool forceDestinationPosition; public bool enableTeleport; public VRTK_ControllerReference controllerReference; } |
++++监听事件以下:
//Setup controller event listeners GetComponent<VRTK_DestinationMarker>().DestinationMarkerEnter += new DestinationMarkerEventHandler(DoPointerIn);
if(showHoverState){ GetComponent<VRTK_DestinationMarker>().DestinationMarkerHover += new DestinationMarkerEventHandler(DoPointerHover); }
GetComponent<VRTK_DestinationMarker>().DestinationMarkerExit += new DestinationMarkerEventHandler(DoPointerOut); GetComponent<VRTK_DestinationMarker>().DestinationMakerSet += new DestinationMarkerEventHandler(DoPointerDestinationSet);
private void DoPointerIn(object sender, DestinationMarkerEventArgs e){ }
private void DoPointerHover(object sender, DestinationMarkerEventArgs e){ }
private void DoPointerOut(object sender, DestinationMarkerEventArgs e){ }
private void DoPointerDestinationSet(object sender, DestinationMarkerEventArgs e){ } |
###004_CameraRig_BasicTeleport |
++004_CameraRig_BasicTeleport
++++立钻哥哥:Assets/VRTK/LegacyExampleFiles/004_CameraRig_BasicTeleport.unity
++004_CameraRig_BasicTeleport
++++立钻哥哥:做用:传送;
++示例
++++立钻哥哥:在[VRTK_Scripts]下随便建立一个空物体GameObject,添加脚本[VRTK_BasicTeleport.cs];
++++[Blink To Color]:传送时过分颜色;
++++[Blink Transition Speed]:在基本的传送脚本上能够改变褪色的闪烁速度,以提供定制的传送体验;将速度设置为0将意味着不会出现褪色的闪烁效果;
++++[Distance Blink Delay]:在0到32之间的范围,决定了眨眼转换的时间长短取决于被传送的距离;值为0,将不会延迟瞬移效应在任何距离上,值为32将延迟瞬移瞬变,即便距离传送的距离很是接近原来的位置;这能够用来模拟时间花费更长的时间来传递用户的远程端口;值16提供了一个适当的基础来模拟这个给用户;
++++[Headset Position Compensation]:以头部为基准,做为传送的位置;未打钩,则是玩家可玩区域的中心位置做为传送的目标点;可玩区域不能和游戏环境交叉,最大化玩家活动空间;
++++[Nav Mesh Limit Distance]:NavMesh边缘限制,在NavMesh上传送,若是在NavMesh的边界,则禁止传送,数值是离边界的距离范围;
++++手柄须要添加发射射线的脚本:[VRTK_Pointer.cs]、[VRTK_StraightPointerRenderer.cs]便可实现传送;
###005_Controller_BasicObjectGrabbing |
++005_Controller_BasicObjectGrabbing
++++立钻哥哥:Assets/VRTK/LegacyExampleFiles/005_Controller_BasicObjectGrabbing.unity
++005_Controller_BasicObjectGrabbing
++++立钻哥哥:做用:抓起物体;
++示例
++++立钻哥哥:在左手控制器上添加[VRTK_InteractTouch.cs]、[VRTK_InteractGrab.cs];
++抓取物体
++++立钻哥哥:在须要抓取的物体上添加[VRTK_InteractableObject.cs]便可,用手柄抓起物体以后,会默认给物体添加抓取方式[VRTK_FixedJointGrabAttach.cs]组件;
++++此外,换手操做须要给物体添加[VRTK_SwapControllerGrabAction.cs];
++++物体高亮添加[VRTK_OutlineObjectCopyHighlighter.cs];
###006_Controller_UsingADoor |
++006_Controller_UsingADoor
++++立钻哥哥:Assets/VRTK/LegacyExampleFiles/006_Controller_UsingADoor.unity
++006_Controller_UsingADoor
++++立钻哥哥:做用:[VRTK_InteractableObject.cs]的扩展;
++示例
++++立钻哥哥:这个Demo里用开关门的例子对[VRTK_InteractableObject.cs]脚本进行了扩展;
++碰到门的处理
++++立钻哥哥:碰到门,按下侧键就会调用一次StartUsing();
//立钻哥哥:\Assets\VRTK\LegacyExampleFiles\ExampleResources\Scripts\Openable_Door.cs namespace VRTK.Examples{ using UnityEngine;
public class Openable_Door : VRTK_InteractableObject{ public bool flipped = false; public bool rotated = false;
private float sideFlip = -1; private float side = -1; private float smooth = 270.0f; private float doorOpenAngle = -90f; private bool open = false;
private Vector3 defaultRatation; private Vector3 openRatation;
public override void StartUsing(VRTK_InteractUse usingObject){ base.StartUsing(usingObject); SetDoorRotation(usingObject.transform.position); SetRotation(); open = !open; }
protected void Start(){ defaultRotation = transform.eulerAngles; SetRotation(); siderFlip = (flipped ? 1 : -1); }
protected override void Update(){ base.Update(); if(open){ transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(openRotation), Time.deltaTime * smooth); }else{ transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(defaultRotation), Time.deltaTime * smooth); } }
private void SetRotation(){ openRotation = new Vector3(defaultRotation.x, defaultRotation.y + (doorOpenAngle * (sideFlip * side)), defaultRotation.z); }
private void SetDoorRotation(Vector3 interacterPosition){ side = ((rotated == false && interacterPosition.z > transform.position.z) || (rotated == true && interacterPosition.x > transform.position.x) ? -1 : 1); }
} //立钻哥哥:public class Openable_Door:VRTK_InteractableObject{}
} //立钻哥哥:namespace VRTK.Examples{} |
###007_CameraRig_HeightAdjustTeleport |
++007_CameraRig_HeightAdjustTeleport
++++立钻哥哥:Assets/VRTK/LegacyExampleFiles/007_CameraRig_HeightAdjustTeleport.unity
++007_CameraRig_HeightAdjustTeleport
++++立钻哥哥:做用:升降传送;
++示例
++++立钻哥哥:“004_CameraRig_BasicTeleport”的传送时平面传送,一样在[VRTK_Scripts]下建立的GameObject上添加[VRTK_HeightAdjustTeleport.cs]组件;
++++[snapToNearestFloor]:若是勾选,那么传送的Y位置将会吸附到离地面最近的位置(即不会飘在空中);若是未勾选,那么传送的Y位置将是目标Y位置的位置(能够在空中);
++++[customRaycast]:某个层的指定射线;
###008_Controller_UsingAGrabbedObject |
++008_Controller_UsingAGrabbedObject
++++立钻哥哥:Assets/VRTK/LegacyExampleFiles/008_Controller_UsingAGrabbedObject.unity
++008_Controller_UsingAGrabbedObject
++++立钻哥哥:做用:[VRTK_InteractableObject.cs]扩展,相似场景“006_Controller_UsingADoor”;
++示例
++++立钻哥哥:
//立钻哥哥:\Assets\VRTK\LegacyExampleFiles\ExampleResources\Scripts\Gun.cs namespace VRTK.Examples{ using UnityEngine;
public class Gun : VRTK_InteractableObject{ private GameObject bullet; private float bullectSpeed = 1000f; private float bullectLife = 5f;
public override void StartUsing(VRTK_InteractUse usingObject){ base.StartUsing(usingObject); FireBullet(); }
protected void Start(){ bullet = transform.Find(“Bullet”).gameObject; bullet.SetActive(false); }
private void FireBullet(){ GameObject bullectClone = Instantiate(bullect, bullect.transform.position, bullet.transform.rotation) as GameObject; bullectClone.SetActive(true); Rigidbody rb = bullectClone.GetComponent<Rigidbody>(); rb.AddForce(-bullect.transform.forward * bullectSpeed); Destroy(bullectClone, bullectLife); }
} //立钻哥哥:public class Gun:VRTK_InteractableObject{}
} //立钻哥哥:namespace VRTK.Examples{} |
###009_Controller_BezierPointer |
++009_Controller_BezierPointer
++++立钻哥哥:Assets/VRTK/LegacyExampleFiles/009_Controller_BezierPointer.unity
++009_Controller_BezierPointer
++++立钻哥哥:做用:抛物线传送(贝塞尔曲线);
++示例
++++立钻哥哥:手柄上须要添加的脚本有:
--[VRTK_Controller_Events.cs]
--[VRTK_Pointer.cs]
--[VRTK_BezierPointerRenderer.cs]
###010_CameraRig_TerrainTeleporting |
++010_CameraRig_TerrainTeleporting
++++立钻哥哥:Assets/VRTK/LegacyExampleFiles/010_CameraRig_TerrainTeleporting.unity
++010_CameraRig_TerrainTeleporting
++++立钻哥哥:做用:传送;
++示例
++++立钻哥哥:和场景“009_Controller_BezierPointer”相似;
###011_Camera_HeadSetCollisionFading |
++011_Camera_HeadSetCollisionFading
++++立钻哥哥:Assets/VRTK/LegacyExampleFiles/011_Camera_HeadSetCollisionFading.unity
++011_Camera_HeadSetCollisionFading
++++立钻哥哥:做用:头部碰到东西黑屏模拟眨眼;
++示例
++++立钻哥哥:有一些黑屏的效果和忽略的碰撞标签;
++++[VRTK_HeadsetCollision.cs]
++++[VRTK_HeadsetFade.cs]
++++[VRTK_HeadsetCollisionFade.cs]
++++[VRTK_PolicyList.cs]
###012_Controller_PointerWithAreaCollision |
++012_Controller_PointerWithAreaCollision
++++立钻哥哥:/VRTK/LegacyExampleFiles/012_Controller_PointerWithAreaCollision.unity
++012_Controller_PointerWithAreaCollision
++++立钻哥哥:做用:传送的人的区域显示,而且能够设置碰撞是否能够传送;
++示例
++++立钻哥哥:在手柄上添加[VRTK_PlayAreaCursor.cs],而且在贝塞尔曲线脚本里引用一下;
++[VRTK_Scripts]
++++立钻哥哥:在[VRTK_Scripts]下的PlayArea要添加[VRTK_HeadsetCollision.cs]脚本,这个脚本依赖于[VRTK_HeadsetFade.cs]便可;
###013_Controller_UsingAndGrabbingMultipleObjects |
++013_Controller_UsingAndGrabbingMultipleObjects
++++立钻哥哥:/LegacyExampleFiles/013_Controller_UsingAndGrabbingMultipleObjects.unity
++013_Controller_UsingAndGrabbingMultipleObjects
++++立钻哥哥:做用:抓取和使用物体的扩展,[VRTK_InteractableObject.cs]扩展;主要体现“Hold Button To Grab”和“Hold Button To Use”的勾选和不勾选的区别;
++++主要区别在于:是否须要持续按键才能够进行操做;
++示例
++++立钻哥哥:是否勾选“Hold Button To Grab”和“Hold Button To Use”的区别在于:是否须要持续按键才能够进行操做;
###014_Controller_SnappingObjectsOnGrab |
++014_Controller_SnappingObjectsOnGrab
++++立钻哥哥:/VRTK/LegacyExampleFiles/014_Controller_SnappingObjectsOnGrab.unity
++014_Controller_SnappingObjectsOnGrab
++++立钻哥哥:做用:抓取的链接方式,以及抓取位置的设置(能够是自由抓取,或者是固定点抓取);
++++例如:拿剑永远拿剑柄;拿枪能够拿枪柄也能够拿枪管;
++示例
++++立钻哥哥:抓取位置:拿剑永远拿剑柄;若是想要自由抓取的话须要将“Precision Grab”勾选;
++++抓取位置:拿剑永远拿剑柄;
++自由抓取
++++立钻哥哥:若是想要自由抓取的话,只须要将“Precision Grab”勾选;
++链接方式(FixedJoint && ChildOfControllerGrab)
++++立钻哥哥:好比剑(Sword)的抓取链接方式为[VRTK_FixedJointGrabAttach.cs],关节链接的方式,抓住物体以后是能够碰掉的,有碰撞的存在;
++++光刀(LightSaber),抓取链接方式为[VRTK_ChildOfControllerGrabAttach.cs],抓取后将光刀设置为手柄的子对象,而且将刚体上的“Is Kinematic”勾选,即不受力的做用,不会产生碰撞的感受;
++光刀(LightSaber)抓取方式[VRTK_ChildOfControllerGrabAttach]
++++立钻哥哥:光刀(LightSaber),抓取链接方式为[VRTK_ChildOfControllerGrabAttach.cs],抓取后将光刀设置为手柄的子对象,而且将刚体上的“Is Kinematic”勾选,即不受力的做用,不会产生碰撞的感受;
//立钻哥哥:\Assets\VRTK\LegacyExampleFiles\ExampleResources\Scripts\LightSaber.cs namespace VRTK.Examples{ using UnityEngine;
public class LightSaber : VRTK_InteractableObject{ private bool beamActive = false; private Vector2 beamLimits = new Vector2(0f, 1.2f); private float currentBeamSize; private float beamExtendSpeed = 0;
private GameObject blade; private Color activeColor; private Color targetColor; private Color[] bladePhaseColors;
public override void StartUsing(VRTK_InteractUse currentUsingObject = null){ base.StartUsing(currentUsingObject); beamExtendSpeed = 5f; bladePhaseColors = new Color[2]{ Color.blue, Color.cyan }; activeColor = bladePhaseColors[0]; targetColor = bladePhaseColors[1]; }
public override void StopUsing(VRTK_InteractUse previousUsingObject = null, bool resetUsingObjectState = true){ base.StopUsing(previousUsingObject, resetUsingObjectState); beamExtendSpeed = -5f; }
protected void Start(){ blade = transform.Find(“Blade”).gameObject; currentBeamSize = beamLimits.x; SetBeamSize(); }
protected override void Update(){ base.Update(); currentBeamSize = Mathf.Clamp(blade.transform.localScale.y + (beamExtendSpeed * Time.deltaTime), beamLimits.x, beamLimits.y); SetBeamSize(); PulseBeam(); }
private void SetBeamSize(){ blade.transform.localScale = new Vector3(1f, currentBeamSize, 1f); beamActive = (currentBeamSize >= beamLimits.y ? true : false) }
private void PulseBeam(){ if(beamActive){ Color bladeColor = Color.Lerp(activeColor, targetColor, Mathf.PingPong(Time.time, 1)); blade.transform.Find(“Beam”).GetComponent<MeshRenderer>().material.color = bladeColor;
if(bladeColor == targetColor){ var previouslyActiveColor = activeColor; activeColor = targetColor; targetColor = previouslyActiveColor; } } }
} //立钻哥哥:public class LightSaber:VRTK_InteractableObject{}
} //立钻哥哥:namespace VRTK.Examples{} |
###015_Controller_TouchpadAxisControl |
++015_Controller_TouchpadAxisControl
++++立钻哥哥:Assets/VRTK/LegacyExampleFiles/015_Controller_TouchpadAxisControl.unity
++015_Controller_TouchpadAxisControl
++++立钻哥哥:做用:扳机键、触摸板、菜单键的交互;
++示例
++++立钻哥哥:注册按键事件;
//立钻哥哥:\VRTK\LegacyExampleFiles\ExampleResources\Scripts\RC_Car_Controller.cs namespace VRTK.Examples{ using UnityEngine;
public class RC_Car_Controller : MonoBehaviour{ public GameObject rcCar; private RC_Car rcCarScript;
private void Start(){ rcCarScript = rcCar.GetComponent<RC_Car>(); GetComponent<VRTK_ControllerEvents>().TriggerAxisChanged += new ControllerInteractionEventHandler(DoTriggerAxisChanged); GetComponent<VRTK_ControllerEvents>().TouchpadAxisChanged += new ControllerInteractionEventHandler(DoTouchpadAxisChanged);
GetComponent<VRTK_ControllerEvents>().TriggerReleased += new ControllerInteractionEventHandler(DoTriggerReleased); GetComponent<VRTK_ControllerEvents>().TouchpadTouchEnd += new ControllerInteractionEventHandler(DoTouchpadTouchEnd);
GetComponent<VRTK_ControllerEvents>().ButtonTwoPressed += new ControllerInteractionEventHandler(DoCarReset); }
private void DoTouchpadAxisChanged(object sender, ControllerInteractionEventArgs e){ rcCarScript.SetTouchAxis(e.touchpadAxis); }
private void DoTriggerAxisChanged(object sender, ControllerInteractionEventArgs e){ rcCarScript.SetTriggerAxis(e.buttonPressure); }
private void DoTouchpadTouchEnd(object sender, ControllerInteractionEventArgs e){ rcCarScript.SetTouchAxis(Vector2.zero); }
private void DoTriggerReleased(object sender, ControllerInteractionEventArgs e){ rcCarScript.SetTriggerAxis(0f); }
private void DoCarReset(object sender, ControllerInteractionEventArgs e){ rcCarScript.ResetCar(); }
} //立钻哥哥:public class RC_Car_Controller:MonoBehaviour{}
} //立钻哥哥:namespace VRTK.Example{} |
++RC_Car.cs
++++立钻哥哥:\Assets\VRTK\LegacyExampleFiles\ExampleResources\Scripts\RC_Car.cs
//立钻哥哥:\Assets\VRTK\LegacyExampleFiles\ExampleResources\Scripts\RC_Car.cs namespace VRTK.Examples{ using UnityEngine;
public class RC_Car : MonoBehaviour{ public float maxAcceleration = 3f; public float jumpPower = 10f;
private float acceleration = 0.05f; private float movementSpeed = 0f; private float rotationSpeed = 180f; private bool isJumping = false; private Vector2 touchAxis; private float triggerAxis; private Rigidbody rb; private Vector3 defaultPosition; private Quaternion defaultRotation;
public void SetTouchAxis(Vector2 data){ touchAxis = data; }
public void SetTriggerAxis(float data){ triggerAxis = data; }
public void ResetCar(){ transform.position = defaultPosition; transform.rotation = defaultRotation; }
private void Awake(){ rb = GetComponent<Rigidbody>(); defaultPosition = transform.position; defaultRotation = transform.rotation; }
private void FixedUpdate(){ if(isJumping){ touchAxis.x = 0f; }
CalculateSpeed(); Move(); Turn(); Jump(); }
private void CalculateSpeed(){ if(touchAxis.y != 0f){ movementSpeed += (acceleration * touchAxis.y); movementSpeed = Mathf.Clamp(movementSpeed, -maxAcceleration, maxAcceleration); }else{ Decelerate(); } }
private void Decelerate(){ if(movementSpeed > 0){ movementSpeed -= Mathf.Lerp(acceleration, maxAcceleration, 0f); }else if(movementSpeed < 0){ movementSpeed += Mathf.Lerp(acceleration, -maxAcceleration, 0f); }else{ movementSpeed = 0; } }
private void Move(){ Vector3 movement = transform.forward * movementSpeed * Time.deltaTime; rb.MovePosition(rb.position + movement); }
private void Turn(){ float turn = touchAxis.x * rotationSpeed * Time.deltaTime; Quaternion turnRotation = Quaternion.Euler(0f, turn, 0f); rb.MoveRotation(rb.rotation * turnRotation); }
private void Jump(){ if(!isJumping && triggerAxis > 0){ float jumpHeight = (triggerAxis * jumpPower); rb.AddRelativeForce(Vector3.up * jumpHeight); triggerAxis = 0f; } }
private void OnTriggerStay(Collider collider){ isJumping = false; }
private void OnTriggerExit(Collider collider){ isJumping = true; }
} //立钻哥哥:public class RC_Car:MonoBehaviour{}
} //立钻哥哥:namespace VRTK.Examples{} |
###016_Controller_HapticRumble |
++016_Controller_HapticRumble
++++立钻哥哥:Assets/VRTK/LegacyExampleFiles/016_Controller_HapticRumble.unity
++016_Controller_HapticRumble
++++立钻哥哥:做用:手柄震动;
++Sword.cs
++++立钻哥哥:\Assets\VRTK\LegacyExampleFiles\ExampleResources\Scripts\Sword.cs
//立钻哥哥:\Assets\VRTK\LegacyExampleFiles\ExampleResources\Scripts\Sword.cs namespace VRTK.Examples{ using UnityEngine;
public class Sword : VRTK_InteractableObject{ private float impactMagnifier = 120f; private float collisionForce = 0f; private float maxCollisionForce = 4000f; private VRTK_ControllerReference controllerReference;
public float CollisionForce(){ return collisionForece; }
public override void Grabbed(VRTK_InteractGrab grabbingObject){ base.Grabbed(grabbingObject); controllerReference = VRTK_ControllerReference.GetControllerReference(grabbingObject.controllerEvents.gameObject); }
public override void Ungrabbed(VRTK_InteractGrab previousGrabbingObject){ base.Ungrabbed(previousGrabbingObject); controllerReference = null; }
protected override void OnEnable(){ base.OnEnable(); controllerReference = null; interactableRigidbody.collisionDetectionMode = CollisionDetectionMode.Continuous; }
private void OnCollisionEnter(Collision collision){ if(VRTK_ControllerReference.IsValid(controllerReference) && IsGrabbed()){ collisionForce = VRTK_DeviceFinder.GetControllerVelocity(controllerReference).magnitude * impactMagnifier; var hapticStrength = collisionForce / maxCollisionForce; VRTK_ControllerHaptics.TriggerHapticPulse(controllerReference, hapticStrength, 0.5f, 0.01f); }else{ collisionForce = collision.relativeVelocity.magnitude * impactMagnifier; } }
} //立钻哥哥:public class Sword : VRTK_InteractableObject{}
} //立钻哥哥:namespace VRTK.Examples{} |
###017_CameraRig_TouchpadWalking |
++017_CameraRig_TouchpadWalking
++++立钻哥哥:Assets/VRTK/LegacyExampleFiles/017_CameraRig_TouchpadWalking.unity
###018_CameraRig_FramesPerSecondCounter |
++立钻哥哥推荐的拓展学习连接(Link_Url):
立钻哥哥推荐的拓展学习连接(Link_Url) |
++++立钻哥哥Unity 学习空间: http://blog.csdn.net/VRunSoftYanlz/
++++HTC_VIVE开发基础:http://www.javashuo.com/article/p-mhcdmelt-bt.html
++++Oculus杂谈:http://www.javashuo.com/article/p-unmgvyjw-ce.html
++++Oculus安装使用:http://www.javashuo.com/article/p-ulvvimkb-cr.html
++++VRTK杂谈:http://www.javashuo.com/article/p-gsryrkjk-eb.html
++++VRTK快速入门(杂谈):http://www.javashuo.com/article/p-bgvfnmia-cm.html
++++VRTK官方示例(目录):http://www.javashuo.com/article/p-dsnjffvq-ea.html
++++VRTK代码结构(目录):http://www.javashuo.com/article/p-wfilzqyd-es.html
++++VRTK(SceneResources):http://www.javashuo.com/article/p-ryptqvzl-hm.html
++++VR实验:以太网帧的构成:http://www.javashuo.com/article/p-fnfhdcgt-bp.html
++++FrameVR示例V0913:http://www.javashuo.com/article/p-xnlrngai-cw.html
++++Unity5.x用户手册:http://www.javashuo.com/article/p-ufnzpmga-s.html
++++Unity面试题ABC:http://www.javashuo.com/article/p-mwacxwca-gm.html
++++Unity面试题D:http://www.javashuo.com/article/p-wuwcrclr-s.html
++++Unity面试题E:http://www.javashuo.com/article/p-hmabbtmc-ba.html
++++Unity面试题F:http://www.javashuo.com/article/p-olslkfao-cq.html
++++Cocos2dx面试题:http://www.javashuo.com/article/p-daozmsii-cz.html
++++Lua快速入门篇(Xlua拓展):http://www.javashuo.com/article/p-rrszijom-cm.html
++++Lua快速入门篇(XLua教程):http://www.javashuo.com/article/p-pduvmusb-ho.html
++++Lua快速入门篇(基础概述):http://www.javashuo.com/article/p-shernvtt-u.html
++++框架知识点:http://www.javashuo.com/article/p-eufbowgf-u.html
++++游戏框架(UI框架夯实篇):http://www.javashuo.com/article/p-cvemoigb-cu.html
++++游戏框架(初探篇):http://www.javashuo.com/article/p-zfpoilbc-hy.html
++++设计模式简单整理:http://www.javashuo.com/article/p-rngqugib-hg.html
++++专题:设计模式(精华篇):http://www.javashuo.com/article/p-nbohnaya-hw.html
++++U3D小项目参考:https://blog.csdn.net/vrunsoftyanlz/article/details/80141811
++++Unity案例(Vehicle):http://www.javashuo.com/article/p-wxnfscgy-dy.html
++++UML类图:http://www.javashuo.com/article/p-sxberuew-bm.html
++++Unity知识点0001:http://www.javashuo.com/article/p-ryvdxxjr-ep.html
++++Unity知识点0008:http://www.javashuo.com/article/p-kxgstxls-gu.html
++++U3D_Shader编程(第一篇:快速入门篇):http://www.javashuo.com/article/p-kyppgrac-gz.html
++++U3D_Shader编程(第二篇:基础夯实篇):http://www.javashuo.com/article/p-qkyowtli-hv.html
++++Unity引擎基础:http://www.javashuo.com/article/p-beommoeb-ka.html
++++Unity面向组件开发:http://www.javashuo.com/article/p-eigmuvut-dt.html
++++Unity物理系统:http://www.javashuo.com/article/p-nqvvciwv-kd.html
++++Unity2D平台开发:http://www.javashuo.com/article/p-ycaagdtj-hs.html
++++UGUI基础:http://www.javashuo.com/article/p-rukxwckw-mc.html
++++UGUI进阶:http://www.javashuo.com/article/p-wcatruhq-gt.html
++++UGUI综合:http://www.javashuo.com/article/p-dkccmqii-gg.html
++++Unity动画系统基础:http://www.javashuo.com/article/p-mbrdouxy-dq.html
++++Unity动画系统进阶:http://www.javashuo.com/article/p-aqaqpbkh-bp.html
++++Navigation导航系统:http://www.javashuo.com/article/p-dswwllas-t.html
++++Unity特效渲染:http://www.javashuo.com/article/p-ckojjyfj-bp.html
++++Unity数据存储:http://www.javashuo.com/article/p-bvlzynso-m.html
++++Unity中Sqlite数据库:http://www.javashuo.com/article/p-ejutsbxl-ca.html
++++WWW类和协程:http://www.javashuo.com/article/p-dbwmhsav-cy.html
++++Unity网络:http://www.javashuo.com/article/p-sqrlntgh-dw.html
++++C#事件:http://www.javashuo.com/article/p-zmwruvql-gm.html
++++C#委托:http://www.javashuo.com/article/p-uozpymaf-gh.html
++++C#集合:http://www.javashuo.com/article/p-sfqfdqsf-ex.html
++++C#泛型:http://www.javashuo.com/article/p-xrttqngo-ee.html
++++C#接口:http://www.javashuo.com/article/p-vhlfplgv-dm.html
++++C#静态类:https://blog.csdn.net/vrunsoftyanlz/article/details/78630979
++++C#中System.String类:http://www.javashuo.com/article/p-olslkfao-cq.html
++++C#数据类型:http://www.javashuo.com/article/p-hmabbtmc-ba.html
++++Unity3D默认的快捷键:http://www.javashuo.com/article/p-wuwcrclr-s.html
++++游戏相关缩写:http://www.javashuo.com/article/p-mwacxwca-gm.html
++++UnityAPI.Rigidbody刚体:http://www.javashuo.com/article/p-phaztrtw-w.html
++++UnityAPI.Material材质:http://www.javashuo.com/article/p-ntyoqcng-q.html
++++UnityAPI.Android安卓:http://www.javashuo.com/article/p-fyyfgkck-q.html
++++UnityAPI.AndroidJNI安卓JNI:http://www.javashuo.com/article/p-kvxjsnzf-w.html
++++UnityAPI.Transform变换:http://www.javashuo.com/article/p-bfgrrhxl-cq.html
++++UnityAPI.WheelCollider轮碰撞器:http://www.javashuo.com/article/p-smnaoooi-cn.html
++++JSON数据结构:http://www.javashuo.com/article/p-dljbtddn-g.html
++++CocosStudio快速入门:http://www.javashuo.com/article/p-qldbaqqa-v.html
++++Unity企业内训(目录):http://www.javashuo.com/article/p-oefbctlf-mn.html
++++Unity企业内训(第1讲):http://www.javashuo.com/article/p-ehlblkrj-mc.html
++++Unity企业内训(第2讲):http://www.javashuo.com/article/p-tiecmlwc-ma.html
++++Unity企业内训(第3讲):http://www.javashuo.com/article/p-mlpucjnv-ma.html
++++计算机组成原理(教材篇):http://www.javashuo.com/article/p-sejaldpf-kr.html
++++立钻哥哥Unity 学习空间: http://blog.csdn.net/VRunSoftYanlz/
--_--VRunSoft:lovezuanzuan--_--