Support for hand tracking

This commit is contained in:
tverona1
2020-05-02 19:29:40 -07:00
parent e13af7dc78
commit ddea5d2acd
16 changed files with 1663 additions and 374 deletions
@@ -58,6 +58,7 @@ namespace QuestAppLauncher
return contentLength <= 0 ? 0 : Mathf.Clamp01((float)this.received / (float)contentLength);
}
[Obsolete]
protected override void ReceiveContentLength(int contentLength)
{
this.contentLength = contentLength;
+6 -6
View File
@@ -38,7 +38,7 @@ namespace QuestAppLauncher
private readonly object stateLock = new object();
// State information
private string name;
private string fileName;
private float progress;
private string errorMessage;
@@ -64,10 +64,10 @@ namespace QuestAppLauncher
switch (this.state)
{
case State.DownloadStart:
this.textGui.text = string.Format("Downloading {0}", this.name);
this.textGui.text = string.Format("Downloading {0}", this.fileName);
break;
case State.DownloadFinish:
this.textGui.text = string.Format("Downloading {0} [100%]", this.name);
this.textGui.text = string.Format("Downloading {0} [100%]", this.fileName);
break;
case State.Checking:
this.textGui.text = string.Format("Checking for updates");
@@ -100,7 +100,7 @@ namespace QuestAppLauncher
this.textGui.text = this.errorMessage;
break;
case State.DownloadProgress:
this.textGui.text = string.Format("Downloading {0} [{1:0}%]", this.name, this.progress * 100);
this.textGui.text = string.Format("Downloading {0} [{1:0}%]", this.fileName, this.progress * 100);
this.state = State.DownloadProgressUpdated;
break;
}
@@ -114,11 +114,11 @@ namespace QuestAppLauncher
}
}
public void OnDownloadStart(string name)
public void OnDownloadStart(string fileName)
{
lock (this.stateLock)
{
this.name = name;
this.fileName = fileName;
this.state = State.DownloadStart;
}
}
+10 -7
View File
@@ -16,9 +16,6 @@ public class ScrollRectColliderMask : MonoBehaviour
// Whether the pointer is within bounds of the scroll rect
private bool isInBounds = true;
private bool isInitialized = false;
private OVRInput.Controller activeController = OVRInput.Controller.None;
// Start is called before the first frame update
void Start()
@@ -29,11 +26,17 @@ public class ScrollRectColliderMask : MonoBehaviour
// Update is called once per frame
void Update()
{
this.activeController = OVRInputHelpers.GetControllerForButton(OVRInput.Button.PrimaryIndexTrigger, this.activeController);
Ray pointer = OVRInputHelpers.GetSelectionRay(this.activeController, this.trackingSpace);
var activeControllerLeft = OVRInputHelpers.GetConnectedControllers(OVRInputHelpers.HandFilter.Left);
Ray pointerLeft;
bool gotRayLeft = OVRInputHelpers.GetSelectionRay(activeControllerLeft, this.trackingSpace, out pointerLeft);
RaycastHit hit;
if (this.boxCollider.Raycast(pointer, out hit, 500))
var activeControllerRight = OVRInputHelpers.GetConnectedControllers(OVRInputHelpers.HandFilter.Right);
Ray pointerRight;
bool gotRayRight = OVRInputHelpers.GetSelectionRay(activeControllerRight, this.trackingSpace, out pointerRight);
RaycastHit hitLeft;
RaycastHit hitRight;
if (gotRayLeft && this.boxCollider.Raycast(pointerLeft, out hitLeft, 500) || gotRayRight && this.boxCollider.Raycast(pointerRight, out hitRight, 500))
{
// We got a hit in the scroll view. Check if we're already within the bounds - if so, do nothing.
if (!isInBounds)
+53 -6
View File
@@ -3,10 +3,11 @@ using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using ControllerSelection;
using System.ComponentModel;
namespace QuestAppLauncher
{
public class ScrollRectOverride : ScrollRect, IMoveHandler, IPointerClickHandler, IScrollHandler
public class ScrollRectOverride : ScrollRect, IMoveHandler, IPointerClickHandler, IScrollHandler, IDragHandler
{
// Scrolling speed multiplier
private const float SpeedMultiplier = 15f;
@@ -33,12 +34,25 @@ namespace QuestAppLauncher
// Whether the pointer is within bounds of the scroll rect
private bool isInBounds = false;
private OVRInput.Controller activeController = OVRInput.Controller.None;
// Parent OVRRawRayCaster
private OVRRawRaycaster parentRawRaycaster = null;
void Start()
{
this.cellHeight = this.transform.GetComponentInChildren<GridLayoutGroup>().cellSize.y;
this.boxCollider = GetComponent<BoxCollider>();
// Find parent OVRRawRayCaster
Transform t = this.gameObject.transform;
while (t.parent != null)
{
parentRawRaycaster = t.parent.GetComponent<OVRRawRaycaster>();
if (parentRawRaycaster != null)
{
break;
}
t = t.parent.transform;
}
}
void Update()
@@ -53,11 +67,17 @@ namespace QuestAppLauncher
// colliders, which will behave as expected.
// If we do not get a hit, it means that we're outside the scroll view - so we disable all the children
// box colliders, which addresses the issue above.
this.activeController = OVRInputHelpers.GetControllerForButton(OVRInput.Button.PrimaryIndexTrigger, this.activeController);
Ray pointer = OVRInputHelpers.GetSelectionRay(this.activeController, this.trackingSpace);
var activeControllerLeft = OVRInputHelpers.GetConnectedControllers(OVRInputHelpers.HandFilter.Left);
Ray pointerLeft;
bool gotRayLeft = OVRInputHelpers.GetSelectionRay(activeControllerLeft, this.trackingSpace, out pointerLeft);
RaycastHit hit;
if (this.boxCollider.Raycast(pointer, out hit, 500))
var activeControllerRight = OVRInputHelpers.GetConnectedControllers(OVRInputHelpers.HandFilter.Right);
Ray pointerRight;
bool gotRayRight = OVRInputHelpers.GetSelectionRay(activeControllerRight, this.trackingSpace, out pointerRight);
RaycastHit hitLeft;
RaycastHit hitRight;
if (gotRayLeft && this.boxCollider.Raycast(pointerLeft, out hitLeft, 500) || gotRayRight && this.boxCollider.Raycast(pointerRight, out hitRight, 500))
{
// We got a hit in the scroll view. Check if we're already within the bounds - if so, do nothing.
if (!isInBounds)
@@ -146,6 +166,32 @@ namespace QuestAppLauncher
public override void OnBeginDrag(PointerEventData eventData)
{
// Only handle dragging if hands are active. Use thumbstick on controllers.
if (!OVRPlugin.GetHandTrackingEnabled())
{
return;
}
if (null != parentRawRaycaster)
{
parentRawRaycaster.OnBeginDrag(eventData);
}
base.OnBeginDrag(eventData);
}
public override void OnEndDrag(PointerEventData eventData)
{
// Only handle dragging if hands are active. Use thumbstick on controllers.
if (!OVRPlugin.GetHandTrackingEnabled())
{
return;
}
if (null != parentRawRaycaster)
{
parentRawRaycaster.OnEndDrag(eventData);
}
base.OnEndDrag(eventData);
}
void IMoveHandler.OnMove(AxisEventData e)
@@ -154,6 +200,7 @@ namespace QuestAppLauncher
void IScrollHandler.OnScroll(PointerEventData eventData)
{
base.OnScroll(eventData);
}
void OnMouseDrag()