Skip to content

Commit 4993bdd

Browse files
Stephen HodgsonStephen Hodgson
authored andcommitted
Merge branch 'HTK-master' into HTK-local
2 parents 2762f06 + bd742a6 commit 4993bdd

40 files changed

+617
-333
lines changed

Assets/HoloToolkit/Input/Scripts/Cursor/Cursor.cs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ public enum CursorStateEnum
2323
/// <summary>
2424
/// Not IsHandVisible
2525
/// </summary>
26-
Observe,
26+
Observe,
2727
/// <summary>
2828
/// Not IsHandVisible AND not IsInputSourceDown AND TargetedObject exists
2929
/// </summary>
30-
ObserveHover,
30+
ObserveHover,
3131
/// <summary>
3232
/// IsHandVisible AND not IsInputSourceDown AND TargetedObject is NULL
3333
/// </summary>
@@ -73,10 +73,13 @@ public enum CursorStateEnum
7373
[Tooltip("The distance from the hit surface to place the cursor")]
7474
public float SurfaceCursorDistance = 0.02f;
7575

76+
[Header("Motion")]
77+
[Tooltip("When lerping, use unscaled time. This is useful for games that have a pause mechanism or otherwise adjust the game timescale.")]
78+
public bool UseUnscaledTime = true;
79+
7680
/// <summary>
7781
/// Blend value for surface normal to user facing lerp
7882
/// </summary>
79-
[Header("Motion")]
8083
public float PositionLerpTime = 0.01f;
8184

8285
/// <summary>
@@ -105,7 +108,7 @@ public Vector3 Position
105108
{
106109
get { return transform.position; }
107110
}
108-
111+
109112
public Quaternion Rotation
110113
{
111114
get { return transform.rotation; }
@@ -153,7 +156,7 @@ public bool IsVisible
153156
}
154157
}
155158

156-
#region MonoBehaviour Functions
159+
#region MonoBehaviour Functions
157160

158161
private void Awake()
159162
{
@@ -177,7 +180,7 @@ private void Update()
177180
/// <summary>
178181
/// Override for enable functions
179182
/// </summary>
180-
protected virtual void OnEnable(){}
183+
protected virtual void OnEnable() { }
181184

182185
/// <summary>
183186
/// Override for disable functions
@@ -194,7 +197,7 @@ private void OnDestroy()
194197
UnregisterManagers();
195198
}
196199

197-
#endregion
200+
#endregion
198201

199202
/// <summary>
200203
/// Register to events from the managers the cursor needs.
@@ -302,17 +305,21 @@ protected virtual void UpdateCursorTransform()
302305
}
303306
}
304307

308+
float deltaTime = UseUnscaledTime
309+
? Time.unscaledDeltaTime
310+
: Time.deltaTime;
311+
305312
// Use the lerp times to blend the position to the target position
306-
transform.position = Vector3.Lerp(transform.position, targetPosition, Time.deltaTime / PositionLerpTime);
307-
transform.localScale = Vector3.Lerp(transform.localScale, targetScale, Time.deltaTime / ScaleLerpTime);
308-
transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, Time.deltaTime / RotationLerpTime);
313+
transform.position = Vector3.Lerp(transform.position, targetPosition, deltaTime / PositionLerpTime);
314+
transform.localScale = Vector3.Lerp(transform.localScale, targetScale, deltaTime / ScaleLerpTime);
315+
transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, deltaTime / RotationLerpTime);
309316
}
310317

311318
/// <summary>
312319
/// Updates the visual representation of the cursor.
313320
/// </summary>
314321
public void SetVisiblity(bool visible)
315-
{
322+
{
316323
if (PrimaryCursorVisual != null)
317324
{
318325
PrimaryCursorVisual.gameObject.SetActive(visible);
@@ -414,7 +421,7 @@ public virtual CursorStateEnum CheckCursorState()
414421
{
415422
return CursorStateEnum.Select;
416423
}
417-
else if(cursorState == CursorStateEnum.Select)
424+
else if (cursorState == CursorStateEnum.Select)
418425
{
419426
return CursorStateEnum.Release;
420427
}

Assets/HoloToolkit/Input/Scripts/Cursor/ObjectCursor.cs

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ protected override void OnEnable()
3737
{
3838
ParentTransform = transform;
3939
}
40+
41+
for (int i = 0; i < ParentTransform.childCount; i++)
42+
{
43+
ParentTransform.GetChild(i).gameObject.SetActive(false);
44+
}
45+
4046
base.OnEnable();
4147
}
4248

@@ -48,23 +54,42 @@ protected override void OnEnable()
4854
public override void OnCursorStateChange(CursorStateEnum state)
4955
{
5056
base.OnCursorStateChange(state);
51-
5257
if (state != CursorStateEnum.Contextual)
5358
{
54-
// Hide all children first
55-
for(int i = 0; i < ParentTransform.childCount; i++)
59+
60+
// First, try to find a cursor for the current state
61+
var newActive = new ObjectCursorDatum();
62+
for(int cursorIndex = 0; cursorIndex < CursorStateData.Length; cursorIndex++)
5663
{
57-
ParentTransform.GetChild(i).gameObject.SetActive(false);
64+
ObjectCursorDatum cursor = CursorStateData[cursorIndex];
65+
if (cursor.CursorState == state)
66+
{
67+
newActive = cursor;
68+
break;
69+
}
70+
}
71+
72+
// If no cursor for current state is found, let the last active cursor be
73+
// (any cursor is better than an invisible cursor)
74+
if (newActive.Name == null)
75+
{
76+
return;
5877
}
5978

60-
// Set active any that match the current state
61-
for (int i = 0; i < CursorStateData.Length; i++)
79+
// If we come here, there is a cursor for the new state,
80+
// so de-activate a possible earlier active cursor
81+
for(int cursorIndex = 0; cursorIndex < CursorStateData.Length; cursorIndex++)
6282
{
63-
if (CursorStateData[i].CursorState == state)
83+
ObjectCursorDatum cursor = CursorStateData[cursorIndex];
84+
if (cursor.CursorObject.activeSelf)
6485
{
65-
CursorStateData[i].CursorObject.SetActive(true);
86+
cursor.CursorObject.SetActive(false);
87+
break;
6688
}
6789
}
90+
91+
// ... and set the cursor for the new state active.
92+
newActive.CursorObject.SetActive(true);
6893
}
6994
}
7095
}

Assets/HoloToolkit/Input/Scripts/InputSources/EditorHandsInput.cs

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public EditorHandData(IInputSource inputSource, uint handId)
3939
public bool IsFingerDownPending;
4040
public bool FingerStateChanged;
4141
public float FingerStateUpdateTimer;
42-
public float FingerDownStartTime;
42+
public float FingerDownStartTime;
4343
public readonly InputSourceEventArgs InputSourceArgs;
4444
}
4545

@@ -56,15 +56,15 @@ public EditorHandData(IInputSource inputSource, uint handId)
5656
/// </summary>
5757
private const float FingerPressDelay = 0.07f;
5858

59-
/// <summary>
60-
/// The maximum interval between button down and button up that will result in a clicked event.
61-
/// </summary>
62-
private const float MaxClickDuration = 0.5f;
59+
/// <summary>
60+
/// The maximum interval between button down and button up that will result in a clicked event.
61+
/// </summary>
62+
private const float MaxClickDuration = 0.5f;
6363

64-
/// <summary>
65-
/// Number of fake hands supported in the editor.
66-
/// </summary>
67-
private const int EditorHandsCount = 2;
64+
/// <summary>
65+
/// Number of fake hands supported in the editor.
66+
/// </summary>
67+
private const int EditorHandsCount = 2;
6868

6969
/// <summary>
7070
/// Array containing the hands data for the two fake hands
@@ -205,19 +205,33 @@ private void Update()
205205
/// </summary>
206206
private void UpdateHandData()
207207
{
208+
float time;
209+
float deltaTime;
210+
211+
if (manualHandControl.UseUnscaledTime)
212+
{
213+
time = Time.unscaledTime;
214+
deltaTime = Time.unscaledDeltaTime;
215+
}
216+
else
217+
{
218+
time = Time.time;
219+
deltaTime = Time.deltaTime;
220+
}
221+
208222
if (manualHandControl.LeftHandInView)
209223
{
210224
GetOrAddHandData(0);
211225
currentHands.Add(0);
212226

213-
UpdateHandState(manualHandControl.LeftHandSourceState, editorHandsData[0]);
227+
UpdateHandState(manualHandControl.LeftHandSourceState, editorHandsData[0], deltaTime, time);
214228
}
215229

216230
if (manualHandControl.RightHandInView)
217231
{
218232
GetOrAddHandData(1);
219233
currentHands.Add(1);
220-
UpdateHandState(manualHandControl.RightHandSourceState, editorHandsData[1]);
234+
UpdateHandState(manualHandControl.RightHandSourceState, editorHandsData[1], deltaTime, time);
221235
}
222236
}
223237

@@ -245,7 +259,7 @@ private EditorHandData GetOrAddHandData(uint sourceId)
245259
/// </summary>
246260
/// <param name="handSource">Hand source to use to update the position.</param>
247261
/// <param name="editorHandData">EditorHandData structure to update.</param>
248-
private void UpdateHandState(DebugInteractionSourceState handSource, EditorHandData editorHandData)
262+
private void UpdateHandState(DebugInteractionSourceState handSource, EditorHandData editorHandData, float deltaTime, float time)
249263
{
250264
// Update hand position
251265
Vector3 handPosition;
@@ -266,26 +280,26 @@ private void UpdateHandState(DebugInteractionSourceState handSource, EditorHandD
266280
editorHandData.FingerStateChanged = false;
267281
if (editorHandData.FingerStateUpdateTimer > 0)
268282
{
269-
editorHandData.FingerStateUpdateTimer -= Time.deltaTime;
283+
editorHandData.FingerStateUpdateTimer -= deltaTime;
270284
if (editorHandData.FingerStateUpdateTimer <= 0)
271285
{
272286
editorHandData.IsFingerDown = editorHandData.IsFingerDownPending;
273287
editorHandData.FingerStateChanged = true;
274-
if (editorHandData.IsFingerDown)
275-
{
276-
editorHandData.FingerDownStartTime = Time.time;
277-
}
288+
if (editorHandData.IsFingerDown)
289+
{
290+
editorHandData.FingerDownStartTime = time;
291+
}
278292
}
279293
}
280294

281-
SendHandStateEvents(editorHandData);
295+
SendHandStateEvents(editorHandData, time);
282296
}
283297

284298
/// <summary>
285299
/// Sends the events for hand state changes.
286300
/// </summary>
287301
/// <param name="editorHandData">Hand data for which events should be sent.</param>
288-
private void SendHandStateEvents(EditorHandData editorHandData)
302+
private void SendHandStateEvents(EditorHandData editorHandData, float time)
289303
{
290304
// Hand moved event
291305
if (editorHandData.HandDelta.sqrMagnitude > 0)
@@ -305,12 +319,12 @@ private void SendHandStateEvents(EditorHandData editorHandData)
305319
RaiseSourceUpEvent(editorHandData.InputSourceArgs);
306320

307321
// Also send click event when using this hands replacement input
308-
if (Time.time - editorHandData.FingerDownStartTime < MaxClickDuration)
309-
{
322+
if (time - editorHandData.FingerDownStartTime < MaxClickDuration)
323+
{
310324
// We currently only support single taps in editor
311325
SourceClickEventArgs args = new SourceClickEventArgs(this, editorHandData.HandId, 1);
312-
RaiseSourceClickedEvent(args);
313-
}
326+
RaiseSourceClickedEvent(args);
327+
}
314328
}
315329
}
316330
}

Assets/HoloToolkit/Input/Scripts/InputSources/RawInteractionSourcesInput.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ public SourceData(IInputSource inputSource, uint sourceId)
5252
/// </summary>
5353
private const float SourcePressDelay = 0.07f;
5454

55+
[Tooltip("Use unscaled time. This is useful for games that have a pause mechanism or otherwise adjust the game timescale.")]
56+
public bool UseUnscaledTime = true;
57+
5558
/// <summary>
5659
/// Dictionary linking each source ID to its data.
5760
/// </summary>
@@ -106,7 +109,7 @@ public override bool TryGetOrientation(uint sourceId, out Quaternion orientation
106109
orientation = Quaternion.identity;
107110
return false;
108111
}
109-
112+
110113
private void Update()
111114
{
112115
newSources.Clear();
@@ -180,7 +183,11 @@ private void UpdateSourceState(InteractionSourceState interactionSource, SourceD
180183
sourceData.SourceStateChanged = false;
181184
if (sourceData.SourceStateUpdateTimer >= 0)
182185
{
183-
sourceData.SourceStateUpdateTimer -= Time.deltaTime;
186+
float deltaTime = UseUnscaledTime
187+
? Time.unscaledDeltaTime
188+
: Time.deltaTime;
189+
190+
sourceData.SourceStateUpdateTimer -= deltaTime;
184191
if (sourceData.SourceStateUpdateTimer < 0)
185192
{
186193
sourceData.IsSourceDown = sourceData.IsSourceDownPending;

0 commit comments

Comments
 (0)