in Assets/MRTK/SDK/Features/UX/Scripts/Pointers/TeleportPointer.cs [393:512]
public override void OnInputChanged(InputEventData<Vector2> eventData)
{
using (OnInputChangedPerfMarker.Auto())
{
// Don't process input if we've got an active teleport request in progress.
if (isTeleportRequestActive || CoreServices.TeleportSystem == null)
{
return;
}
if (eventData.SourceId == InputSourceParent.SourceId &&
eventData.Handedness == Handedness &&
eventData.MixedRealityInputAction == teleportAction)
{
currentInputPosition = eventData.InputData;
}
if (currentInputPosition.sqrMagnitude > InputThresholdSquared)
{
// Get the angle of the pointer input
float angle = Mathf.Atan2(currentInputPosition.x, currentInputPosition.y) * Mathf.Rad2Deg;
// Offset the angle so it's 'forward' facing
angle += angleOffset;
PointerOrientation = angle;
if (!TeleportRequestRaised)
{
float absoluteAngle = Mathf.Abs(angle);
if (absoluteAngle < teleportActivationAngle)
{
TeleportRequestRaised = true;
CoreServices.TeleportSystem?.RaiseTeleportRequest(this, TeleportHotSpot);
if (pointerAudioSource != null && teleportRequestedClip != null)
{
pointerAudioSource.PlayOneShot(teleportRequestedClip);
}
}
else if (canMove)
{
// wrap the angle value.
if (absoluteAngle > 180f)
{
absoluteAngle = Mathf.Abs(absoluteAngle - 360f);
}
// Calculate the offset rotation angle from the 90 degree mark.
// Half the rotation activation angle amount to make sure the activation angle stays centered at 90.
float offsetRotationAngle = 90f - rotateActivationAngle;
// subtract it from our current angle reading
offsetRotationAngle = absoluteAngle - offsetRotationAngle;
// if it's less than zero, then we don't have activation
if (offsetRotationAngle > 0)
{
// check to make sure we're still under our activation threshold.
if (offsetRotationAngle < 2 * rotateActivationAngle)
{
canMove = false;
// Rotate the camera by the rotation amount. If our angle is positive then rotate in the positive direction, otherwise in the opposite direction.
MixedRealityPlayspace.RotateAround(CameraCache.Main.transform.position, Vector3.up, angle >= 0.0f ? rotationAmount : -rotationAmount);
}
else // We may be trying to strafe backwards.
{
// Calculate the offset rotation angle from the 180 degree mark.
// Half the strafe activation angle to make sure the activation angle stays centered at 180f
float offsetStrafeAngle = 180f - backStrafeActivationAngle;
// subtract it from our current angle reading
offsetStrafeAngle = absoluteAngle - offsetStrafeAngle;
// Check to make sure we're still under our activation threshold.
if (offsetStrafeAngle > 0 && offsetStrafeAngle <= backStrafeActivationAngle)
{
canMove = false;
var height = MixedRealityPlayspace.Position.y;
var newPosition = -CameraCache.Main.transform.forward * strafeAmount + MixedRealityPlayspace.Position;
newPosition.y = height;
MixedRealityPlayspace.Position = newPosition;
}
}
}
}
}
}
else
{
canTeleport = TeleportSurfaceResult == TeleportSurfaceResult.Valid || TeleportSurfaceResult == TeleportSurfaceResult.HotSpot;
if (!canTeleport && !TeleportRequestRaised)
{
// Reset the move flag when the user stops moving the joystick
// but hasn't yet started teleport request.
canMove = true;
}
if (canTeleport)
{
TeleportRequestRaised = false;
if (TeleportSurfaceResult == TeleportSurfaceResult.Valid ||
TeleportSurfaceResult == TeleportSurfaceResult.HotSpot)
{
CoreServices.TeleportSystem?.RaiseTeleportStarted(this, TeleportHotSpot);
if (pointerAudioSource != null && teleportCompletedClip != null)
{
pointerAudioSource.PlayOneShot(teleportCompletedClip);
}
}
}
if (TeleportRequestRaised)
{
TeleportRequestRaised = false;
CoreServices.TeleportSystem?.RaiseTeleportCanceled(this, TeleportHotSpot);
}
}
}
}