Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Commit

Permalink
Allow Digital and SingleAxis input actions for teleport (#217)
Browse files Browse the repository at this point in the history
* Update validator default profile

* Get TeleportAction from system in TeleportPointer

* Prepare TeleportPointer handling for Digital/SingleAxis

* Fix TeleportPointer inspector still reasing obsolete fields

* Implement digital teleport action

* Remove logs

* Implement single axis teleport

* Use > instead of >=

* FInalize and clean up

* Assign default teleport action in SDK

* Bump core dependency
  • Loading branch information
FejZa authored Dec 21, 2020
1 parent 2ac556f commit 62f78f4
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 67 deletions.
13 changes: 1 addition & 12 deletions Editor/UX/Pointers/TeleportPointerInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,36 @@ public class TeleportPointerInspector : LinePointerInspector
{
private readonly GUIContent teleportFoldoutHeader = new GUIContent("Teleport Pointer Settings");

private SerializedProperty teleportAction;
private SerializedProperty inputThreshold;
private SerializedProperty angleOffset;
private SerializedProperty teleportActivationAngle;
private SerializedProperty rotateActivationAngle;
private SerializedProperty rotationAmount;
private SerializedProperty backStrafeActivationAngle;
private SerializedProperty strafeAmount;
private SerializedProperty upDirectionThreshold;
private SerializedProperty lineColorHotSpot;
private SerializedProperty validLayers;
private SerializedProperty invalidLayers;

protected override void OnEnable()
{
DrawBasePointerActions = false;
base.OnEnable();

teleportAction = serializedObject.FindProperty(nameof(teleportAction));
inputThreshold = serializedObject.FindProperty(nameof(inputThreshold));
angleOffset = serializedObject.FindProperty(nameof(angleOffset));
teleportActivationAngle = serializedObject.FindProperty(nameof(teleportActivationAngle));
rotateActivationAngle = serializedObject.FindProperty(nameof(rotateActivationAngle));
rotationAmount = serializedObject.FindProperty(nameof(rotationAmount));
backStrafeActivationAngle = serializedObject.FindProperty(nameof(backStrafeActivationAngle));
strafeAmount = serializedObject.FindProperty(nameof(strafeAmount));
upDirectionThreshold = serializedObject.FindProperty(nameof(upDirectionThreshold));
lineColorHotSpot = serializedObject.FindProperty(nameof(lineColorHotSpot));
validLayers = serializedObject.FindProperty(nameof(validLayers));
invalidLayers = serializedObject.FindProperty(nameof(invalidLayers));
}

public override void OnInspectorGUI()
{
base.OnInspectorGUI();
serializedObject.Update();

if (teleportAction.FoldoutWithBoldLabelPropertyField(teleportFoldoutHeader))
if (inputThreshold.FoldoutWithBoldLabelPropertyField(teleportFoldoutHeader))
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(inputThreshold);
Expand All @@ -60,10 +52,7 @@ public override void OnInspectorGUI()
EditorGUILayout.PropertyField(rotationAmount);
EditorGUILayout.PropertyField(backStrafeActivationAngle);
EditorGUILayout.PropertyField(strafeAmount);
EditorGUILayout.PropertyField(upDirectionThreshold);
EditorGUILayout.PropertyField(lineColorHotSpot);
EditorGUILayout.PropertyField(validLayers);
EditorGUILayout.PropertyField(invalidLayers);
EditorGUI.indentLevel--;
}

Expand Down
9 changes: 2 additions & 7 deletions Prefabs~/UX/Pointers/ParabolicPointer.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ LineRenderer:
m_MotionVectors: 0
m_LightProbeUsage: 0
m_ReflectionProbeUsage: 0
m_RayTracingMode: 0
m_RenderingLayerMask: 4294967295
m_RendererPriority: 0
m_Materials:
Expand All @@ -123,6 +124,7 @@ LineRenderer:
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
Expand Down Expand Up @@ -801,7 +803,6 @@ MonoBehaviour:
rotationAmount: 90
backStrafeActivationAngle: 45
strafeAmount: 0.25
upDirectionThreshold: 0.2
lineColorHotSpot:
serializedVersion: 2
key0: {r: 0, g: 0, b: 1, a: 0}
Expand Down Expand Up @@ -831,12 +832,6 @@ MonoBehaviour:
m_Mode: 0
m_NumColorKeys: 2
m_NumAlphaKeys: 4
validLayers:
serializedVersion: 2
m_Bits: 1
invalidLayers:
serializedVersion: 2
m_Bits: 4
minParabolaVelocity: 5
maxParabolaVelocity: 20
minDistanceModifier: 1
Expand Down
5 changes: 5 additions & 0 deletions Profiles~/Teleport/MixedRealityTeleportSystemProfile.asset
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ MonoBehaviour:
profile: {fileID: 11400000, guid: f3f7a928ca0f70649a77a0f17e7465ff, type: 2}
teleportProvider:
reference:
teleportAction:
profileGuid: 399335ccc89c4d12b79f3539ca7771db
id: 5
description: Teleport Direction
axisConstraint: 4
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ MonoBehaviour:
m_Bits: 4
upDirectionThreshold: 0.2
maxDistance: 10
maxHeightDistance: 10
187 changes: 140 additions & 47 deletions Runtime/Features/UX/Scripts/Pointers/TeleportPointer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using UnityEngine;
using UnityEngine.Serialization;
using XRTK.Definitions.InputSystem;
using XRTK.Definitions.Physics;
using XRTK.EventDatum.Input;
using XRTK.EventDatum.Teleport;
Expand All @@ -17,9 +16,6 @@ namespace XRTK.SDK.UX.Pointers
{
public class TeleportPointer : LinePointer
{
[SerializeField]
private MixedRealityInputAction teleportAction = MixedRealityInputAction.None;

[SerializeField]
[Range(0f, 1f)]
[Tooltip("The threshold amount for joystick input (Dead Zone)")]
Expand Down Expand Up @@ -64,8 +60,8 @@ protected Gradient LineColorHotSpot
set => lineColorHotSpot = value;
}

private Vector2 currentInputPosition = Vector2.zero;

private bool currentDigitalInputState = false;
private Vector2 currentDualAxisInputPosition = Vector2.zero;
private bool teleportEnabled = false;

private bool canTeleport = false;
Expand Down Expand Up @@ -212,24 +208,156 @@ public override void OnPostRaycast()

#region IMixedRealityInputHandler Implementation

/// <inheritdoc />
public override void OnInputDown(InputEventData eventData)
{
// Don't process input if we've got an active teleport request in progress.
if (eventData.used || IsTeleportRequestActive || !IsTeleportSystemEnabled)
{
return;
}

if (eventData.SourceId == InputSourceParent.SourceId &&
eventData.Handedness == Handedness &&
eventData.MixedRealityInputAction == MixedRealityToolkit.TeleportSystem.TeleportAction)
{
eventData.Use();
ProcessDigitalTeleportInput(true);
}
}

/// <inheritdoc />
public override void OnInputUp(InputEventData eventData)
{
if (eventData.SourceId == InputSourceParent.SourceId &&
eventData.Handedness == Handedness &&
eventData.MixedRealityInputAction == MixedRealityToolkit.TeleportSystem.TeleportAction)
{
eventData.Use();
ProcessDigitalTeleportInput(false);
}
}

/// <inheritdoc />
public override void OnInputChanged(InputEventData<float> eventData)
{
// Don't process input if we've got an active teleport request in progress.
if (eventData.used || IsTeleportRequestActive || !IsTeleportSystemEnabled)
{
return;
}

if (eventData.SourceId == InputSourceParent.SourceId &&
eventData.Handedness == Handedness &&
eventData.MixedRealityInputAction == MixedRealityToolkit.TeleportSystem.TeleportAction)
{
eventData.Use();
ProcessSingleAxisTeleportInput(eventData);
}
}

/// <inheritdoc />
public override void OnInputChanged(InputEventData<Vector2> eventData)
{
// Don't process input if we've got an active teleport request in progress.
if (IsTeleportRequestActive || !IsTeleportSystemEnabled) { return; }
if (eventData.used || IsTeleportRequestActive || !IsTeleportSystemEnabled)
{
return;
}

if (eventData.SourceId == InputSourceParent.SourceId &&
eventData.Handedness == Handedness &&
eventData.MixedRealityInputAction == teleportAction)
eventData.MixedRealityInputAction == MixedRealityToolkit.TeleportSystem.TeleportAction)
{
eventData.Use();
ProcessDualAxisTeleportInput(eventData);
}
}

#endregion IMixedRealityInputHandler Implementation

#region IMixedRealityTeleportHandler Implementation

/// <inheritdoc />
public override void OnTeleportRequest(TeleportEventData eventData)
{
// Only turn off the pointer if we're not the one sending the request
if (eventData.Pointer.PointerId == PointerId)
{
IsTeleportRequestActive = false;
}
else
{
IsTeleportRequestActive = true;
BaseCursor?.SetVisibility(false);
}
}

/// <inheritdoc />
public override void OnTeleportCompleted(TeleportEventData eventData)
{
IsTeleportRequestActive = false;
BaseCursor?.SetVisibility(false);
}

/// <inheritdoc />
public override void OnTeleportCanceled(TeleportEventData eventData)
{
IsTeleportRequestActive = false;
BaseCursor?.SetVisibility(false);
}

#endregion IMixedRealityTeleportHandler Implementation

private void ProcessDigitalTeleportInput(bool isPressed)
{
currentDigitalInputState = isPressed;

if (currentDigitalInputState && !teleportEnabled)
{
teleportEnabled = true;
MixedRealityToolkit.TeleportSystem?.RaiseTeleportRequest(this, TeleportHotSpot);
}
else if (!currentDigitalInputState)
{
currentInputPosition = eventData.InputData;
var canTeleport = false;

if (teleportEnabled &&
TeleportValidationResult == TeleportValidationResult.Valid ||
TeleportValidationResult == TeleportValidationResult.HotSpot)
{
canTeleport = true;
}

if (canTeleport)
{
teleportEnabled = false;

if (TeleportValidationResult == TeleportValidationResult.Valid ||
TeleportValidationResult == TeleportValidationResult.HotSpot)
{
MixedRealityToolkit.TeleportSystem?.RaiseTeleportStarted(this, TeleportHotSpot);
}
}
else if (teleportEnabled)
{
teleportEnabled = false;
MixedRealityToolkit.TeleportSystem?.RaiseTeleportCanceled(this, TeleportHotSpot);
}
}
}

private void ProcessSingleAxisTeleportInput(InputEventData<float> eventData) => ProcessDigitalTeleportInput(eventData.InputData > inputThreshold);

private void ProcessDualAxisTeleportInput(InputEventData<Vector2> eventData)
{
currentDualAxisInputPosition = eventData.InputData;

if (Mathf.Abs(currentInputPosition.y) > inputThreshold ||
Mathf.Abs(currentInputPosition.x) > inputThreshold)
if (Mathf.Abs(currentDualAxisInputPosition.y) > inputThreshold ||
Mathf.Abs(currentDualAxisInputPosition.x) > inputThreshold)
{
// Get the angle of the pointer input
float angle = Mathf.Atan2(currentInputPosition.x, currentInputPosition.y) * Mathf.Rad2Deg;
float angle = Mathf.Atan2(currentDualAxisInputPosition.x, currentDualAxisInputPosition.y) * Mathf.Rad2Deg;

// Offset the angle so it's 'forward' facing
angle += angleOffset;
Expand Down Expand Up @@ -333,40 +461,5 @@ public override void OnInputChanged(InputEventData<Vector2> eventData)
canTeleport = true;
}
}

#endregion IMixedRealityInputHandler Implementation

#region IMixedRealityTeleportHandler Implementation

/// <inheritdoc />
public override void OnTeleportRequest(TeleportEventData eventData)
{
// Only turn off the pointer if we're not the one sending the request
if (eventData.Pointer.PointerId == PointerId)
{
IsTeleportRequestActive = false;
}
else
{
IsTeleportRequestActive = true;
BaseCursor?.SetVisibility(false);
}
}

/// <inheritdoc />
public override void OnTeleportCompleted(TeleportEventData eventData)
{
IsTeleportRequestActive = false;
BaseCursor?.SetVisibility(false);
}

/// <inheritdoc />
public override void OnTeleportCanceled(TeleportEventData eventData)
{
IsTeleportRequestActive = false;
BaseCursor?.SetVisibility(false);
}

#endregion IMixedRealityTeleportHandler Implementation
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"src": "Assets/XRTK.Core",
"author": "XRTK Team (https://github.com/XRTK)",
"dependencies": {
"com.xrtk.core": "0.2.0-preview.171",
"com.xrtk.core": "0.2.0-preview.172",
"com.unity.textmeshpro": "2.1.3"
},
"profiles": [
Expand Down

0 comments on commit 62f78f4

Please sign in to comment.