/// Controls the player's movement in virtual reality.
/// </summary>
[RequireComponent(typeof(CharacterController))]
publicclassOVRPlayerController:MonoBehaviour
{
/// <summary>
/// The rate acceleration during movement.
/// </summary>
publicfloatAcceleration=0.1f;
/// <summary>
/// The rate of damping on movement.
/// </summary>
publicfloatDamping=0.3f;
/// <summary>
/// The rate of additional damping when moving sideways or backwards.
/// </summary>
publicfloatBackAndSideDampen=0.5f;
/// <summary>
/// The force applied to the character when jumping.
/// </summary>
publicfloatJumpForce=0.3f;
/// <summary>
/// The rate of rotation when using a gamepad.
/// </summary>
publicfloatRotationAmount=1.5f;
/// <summary>
/// The rate of rotation when using the keyboard.
/// </summary>
publicfloatRotationRatchet=45.0f;
/// <summary>
/// The player will rotate in fixed steps if Snap Rotation is enabled.
/// </summary>
[Tooltip("The player will rotate in fixed steps if Snap Rotation is enabled.")]
publicboolSnapRotation=true;
/// <summary>
/// How many fixed speeds to use with linear movement? 0=linear control
/// </summary>
[Tooltip("How many fixed speeds to use with linear movement? 0=linear control")]
publicintFixedSpeedSteps;
/// <summary>
/// If true, reset the initial yaw of the player controller when the Hmd pose is recentered.
/// </summary>
publicboolHmdResetsY=true;
/// <summary>
/// If true, tracking data from a child OVRCameraRig will update the direction of movement.
/// </summary>
publicboolHmdRotatesY=true;
/// <summary>
/// Modifies the strength of gravity.
/// </summary>
publicfloatGravityModifier=0.379f;
/// <summary>
/// If true, each OVRPlayerController will use the player's physical height.
/// </summary>
publicbooluseProfileData=true;
/// <summary>
/// The CameraHeight is the actual height of the HMD and can be used to adjust the height of the character controller, which will affect the
/// ability of the character to move into areas with a low ceiling.
/// </summary>
[NonSerialized]
publicfloatCameraHeight;
/// <summary>
/// This event is raised after the character controller is moved. This is used by the OVRAvatarLocomotion script to keep the avatar transform synchronized
/// with the OVRPlayerController.
/// </summary>
publiceventAction<Transform>TransformUpdated;
/// <summary>
/// This bool is set to true whenever the player controller has been teleported. It is reset after every frame. Some systems, such as
/// CharacterCameraConstraint, test this boolean in order to disable logic that moves the character controller immediately
/// following the teleport.
/// </summary>
[NonSerialized]// This doesn't need to be visible in the inspector.
publicboolTeleported;
/// <summary>
/// This event is raised immediately after the camera transform has been updated, but before movement is updated.
/// </summary>
publiceventActionCameraUpdated;
/// <summary>
/// This event is raised right before the character controller is actually moved in order to provide other systems the opportunity to
/// move the character controller in response to things other than user input, such as movement of the HMD. See CharacterCameraConstraint.cs
/// for an example of this.
/// </summary>
publiceventActionPreCharacterMove;
/// <summary>
/// When true, user input will be applied to linear movement. Set this to false whenever the player controller needs to ignore input for
/// linear movement.
/// </summary>
publicboolEnableLinearMovement=true;
/// <summary>
/// When true, user input will be applied to rotation. Set this to false whenever the player controller needs to ignore input for rotation.
/// </summary>
publicboolEnableRotation=true;
protectedCharacterControllerController=null;
protectedOVRCameraRigCameraRig=null;
privatefloatMoveScale=1.0f;
privateVector3MoveThrottle=Vector3.zero;
privatefloatFallSpeed=0.0f;
privateOVRPose?InitialPose;
publicfloatInitialYRotation{get;privateset;}
privatefloatMoveScaleMultiplier=1.0f;
privatefloatRotationScaleMultiplier=1.0f;
privateboolSkipMouseRotation=true;// It is rare to want to use mouse movement in VR, so ignore the mouse by default.
privateboolHaltUpdateMovement=false;
privateboolprevHatLeft=false;
privateboolprevHatRight=false;
privatefloatSimulationRate=60f;
privatefloatbuttonRotation=0f;
privateboolReadyToSnapTurn;// Set to true when a snap turn has occurred, code requires one frame of centered thumbstick to enable another snap turn.
voidStart()
{
// Add eye-depth as a camera offset from the player controller