Skip to content

Commit

Permalink
Better Quest Support
Browse files Browse the repository at this point in the history
  • Loading branch information
Yannick committed May 29, 2019
1 parent c259ed7 commit 62a1690
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 62 deletions.
1 change: 1 addition & 0 deletions Assets/Prefabs/Player.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_priority: 0
m_TiledMultiResLevel: 2
--- !u!114 &4537370621232559901
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down
6 changes: 3 additions & 3 deletions Assets/Scripts/Core/Input/DesktopInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public float GetAxis(MWAxis axis)
return 0.0f;
}

public bool GetButton(MWButton button) => Input.GetButton(button.ToString());
public bool GetButtonDown(MWButton button) => Input.GetButtonDown(button.ToString());
public bool GetButtonUp(MWButton button) => Input.GetButtonUp(button.ToString());
public bool Get(MWButton button) => Input.GetButton(button.ToString());
public bool GetDown(MWButton button) => Input.GetButtonDown(button.ToString());
public bool GetUp(MWButton button) => Input.GetButtonUp(button.ToString());
}
}
6 changes: 3 additions & 3 deletions Assets/Scripts/Core/Input/IInputProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public interface IInputProvider
{
bool TryInitialize();
float GetAxis(MWAxis axis);
bool GetButton(MWButton button);
bool GetButtonDown(MWButton button);
bool GetButtonUp(MWButton button);
bool Get(MWButton button);
bool GetDown(MWButton button);
bool GetUp(MWButton button);
}
}
36 changes: 17 additions & 19 deletions Assets/Scripts/Core/Input/InputManager.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using Demonixis.Toolbox.XR;
using System.Collections.Generic;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR;

namespace TESUnity.Inputs
{
Expand Down Expand Up @@ -30,6 +28,16 @@ private static void EnsureStarted()
#if WAVEVR_SDK
InputProviders = new IInputProvider[] { new WaveVRInput() };
#else
#if OCULUS_SDK
if (OVRManager.isHmdPresent)
{
var oculusInput = new OculusInput();
oculusInput.TryInitialize();

InputProviders = new IInputProvider[] { oculusInput };
return;
}
#endif
var providers = new IInputProvider[]
{
new TouchInput(),
Expand All @@ -40,16 +48,6 @@ private static void EnsureStarted()
var list = new List<IInputProvider>();
var touchEnabled = false;



#if UNITY_ANDROID
if (UnityXRDevice.IsOculus)
{
InputProviders = new IInputProvider[] { new OculusInput() };
return;
}
#endif

foreach (var provider in providers)
{
if (provider.TryInitialize())
Expand Down Expand Up @@ -98,9 +96,9 @@ public static bool GetButton(MWButton button)
{
EnsureStarted();

foreach (var provider in InputProviders)
foreach (var input in InputProviders)
{
if (provider.GetButton(button))
if (input.Get(button))
return true;
}

Expand All @@ -111,9 +109,9 @@ public static bool GetButtonUp(MWButton button)
{
EnsureStarted();

foreach (var provider in InputProviders)
foreach (var input in InputProviders)
{
if (provider.GetButtonUp(button))
if (input.GetUp(button))
return true;
}

Expand All @@ -124,9 +122,9 @@ public static bool GetButtonDown(MWButton button)
{
EnsureStarted();

foreach (var provider in InputProviders)
foreach (var input in InputProviders)
{
if (provider.GetButtonDown(button))
if (input.GetDown(button))
return true;
}

Expand Down
62 changes: 39 additions & 23 deletions Assets/Scripts/Core/Input/OculusInput.cs
Original file line number Diff line number Diff line change
@@ -1,62 +1,74 @@
using Demonixis.Toolbox.XR;
using UnityEngine;

namespace TESUnity.Inputs
{
public class OculusInput : IInputProvider
{
#if OCULUS_SDK
public delegate bool GetAxisDelegate(OVRInput.Button virtualMask, OVRInput.Controller controllerMask = OVRInput.Controller.Active);
#endif
private bool m_6DOFControllers = false;

public bool TryInitialize()
{
#if OCULUS_SDK
if (UnityXRDevice.IsOculus)
{
m_6DOFControllers = UnityXRDevice.GetVRHeadsetModel() == VRHeadsetModel.OculusQuest;
return true;
}
#endif
var model = UnityXRDevice.GetVRHeadsetModel();
m_6DOFControllers = model == VRHeadsetModel.OculusQuest;
Debug.Log($"[TESUnity] Oculus Input Initialized. 6DoF:{m_6DOFControllers}");
return true;
#else
return false;
#endif
}

public float GetAxis(MWAxis axis)
{
var result = 0.0f;
#if OCULUS_SDK
var leftValue = OVRInput.Get(OVRInput.Axis2D.PrimaryTouchpad, GetController(false));

if (axis == MWAxis.Vertical)
result = leftValue.y;
else if (axis == MWAxis.Horizontal)
result = leftValue.x;
else if (axis == MWAxis.MouseX)
return OVRInput.Get(OVRInput.Axis2D.PrimaryTouchpad, GetController(true)).x;
if (m_6DOFControllers)
{
var value = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, LeftController);

if (axis == MWAxis.Vertical)
return value.y;
else if (axis == MWAxis.Horizontal)
return value.x;
else if (axis == MWAxis.MouseX)
return OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, RightController).x;
}
else
{
var leftValue = OVRInput.Get(OVRInput.Axis2D.PrimaryTouchpad, LeftController);
if (axis == MWAxis.Vertical)
return leftValue.y;
else if (axis == MWAxis.Horizontal)
return leftValue.x;
}
#endif
return result;
return 0.0f;
}

private bool GetButtonState(GetAxisDelegate inputFunction, MWButton button)
{
#if OCULUS_SDK
if (button == MWButton.Use)
{
return inputFunction(OVRInput.Button.PrimaryIndexTrigger, GetController(true));
return inputFunction(OVRInput.Button.PrimaryIndexTrigger, RightController);
}
else if (button == MWButton.Menu)
{
return inputFunction(OVRInput.Button.Back, GetController(false)) ||
inputFunction(OVRInput.Button.Start, GetController(false));
return inputFunction(OVRInput.Button.Back, LeftController) ||
inputFunction(OVRInput.Button.Start, LeftController);
}
else if (button == MWButton.Jump)
{
inputFunction(OVRInput.Button.One, GetController(false));
inputFunction(OVRInput.Button.One, RightController);
}
#endif
return false;
}

public bool GetButton(MWButton button)
public bool Get(MWButton button)
{
#if OCULUS_SDK
return GetButtonState(OVRInput.Get, button);
Expand All @@ -65,7 +77,7 @@ public bool GetButton(MWButton button)
#endif
}

public bool GetButtonDown(MWButton button)
public bool GetDown(MWButton button)
{
#if OCULUS_SDK
return GetButtonState(OVRInput.GetDown, button);
Expand All @@ -74,7 +86,7 @@ public bool GetButtonDown(MWButton button)
#endif
}

public bool GetButtonUp(MWButton button)
public bool GetUp(MWButton button)
{
#if OCULUS_SDK
return GetButtonState(OVRInput.GetUp, button);
Expand All @@ -84,6 +96,10 @@ public bool GetButtonUp(MWButton button)
}

#if OCULUS_SDK

public OVRInput.Controller LeftController => m_6DOFControllers ? OVRInput.Controller.LTouch : OVRInput.Controller.Remote;
public OVRInput.Controller RightController => m_6DOFControllers ? OVRInput.Controller.RTouch : OVRInput.Controller.Remote;

private OVRInput.Controller GetController(bool left)
{
if (m_6DOFControllers)
Expand Down
6 changes: 3 additions & 3 deletions Assets/Scripts/Core/Input/TouchInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,23 @@ public float GetAxis(MWAxis axis)
return result;
}

public bool GetButton(MWButton button)
public bool Get(MWButton button)
{
if (button == MWButton.Use)
return Input.touchCount > 0 && Input.touches[0].phase == TouchPhase.Moved || Input.touches[0].phase == TouchPhase.Stationary;

return false;
}

public bool GetButtonDown(MWButton button)
public bool GetDown(MWButton button)
{
if (button == MWButton.Use)
return Input.touchCount > 0 && Input.touches[0].phase == TouchPhase.Began;

return false;
}

public bool GetButtonUp(MWButton button)
public bool GetUp(MWButton button)
{
if (button == MWButton.Use)
return Input.touchCount > 0 && Input.touches[0].phase == TouchPhase.Ended;
Expand Down
6 changes: 3 additions & 3 deletions Assets/Scripts/Core/Input/UnityXRInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public float GetAxis(MWAxis axis)
return result;
}

public bool GetButton(MWButton button)
public bool Get(MWButton button)
{
if (m_XRMapping == null)
InitializeMapping();
Expand All @@ -54,7 +54,7 @@ public bool GetButton(MWButton button)
return false;
}

public bool GetButtonDown(MWButton button)
public bool GetDown(MWButton button)
{
if (m_XRMapping == null)
InitializeMapping();
Expand All @@ -68,7 +68,7 @@ public bool GetButtonDown(MWButton button)
return false;
}

public bool GetButtonUp(MWButton button)
public bool GetUp(MWButton button)
{
if (m_XRMapping == null)
InitializeMapping();
Expand Down
6 changes: 3 additions & 3 deletions Assets/Scripts/Core/Input/WaveVRInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public float GetAxis(MWAxis axis)
return 0.0f;
}

public bool GetButton(MWButton button)
public bool Get(MWButton button)
{
#if WAVEVR_SDK
if (button == MWButton.Use)
Expand All @@ -47,7 +47,7 @@ public bool GetButton(MWButton button)
return false;
}

public bool GetButtonDown(MWButton button)
public bool GetDown(MWButton button)
{
#if WAVEVR_SDK
if (button == MWButton.Use)
Expand All @@ -64,7 +64,7 @@ public bool GetButtonDown(MWButton button)
return false;
}

public bool GetButtonUp(MWButton button)
public bool GetUp(MWButton button)
{
#if WAVEVR_SDK
if (button == MWButton.Use)
Expand Down
4 changes: 3 additions & 1 deletion Assets/Scripts/XR/UnityXRDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,14 @@ public override void SetActive(bool active)
OVRManager.tiledMultiResLevel = m_TiledMultiResLevel;
}
#endif

Debug.Log($"[GSPVR] IsOculus: {IsOculus}");
}

public override void SetTrackingSpaceType(TrackingSpaceType type, Transform headTransform, float height)
{
#if UNITY_ANDROID
if (XRManager.Instance.ForceSeatedOnMobile)
if (XRManager.Instance.ForceSeatedOnMobile && GetVRHeadsetModel() == VRHeadsetModel.OculusQuest)
type = TrackingSpaceType.Stationary;
#endif
XRDevice.SetTrackingSpaceType(type);
Expand Down
1 change: 1 addition & 0 deletions Packages/manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"dependencies": {
"com.unity.mobile.android-logcat": "0.2.7-preview",
"com.unity.package-manager-ui": "2.1.2",
"com.unity.postprocessing": "2.2.0",
"com.unity.xr.oculus.android": "1.36.0",
Expand Down
2 changes: 1 addition & 1 deletion ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ PlayerSettings:
m_BuildTargetEnableVuforiaSettings: []
openGLRequireES31: 0
openGLRequireES31AEP: 0
openGLRequireES32: 0
openGLRequireES32: 1
m_TemplateCustomTags: {}
mobileMTRendering:
Android: 1
Expand Down
7 changes: 4 additions & 3 deletions ProjectSettings/QualitySettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ QualitySettings:
skinWeights: 1
textureQuality: 1
anisotropicTextures: 0
antiAliasing: 2
antiAliasing: 4
softParticles: 0
softVegetation: 0
realtimeReflectionProbes: 0
Expand Down Expand Up @@ -217,5 +217,6 @@ QualitySettings:
resolutionScalingFixedDPIFactor: 1
excludedTargetPlatforms: []
m_PerPlatformDefaultQuality:
Android: 0
Standalone: 0
Android: 1
Standalone: 4
Windows Store Apps: 4

0 comments on commit 62a1690

Please sign in to comment.