Skip to content

Commit 901a827

Browse files
author
lawwong
committed
## Changes for v1.7.0:
* New features - Add notification when new version released on [Github](https://github.com/ViveSoftware/ViveInputUtility-Unity/releases). - Add **VRModule** class to bridge various VR SDK. It currently supports SteamVR plugin, Oculus VR plugin and Unity native VR/XR interface. - **void VRModule.Initialize()**: Create and initilize VRModule manager instance. - **VRModuleActiveEnum VRModule.activeModule**: Returns the activated module. - **IVRModuleDeviceState VRModule.GetCurrentDeviceState(uint deviceIndex)**: Returns the virtual VR device status. - **event NewPosesListener VRModule.onNewPoses**: Invoked after virtual VR device status is updated. - **event DeviceConnectedListener VRModule.onDeviceConnected**: Invoked after virtual VR device is connected/disconnected. - **event ActiveModuleChangedListener VRModule.onActiveModuleChanged**: Invoked when a VR module is activated. - New binding interface using overlay UI. By default, the binding interface can be enabled by pressing RightShift + B in play mode. - ![Binding UI](https://github.com/ViveSoftware/ViveInputUtility-Unity/blob/gh-pages/assets/img/binding_ui_preview_01.png) - ![Binding UI](https://github.com/ViveSoftware/ViveInputUtility-Unity/blob/gh-pages/assets/img/binding_ui_preview_02.png) - ![Binding UI](https://github.com/ViveSoftware/ViveInputUtility-Unity/blob/gh-pages/assets/img/binding_ui_preview_03.png) - Add define symbols - **VIU_PLUGIN**: Defined when Vive Input Utility plugin is imported in the project. - **VIU_STEAMVR**: Defined when SteamVR plugin is imported in the project. - **VIU_OCULUSVR**: Defined when OculusVR plugin (OVRPlugin) is imported in the project. - **VIU_BINDING_INTERFACE_SWITCH**: Define it to let the project be able to switch binding interface by pressing RightShift + B in play mode. - **VIU_EXTERNAL_CAMERA_SWITCH**: Define it to let the project be able to switch external camera quad view by pressing RightShift + M in play mode. - Add new role HandRole.ExternalCamera (Alias for HandRole.Controller3). - By default, it is mapping to the 3rd controller, if 3rd controller not available, then mapping to the first valid generic tracker. - ExternalCameraHook uses mapping as the default tracking target. * New componts - [ViveInputVirtualButton] Use this helper component to combine multiple Vive inputs into one virtual button. * Improvement - [ViveInput] Add more controller buttons, use ViveInput.GetPress(role, buttonEnum) to get device button stat - **System** (Only visible when sendSystemButtonToAllApps option is on) - **Menu** - **MenuTouch** - **Trigger** - **TriggerTouch** - **Pad** - **PadTouch** - **Grip** - **GripTouch** - **CapSenseGrip** - **CapSenseGripTouch** - **AKey** - **AKeyTouch** - **OuterFaceButton** (Alias for Menu) - **OuterFaceButtonTouch** (Alias for MenuTouch) - **InnerFaceButton** (Alias for Grip) - **InnerFaceButtonTouch** (Alias for GripTouch) - [ViveInput] Add controller axis enum, use ViveInput.GetAxis(role, axisEnum) to get device axis value - **PadX** - **PadY** - **Trigger** - **CapSenseGrip** - **IndexCurl** - **MiddleCurl** - **RingCurl** - **PinkyCurl** - [ViveRole] Role mapping/binding mechanism is improved and become more flexible. - Now different devices can bind to same role at the same time. - If a unconnected device is bound to a role, that role can still map to other connected device. - [ViveRole] Obsolete functions that retrieve device status and property, use static API in VRModule instead. - **ViveRole.TryGetDeviceIndexBySerialNumber**: Use VRModule.TryGetDeviceIndex instead. - **ViveRole.GetModelNumber**: Use VRModule.GetCurrentDeviceState(deviceIndex).modelNumber instead - **ViveRole.GetSerialNumber**: Use VRModule.GetCurrentDeviceState(deviceIndex).serialNumber instead - **ViveRole.GetDeviceClass**: Use VRModule.GetCurrentDeviceState(deviceIndex).deviceClass instead - [ViveRoleBindingsHelper] Now will automatically load bindings from "vive_role_bindings.cfg", no need to be in the scene to work. - [RenderModelHook] Add override model and shader option. - [ExternalCameraHook] Now ExternalCameraHook will track the HandRole.ExternalCamera by default. - [ExternalCameraHook] Now will be added into scene automatically if "externalcamera.cfg" exist when start playing, no need to add to scene manually. - [ExternalCameraHook] You can now enable static External Camera quad view (without tracking to a device) if 1. VIU_EXTERNAL_CAMERA_SWITCH symbol is defined. 2. externalcamera.cfg exist. 3. RightShift + M pressed in play mode. - [BasicGrabbable, StickyGrabbable, Draggable] Add unblockable grab/drag option. * Bug fix - [ViveRoleProperty] Fix not handling serialized data right in inspector. - [PoseEaser] Now use unscaled time instead to avoid from being effected by time scale.
1 parent 8f8ef7b commit 901a827

File tree

208 files changed

+29829
-7304
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

208 files changed

+29829
-7304
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
/[Oo]bj/
44
/[Bb]uild/
55
/[Bb]uilds/
6+
/[Pp]ackages/
7+
/.vs/
68

79
ProjectSettings/*
810
!ProjectSettings/EditorSettings.asset

Assets/HTC.UnityPlugin/ColliderEvent/ColliderEventCaster.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
using HTC.UnityPlugin.Utility;
44
using System.Collections.Generic;
5-
using System.Collections.ObjectModel;
65
using UnityEngine;
76
using UnityEngine.EventSystems;
87

@@ -225,8 +224,8 @@ protected virtual void Update()
225224
for (int i = 0, imax = axisEventDataList.Count; i < imax; ++i)
226225
{
227226
var eventData = axisEventDataList[i];
228-
229-
if (!eventData.IsValueChangedThisFrame()) { continue; }
227+
228+
if ((eventData.v4 = eventData.GetDelta()) == Vector4.zero) { continue; }
230229

231230
var handlers = GetAxisHandlers(i);
232231

Assets/HTC.UnityPlugin/ColliderEvent/ColliderEventData.cs

Lines changed: 38 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static TEventCaster GetEventCaster<TEventCaster>(this ColliderEventData e
1818
public static bool TryGetEventCaster<TEventCaster>(this ColliderEventData eventData, out TEventCaster eventCaster) where TEventCaster : MonoBehaviour, IColliderEventCaster
1919
{
2020
eventCaster = null;
21-
21+
2222
if (!(eventData.eventCaster is TEventCaster)) { return false; }
2323

2424
eventCaster = eventData.eventCaster as TEventCaster;
@@ -43,21 +43,29 @@ public ColliderHoverEventData(IColliderEventCaster eventCaster) : base(eventCast
4343

4444
public abstract class ColliderButtonEventData : ColliderEventData
4545
{
46-
public int buttonId;
46+
public enum InputButton
47+
{
48+
Trigger,
49+
PadOrStick,
50+
GripOrHandTrigger,
51+
FunctionKey,
52+
}
53+
4754
public IndexedSet<GameObject> pressEnteredObjects = new IndexedSet<GameObject>();
4855
public IndexedSet<GameObject> draggingHandlers = new IndexedSet<GameObject>();
4956
public IndexedSet<GameObject> clickingHandlers = new IndexedSet<GameObject>();
5057

58+
public InputButton button { get; private set; }
5159
public Vector3 pressPosition { get; set; }
5260
public Quaternion pressRotation { get; set; }
5361

5462
public bool isDragging { get { return draggingHandlers.Count > 0; } }
5563

5664
public bool isPressed { get; set; }
5765

58-
public ColliderButtonEventData(IColliderEventCaster eventCaster, int buttonId = 0) : base(eventCaster)
66+
public ColliderButtonEventData(IColliderEventCaster eventCaster, InputButton button = 0) : base(eventCaster)
5967
{
60-
this.buttonId = buttonId;
68+
this.button = button;
6169
}
6270

6371
public abstract bool GetPress();
@@ -69,69 +77,45 @@ public ColliderButtonEventData(IColliderEventCaster eventCaster, int buttonId =
6977

7078
public abstract class ColliderAxisEventData : ColliderEventData
7179
{
80+
public enum InputAxis
81+
{
82+
Scroll2D,
83+
Trigger1D,
84+
}
85+
7286
public enum Dim
7387
{
74-
d1,
75-
d2,
76-
d3,
77-
d4,
88+
D1,
89+
D2,
90+
D3,
91+
D4,
7892
}
93+
94+
// raw delta values
95+
private float m_x;
96+
private float m_y;
97+
private float m_z;
98+
private float m_w;
7999

80-
public int axisId;
100+
public InputAxis axis { get; private set; }
101+
public Dim dimention { get; private set; }
81102

82-
public bool xUsed = true;
83-
public bool yUsed = true;
84-
public bool zUsed = false;
85-
public bool wUsed = false;
86-
// raw delta values
87-
public float xRaw;
88-
public float yRaw;
89-
public float zRaw;
90-
public float wRaw;
91103
// delta values
92-
public float x { get { return xUsed ? xRaw : 0f; } set { if (xUsed) xRaw = value; } }
93-
public float y { get { return yUsed ? yRaw : 0f; } set { if (yUsed) yRaw = value; } }
94-
public float z { get { return zUsed ? zRaw : 0f; } set { if (zUsed) zRaw = value; } }
95-
public float w { get { return wUsed ? wRaw : 0f; } set { if (wUsed) wRaw = value; } }
104+
public float x { get { return dimention >= Dim.D1 ? m_x : 0f; } set { if (dimention >= Dim.D1) m_x = value; } }
105+
public float y { get { return dimention >= Dim.D2 ? m_y : 0f; } set { if (dimention >= Dim.D2) m_y = value; } }
106+
public float z { get { return dimention >= Dim.D3 ? m_z : 0f; } set { if (dimention >= Dim.D3) m_z = value; } }
107+
public float w { get { return dimention >= Dim.D4 ? m_w : 0f; } set { if (dimention >= Dim.D4) m_w = value; } }
96108

97109
public Vector2 v2 { get { return new Vector2(x, y); } set { x = value.x; y = value.y; } }
98110
public Vector3 v3 { get { return new Vector3(x, y, z); } set { x = value.x; y = value.y; z = value.z; } }
99111
public Vector4 v4 { get { return new Vector4(x, y, z, w); } set { x = value.x; y = value.y; z = value.z; w = value.w; } }
100112

101-
public ColliderAxisEventData(IColliderEventCaster eventCaster, int axisId = 0) : base(eventCaster)
102-
{
103-
this.axisId = axisId;
104-
}
105-
106-
public ColliderAxisEventData(IColliderEventCaster eventCaster, Dim dimention, int axisId = 0) : base(eventCaster)
107-
{
108-
this.axisId = axisId;
109-
SetDimention(dimention);
110-
}
111-
112-
public void SetDimention(Dim dimention)
113-
{
114-
switch (dimention)
115-
{
116-
case Dim.d1: { xUsed = true; yUsed = false; zUsed = false; wUsed = false; break; }
117-
case Dim.d2: { xUsed = true; yUsed = true; zUsed = false; wUsed = false; break; }
118-
case Dim.d3: { xUsed = true; yUsed = true; zUsed = true; wUsed = false; break; }
119-
case Dim.d4: { xUsed = true; yUsed = true; zUsed = true; wUsed = true; break; }
120-
}
121-
}
122-
123-
public bool IsDimention(Dim dimention)
113+
public ColliderAxisEventData(IColliderEventCaster eventCaster, Dim dimention, InputAxis axis = 0) : base(eventCaster)
124114
{
125-
switch (dimention)
126-
{
127-
case Dim.d1: return xUsed && !yUsed && !zUsed && !wUsed;
128-
case Dim.d2: return xUsed && yUsed && !zUsed && !wUsed;
129-
case Dim.d3: return xUsed && yUsed && zUsed && !wUsed;
130-
case Dim.d4: return xUsed && yUsed && zUsed && wUsed;
131-
default: return false;
132-
}
115+
this.axis = axis;
116+
this.dimention = dimention;
133117
}
134118

135-
public abstract bool IsValueChangedThisFrame();
119+
public abstract Vector4 GetDelta();
136120
}
137121
}

Assets/HTC.UnityPlugin/Pointer3D/Pointer3DInputModule.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,10 @@ protected override void OnDisable()
146146
}
147147
}
148148

149-
eventSystem.SetSelectedGameObject(null, GetBaseEventData());
149+
if (eventSystem != null)
150+
{
151+
eventSystem.SetSelectedGameObject(null, GetBaseEventData());
152+
}
150153
}
151154

152155
public static readonly Comparison<RaycastResult> defaultRaycastComparer = RaycastComparer;
@@ -485,7 +488,7 @@ protected void DeselectIfSelectionChanged(GameObject currentOverGo, BaseEventDat
485488
var selectHandlerGO = ExecuteEvents.GetEventHandler<ISelectHandler>(currentOverGo);
486489
// if we have clicked something new, deselect the old thing
487490
// leave 'selection handling' up to the press event though.
488-
if (selectHandlerGO != eventSystem.currentSelectedGameObject)
491+
if (eventSystem != null && selectHandlerGO != eventSystem.currentSelectedGameObject)
489492
{
490493
eventSystem.SetSelectedGameObject(null, pointerEvent);
491494
}

Assets/HTC.UnityPlugin/Pointer3D/Raycaster/Base/BaseFallbackCamRaycaster.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
using System;
44
using UnityEngine;
5+
using UnityEngine.EventSystems;
56

67
namespace HTC.UnityPlugin.Pointer3D
78
{
@@ -57,7 +58,7 @@ public override Camera eventCamera
5758
var go = new GameObject(name + " FallbackCamera");
5859
go.SetActive(false);
5960
// place fallback camera at root to preserve world position
60-
//go.transform.SetParent(transform);
61+
go.transform.SetParent(EventSystem.current.transform, false);
6162
go.transform.localPosition = Vector3.zero;
6263
go.transform.localRotation = Quaternion.identity;
6364
go.transform.localScale = Vector3.one;

Assets/HTC.UnityPlugin/PoseTracker/Base/BasePoseTracker.cs

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//========= Copyright 2016-2017, HTC Corporation. All rights reserved. ===========
22

3-
using System.Collections.Generic;
3+
using HTC.UnityPlugin.Utility;
44
using UnityEngine;
55

66
namespace HTC.UnityPlugin.PoseTracker
@@ -10,50 +10,32 @@ public abstract class BasePoseTracker : MonoBehaviour, IPoseTracker
1010
public Vector3 posOffset;
1111
public Vector3 rotOffset;
1212

13-
private readonly Dictionary<IPoseModifier, LinkedListNode<IPoseModifier>> modifierTable = new Dictionary<IPoseModifier, LinkedListNode<IPoseModifier>>();
14-
private readonly LinkedList<IPoseModifier> modifiers = new LinkedList<IPoseModifier>();
13+
private OrderedIndexedSet<IPoseModifier> modifierSet;
1514

1615
public void AddModifier(IPoseModifier obj)
1716
{
18-
if (obj == null || modifierTable.ContainsKey(obj)) { return; }
17+
if (obj == null) { return; }
1918

20-
var node = modifiers.Last;
21-
if (node == null || node.Value != null)
19+
if (modifierSet == null)
2220
{
23-
node = modifiers.AddFirst(obj);
21+
modifierSet = new OrderedIndexedSet<IPoseModifier>();
22+
modifierSet.Add(obj);
2423
}
25-
else
24+
else if (!modifierSet.Contains(obj))
2625
{
27-
modifiers.Remove(node);
28-
node.Value = obj;
29-
modifiers.AddFirst(node);
30-
}
31-
32-
modifierTable.Add(obj, node);
33-
34-
// sort new modifier node
35-
var priorNode = node;
36-
while (priorNode.Next != null && priorNode.Next.Value != null && priorNode.Next.Value.priority < obj.priority)
37-
{
38-
priorNode = priorNode.Next;
39-
}
40-
41-
if (priorNode != node)
42-
{
43-
modifiers.Remove(node);
44-
modifiers.AddAfter(priorNode, node);
26+
for (int i = modifierSet.Count - 1; i >= 0; --i)
27+
{
28+
if (modifierSet[i].priority <= obj.priority)
29+
{
30+
modifierSet.Insert(i + 1, obj);
31+
}
32+
}
4533
}
4634
}
4735

4836
public bool RemoveModifier(IPoseModifier obj)
4937
{
50-
LinkedListNode<IPoseModifier> node;
51-
if (!modifierTable.TryGetValue(obj, out node)) { return false; }
52-
modifierTable.Remove(obj);
53-
modifiers.Remove(node);
54-
node.Value = null;
55-
modifiers.AddLast(node);
56-
return true;
38+
return modifierSet == null ? false : modifierSet.Remove(obj);
5739
}
5840

5941
protected void TrackPose(Pose pose, Transform origin = null)
@@ -65,10 +47,12 @@ protected void TrackPose(Pose pose, Transform origin = null)
6547

6648
protected void ModifyPose(ref Pose pose, Transform origin)
6749
{
68-
for (var node = modifiers.First; node != null && node.Value != null; node = node.Next)
50+
if (modifierSet == null) { return; }
51+
52+
for (int i = 0, imax = modifierSet.Count; i < imax; ++i)
6953
{
70-
if (!node.Value.enabled) { continue; }
71-
node.Value.ModifyPose(ref pose, origin);
54+
if (!modifierSet[i].enabled) { continue; }
55+
modifierSet[i].ModifyPose(ref pose, origin);
7256
}
7357
}
7458
}

0 commit comments

Comments
 (0)