I'm trying to use the navigation gesture on two different objects in close proximity. What can happen is that as the user is gesturing over one object, their gaze penetrates the other one, and what ends up happening is that focus switches to the other object. But no cancel or completion events are fired for the first. I've also noticed that with a single object, if the gesture is started but then finished off of the object, no callbacks get fired making it impossible to detect whether the gesture was actually completed.
Does anyone have a solution for this? I'm testing with Holographic emulation in Unity 2017.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using HoloToolkit.Unity.InputModule;
[System.Serializable]
public class MyFloatEvent : UnityEvent<float>
{
}
public class DragValue: MonoBehaviour, INavigationHandler, IInputClickHandler
{
public float minValue = 0.5f;
public float maxValue = 2f;
public MyFloatEvent OnValueChanged;
public void OnNavigationStarted(NavigationEventData eventData)
{
Debug.Log(gameObject.name + ": OnNavigationStarted");
}
public void OnNavigationUpdated(NavigationEventData eventData)
{
// Convert [-1,1] -> [minValue,maxValue]
float delta = eventData.CumulativeDelta.y;
float value = Mathf.Lerp(minValue, maxValue, 0.5f * (delta + 1));
// Call handler
if (OnValueChanged != null)
OnValueChanged.Invoke(value);
}
public void OnNavigationCompleted(NavigationEventData eventData)
{
Debug.Log(gameObject.name + ": OnNavigationCompleted");
}
public void OnNavigationCanceled(NavigationEventData eventData)
{
Debug.Log(gameObject.name + ": OnNavigationCanceled");
}
public void OnInputClicked(InputClickedEventData eventData)
{
/*
Debug.Log("got here");
if (OnValueChanged != null)
OnValueChanged.Invoke(0.5f);
*/
}
}
Thank you!