Skip to content

Commit 263a383

Browse files
committed
Update PinchInputReader.cs
1 parent aaa2f22 commit 263a383

File tree

1 file changed

+31
-23
lines changed

1 file changed

+31
-23
lines changed

org.mixedrealitytoolkit.input/Readers/PinchInputReader.cs

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class PinchInputReader : MonoBehaviour, IXRInputButtonReader
2929
/// </summary>
3030
private struct FallbackState
3131
{
32-
public bool hasPinchData;
32+
public bool isInProgress;
3333
public bool isPerformed;
3434
public bool wasPerformedThisFrame;
3535
public bool wasCompletedThisFrame;
@@ -167,10 +167,8 @@ public bool ReadIsPerformed()
167167
InputActionPhase phase = action.phase;
168168
return phase == InputActionPhase.Performed || (phase != InputActionPhase.Disabled && action.WasPerformedThisFrame());
169169
}
170-
else
171-
{
172-
return m_fallbackState.isPerformed;
173-
}
170+
171+
return m_fallbackState.isPerformed;
174172
}
175173

176174
/// <inheritdoc />
@@ -180,10 +178,8 @@ public bool ReadWasPerformedThisFrame()
180178
{
181179
return selectAction.action.WasPerformedThisFrame();
182180
}
183-
else
184-
{
185-
return m_fallbackState.wasPerformedThisFrame;
186-
}
181+
182+
return m_fallbackState.wasPerformedThisFrame;
187183
}
188184

189185
/// <inheritdoc />
@@ -193,10 +189,8 @@ public bool ReadWasCompletedThisFrame()
193189
{
194190
return selectAction.action.WasCompletedThisFrame();
195191
}
196-
else
197-
{
198-
return m_fallbackState.wasCompletedThisFrame;
199-
}
192+
193+
return m_fallbackState.wasCompletedThisFrame;
200194
}
201195

202196
/// <inheritdoc />
@@ -206,10 +200,8 @@ public float ReadValue()
206200
{
207201
return selectActionValue.action.ReadValue<float>();
208202
}
209-
else
210-
{
211-
return m_fallbackState.value;
212-
}
203+
204+
return m_fallbackState.value;
213205
}
214206

215207
/// <inheritdoc />
@@ -221,11 +213,9 @@ public bool TryReadValue(out float value)
221213
value = action.ReadValue<float>();
222214
return action.IsInProgress();
223215
}
224-
else
225-
{
226-
value = m_fallbackState.value;
227-
return m_fallbackState.hasPinchData;
228-
}
216+
217+
value = m_fallbackState.value;
218+
return m_fallbackState.isInProgress;
229219
}
230220

231221
#endregion IXRInputButtonReader
@@ -242,6 +232,24 @@ private void UpdatePinchSelection()
242232
{
243233
using (UpdatePinchSelectionPerfMarker.Auto())
244234
{
235+
// This section accounts for one of "select" and "select value" being bound while the other is polyfilled.
236+
// We can use the data from the bound action to synthesize the other better than the hand joint logic will.
237+
if (!m_isSelectPolyfilled && !m_isTrackingStatePolyfilled)
238+
{
239+
m_fallbackState.isInProgress = ReadIsPerformed();
240+
m_fallbackState.value = m_fallbackState.isInProgress ? 1 : 0;
241+
return;
242+
}
243+
else if (!m_isSelectValuePolyfilled && !m_isTrackingStatePolyfilled)
244+
{
245+
bool isPinched = ReadValue() >= (m_fallbackState.isPerformed ? 0.9f : 1.0f);
246+
247+
m_fallbackState.wasPerformedThisFrame = isPinched && !m_fallbackState.isPerformed;
248+
m_fallbackState.wasCompletedThisFrame = !isPinched && m_fallbackState.isPerformed;
249+
m_fallbackState.isPerformed = isPinched;
250+
return;
251+
}
252+
245253
// If we still don't have an aggregator, then don't update selects.
246254
if (XRSubsystemHelpers.HandsAggregator == null)
247255
{
@@ -266,7 +274,7 @@ private void UpdatePinchSelection()
266274
m_fallbackState.wasCompletedThisFrame = !isPinched && m_fallbackState.isPerformed;
267275
m_fallbackState.isPerformed = isPinched;
268276
m_fallbackState.value = pinchAmount;
269-
m_fallbackState.hasPinchData = true;
277+
m_fallbackState.isInProgress = pinchAmount > 0;
270278
}
271279
else
272280
{

0 commit comments

Comments
 (0)