I am trying to add support for VR controllers (using VRTK) by making a script similar to the TouchScript bridge script that you provided in this thread here:
http://www.tasharen.com/forum/index.php?topic=4984.msg56678My code:
void OnPointerActivated(object sender, ControllerInteractionEventArgs e)
{
// Start tracking touches
UICamera.GetInputTouchCount = OnGetTouchCount;
UICamera.GetInputTouch = OnGetTouch;
mTouches
.Add(new UICamera
.Touch() {
phase = TouchPhase.Began,
fingerId = 0,
position = HoverPosition,
tapCount = 1
});
}
void OnPointerHover(object sender, DestinationMarkerEventArgs e)
{
for (int index = 0; index < mTouches.size; ++index)
{
UICamera.Touch t = mTouches[index];
if (t.fingerId == 0)
{
var pointInScreenSpace = VRTK_DeviceFinder.HeadsetCamera().GetComponent<Camera>().WorldToScreenPoint(e.destinationPosition);
t
.position = new Vector2
(pointInScreenSpace
.x, pointInScreenSpace
.y); t.phase = TouchPhase.Moved;
HoverPosition = t.position;
break;
}
}
}
void OnPointerClicked()
{
for (int index = 0; index < mTouches.size; ++index)
{
UICamera.Touch t = mTouches[index];
if (t.fingerId == 0)
{
t.phase = TouchPhase.Ended;
t.position = HoverPosition;
break;
}
}
}
void OnPointerDeactivated(object sender, ControllerInteractionEventArgs e)
{
// Stop tracking touches
mTouches.Clear();
UICamera.GetInputTouchCount = null;
UICamera.GetInputTouch = null;
}
int OnGetTouchCount()
{
return mTouches.size;
}
UICamera.Touch OnGetTouch(int index)
{
return mTouches[index];
}
void LateUpdate()
{
int index = 0;
while (index < mTouches.size)
{
UICamera.Touch touch = mTouches[index];
if (touch.phase == TouchPhase.Ended)
{
mTouches.RemoveAt(index);
}
else
{
touch.phase = TouchPhase.Moved;
++index;
}
}
}
1. I have the touchPosition, that is a Camera.WorldToScreenPoint, and use it as touch.position when adding touches using UICamera.GetInputTouch and UICamera.GetInputTouchCount callbacks.
Could you tell me if there is something wrong in how I am adding the Touch events to mTouches and the reason why UICamera is not processing a touch once my TouchEnded touch has been added? Notice that I have changed fingerID of the touches to 0, since there is only 1 pointer I am using for now, would this be an issue?
2. I also tried making my own UICamera and replaced Input.mousePosition with HoverPosition and that did not work either.
3. There is OnCustomInput in UICamera but I could not find any resources on how to use it, could you please tell me how to go about it?