VRTK官方示例 |
版本 |
作者 |
参与者 |
完成日期 |
备注 |
VRTK_LegacyExample_V01_1.0 |
严立钻 |
|
2018.10.05 |
|
|
|
|
|
|
#《VRTK官方示例》发布说明:
++++“VRTK官方示例”,VRTK作为立钻哥哥2018年度重点打造的技术突破点,所以对VRTK的各种尝试,也产生了各种对VRTK的研究剖析,这里我们对官方示例进行剖析;
++++“VRTK官方示例”,定位是初级阶段的探索,通过剖析学习官方示例,达到熟悉VRTK的应用;
#《VRTK官方示例》目录:
++++00、立钻哥哥带您VRTK官方示例
++++01、001_CameraRig_VRPlayArea
++++02、002_Controller_Events
++++03、003_Controller_SimplePointer
++++04、004_CameraRig_BasicTeleport
++++05、005_Controller_BasicObjectGrabbing
++++06、006_Controller_UsingADoor
++++07、007_CameraRig_HeightAdjustTeleport
++++08、008_Controller_UsingAGrabbedObject
++++09、009_Controller_BezierPointer
++++10、010_CameraRig_TerrainTeleporting
++++11、011_Camera_HeadSetCollisionFading
++++12、012_Controller_PointerWithAreaCollision
++++13、013_Controller_UsingAndGrabbingMultipleObjects
++++14、014_Controller_SnappingObjectsOnGrab
++++15、015_Controller_TouchpadAxisControl
++++16、016_Controller_HapticRumble
++++17、017_CameraRig_TouchpadWalking
++++18、018_CameraRig_FramesPerSecondCounter
++++19、019_Controller_InteractingWithPointer
++++20、020_CameraRig_MeshTeleporting
++++21、021_Controller_GrabbingObjectsWithJoints
++++22、022_Controller_CustomBezierPointer
++++23、023_Controller_ChildOfControllerOnGrab
++++24、024_CameraRig_ExcludeTeleportLocations
++++25、025_Controls_Overview
++++26、026_Controller_ForceHoldObject
++++27、027_CameraRig_TeleportByModelVillage
++++28、028_CameraRig_RoomExtender
++++29、029_Controller_Tooltips
++++30、030_Controls_RadialTouchpadMenu
++++31、031_CameraRig_HeadsetGazePointer
++++32、032_Controller_CustomControllerModel
++++33、033_CameraRig_TeleportingInNavMesh
++++34、034_Controls_InteractingWithUnityUI
++++35、035_Controller_OpacityAndHighlighting
++++36、036_Controller_CustomCompoundPointer
++++37、037_CameraRig_ClimbingFalling
++++38、038_CameraRig_DashTeleport
++++39、039_CameraRig_AdaptiveQuality
++++40、040_Controls_PanelMenu
++++41、041_Controller_ObjectSnappingToDropZones
++++42、042_CameraRig_MoveInPlace
++++43、043_Controller_SecondaryControllerActions
++++44、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开发基础:https://blog.csdn.net/VRunSoftYanlz/article/details/81989970
++++Oculus杂谈:https://blog.csdn.net/VRunSoftYanlz/article/details/82469850
++++Oculus安装使用:https://blog.csdn.net/VRunSoftYanlz/article/details/82718982
++++VRTK杂谈:https://blog.csdn.net/VRunSoftYanlz/article/details/82562993
++++VRTK快速入门(杂谈):https://blog.csdn.net/VRunSoftYanlz/article/details/82955267
++++VRTK官方示例(目录):https://blog.csdn.net/VRunSoftYanlz/article/details/82955410
++++VRTK代码结构(目录):https://blog.csdn.net/VRunSoftYanlz/article/details/82780085
++++VRTK(SceneResources):https://blog.csdn.net/VRunSoftYanlz/article/details/82795400
++++VR实验:以太网帧的构成:https://blog.csdn.net/VRunSoftYanlz/article/details/82598140
++++FrameVR示例V0913:https://blog.csdn.net/VRunSoftYanlz/article/details/82808498
++++Unity5.x用户手册:https://blog.csdn.net/VRunSoftYanlz/article/details/81712741
++++Unity面试题ABC:https://blog.csdn.net/vrunsoftyanlz/article/details/78630687
++++Unity面试题D:https://blog.csdn.net/VRunSoftYanlz/article/details/78630838
++++Unity面试题E:https://blog.csdn.net/vrunsoftyanlz/article/details/78630913
++++Unity面试题F:https://blog.csdn.net/VRunSoftYanlz/article/details/78630945
++++Cocos2dx面试题:https://blog.csdn.net/VRunSoftYanlz/article/details/78630967
++++Lua快速入门篇(Xlua拓展):https://blog.csdn.net/VRunSoftYanlz/article/details/81173818
++++Lua快速入门篇(XLua教程):https://blog.csdn.net/VRunSoftYanlz/article/details/81141502
++++Lua快速入门篇(基础概述):https://blog.csdn.net/VRunSoftYanlz/article/details/81041359
++++框架知识点:https://blog.csdn.net/VRunSoftYanlz/article/details/80862879
++++游戏框架(UI框架夯实篇):https://blog.csdn.net/vrunsoftyanlz/article/details/80781140
++++游戏框架(初探篇):https://blog.csdn.net/VRunSoftYanlz/article/details/80630325
++++设计模式简单整理:https://blog.csdn.net/vrunsoftyanlz/article/details/79839641
++++专题:设计模式(精华篇):https://blog.csdn.net/VRunSoftYanlz/article/details/81322678
++++U3D小项目参考:https://blog.csdn.net/vrunsoftyanlz/article/details/80141811
++++Unity案例(Vehicle):https://blog.csdn.net/VRunSoftYanlz/article/details/82355876
++++UML类图:https://blog.csdn.net/vrunsoftyanlz/article/details/80289461
++++Unity知识点0001:https://blog.csdn.net/vrunsoftyanlz/article/details/80302012
++++Unity知识点0008:https://blog.csdn.net/VRunSoftYanlz/article/details/81153606
++++U3D_Shader编程(第一篇:快速入门篇):https://blog.csdn.net/vrunsoftyanlz/article/details/80372071
++++U3D_Shader编程(第二篇:基础夯实篇):https://blog.csdn.net/vrunsoftyanlz/article/details/80372628
++++Unity引擎基础:https://blog.csdn.net/vrunsoftyanlz/article/details/78881685
++++Unity面向组件开发:https://blog.csdn.net/vrunsoftyanlz/article/details/78881752
++++Unity物理系统:https://blog.csdn.net/vrunsoftyanlz/article/details/78881879
++++Unity2D平台开发:https://blog.csdn.net/vrunsoftyanlz/article/details/78882034
++++UGUI基础:https://blog.csdn.net/vrunsoftyanlz/article/details/78884693
++++UGUI进阶:https://blog.csdn.net/vrunsoftyanlz/article/details/78884882
++++UGUI综合:https://blog.csdn.net/vrunsoftyanlz/article/details/78885013
++++Unity动画系统基础:https://blog.csdn.net/vrunsoftyanlz/article/details/78886068
++++Unity动画系统进阶:https://blog.csdn.net/vrunsoftyanlz/article/details/78886198
++++Navigation导航系统:https://blog.csdn.net/vrunsoftyanlz/article/details/78886281
++++Unity特效渲染:https://blog.csdn.net/vrunsoftyanlz/article/details/78886403
++++Unity数据存储:https://blog.csdn.net/vrunsoftyanlz/article/details/79251273
++++Unity中Sqlite数据库:https://blog.csdn.net/vrunsoftyanlz/article/details/79254162
++++WWW类和协程:https://blog.csdn.net/vrunsoftyanlz/article/details/79254559
++++Unity网络:https://blog.csdn.net/vrunsoftyanlz/article/details/79254902
++++C#事件:https://blog.csdn.net/vrunsoftyanlz/article/details/78631267
++++C#委托:https://blog.csdn.net/vrunsoftyanlz/article/details/78631183
++++C#集合:https://blog.csdn.net/vrunsoftyanlz/article/details/78631175
++++C#泛型:https://blog.csdn.net/vrunsoftyanlz/article/details/78631141
++++C#接口:https://blog.csdn.net/vrunsoftyanlz/article/details/78631122
++++C#静态类:https://blog.csdn.net/vrunsoftyanlz/article/details/78630979
++++C#中System.String类:https://blog.csdn.net/vrunsoftyanlz/article/details/78630945
++++C#数据类型:https://blog.csdn.net/vrunsoftyanlz/article/details/78630913
++++Unity3D默认的快捷键:https://blog.csdn.net/vrunsoftyanlz/article/details/78630838
++++游戏相关缩写:https://blog.csdn.net/vrunsoftyanlz/article/details/78630687
++++UnityAPI.Rigidbody刚体:https://blog.csdn.net/VRunSoftYanlz/article/details/81784053
++++UnityAPI.Material材质:https://blog.csdn.net/VRunSoftYanlz/article/details/81814303
++++UnityAPI.Android安卓:https://blog.csdn.net/VRunSoftYanlz/article/details/81843193
++++UnityAPI.AndroidJNI安卓JNI:https://blog.csdn.net/VRunSoftYanlz/article/details/81879345
++++UnityAPI.Transform变换:https://blog.csdn.net/VRunSoftYanlz/article/details/81916293
++++UnityAPI.WheelCollider轮碰撞器:https://blog.csdn.net/VRunSoftYanlz/article/details/82356217
++++JSON数据结构:https://blog.csdn.net/VRunSoftYanlz/article/details/82026644
++++CocosStudio快速入门:https://blog.csdn.net/VRunSoftYanlz/article/details/82356839
++++Unity企业内训(目录):https://blog.csdn.net/VRunSoftYanlz/article/details/82634668
++++Unity企业内训(第1讲):https://blog.csdn.net/VRunSoftYanlz/article/details/82634733
++++Unity企业内训(第2讲):https://blog.csdn.net/VRunSoftYanlz/article/details/82861180
++++Unity企业内训(第3讲):https://blog.csdn.net/VRunSoftYanlz/article/details/82927699
++++计算机组成原理(教材篇):https://blog.csdn.net/VRunSoftYanlz/article/details/82719129
++++立钻哥哥Unity 学习空间: http://blog.csdn.net/VRunSoftYanlz/
--_--VRunSoft:lovezuanzuan--_--