Skip to content

Commit 6b5dfc0

Browse files
lawwonglawwong
authored andcommitted
Insure only one instance is updating OVRInput
1 parent be37e25 commit 6b5dfc0

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

  • Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Misc/OculusVRExtension

Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Misc/OculusVRExtension/VIUOvrAvatar.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ public class VIUOvrAvatar : MonoBehaviour
4242
// if true, manual update OVRInput if OVRManager not found
4343
[SerializeField]
4444
private bool manualUpdateOVRInput = true;
45-
46-
private bool visibilityChanged = true;
45+
private static VIUOvrAvatar updateOvrInputUpdateInstance = null;
4746

4847
public bool isAvatarReady { get; private set; }
4948
public IntPtr sdkAvatar { get; private set; }
@@ -114,7 +113,22 @@ private void Update()
114113

115114
if (ShouldManuallyUpdateOVRInput)
116115
{
117-
OVRInput.Update();
116+
if (updateOvrInputUpdateInstance == this)
117+
{
118+
OVRInput.Update();
119+
}
120+
else if (updateOvrInputUpdateInstance == null)
121+
{
122+
updateOvrInputUpdateInstance = this;
123+
OVRInput.Update();
124+
}
125+
}
126+
else
127+
{
128+
if (updateOvrInputUpdateInstance == this)
129+
{
130+
updateOvrInputUpdateInstance = null;
131+
}
118132
}
119133

120134
if (ovrAvatarDriver != null)
@@ -124,9 +138,17 @@ private void Update()
124138
}
125139
}
126140

141+
private void OnDisable()
142+
{
143+
if (updateOvrInputUpdateInstance == this)
144+
{
145+
updateOvrInputUpdateInstance = null;
146+
}
147+
}
148+
127149
private void FixedUpdate()
128150
{
129-
if (ShouldManuallyUpdateOVRInput)
151+
if (ShouldManuallyUpdateOVRInput && updateOvrInputUpdateInstance == this)
130152
{
131153
OVRInput.FixedUpdate();
132154
}

0 commit comments

Comments
 (0)