Skip to content

Commit 491169f

Browse files
authored
Merge pull request #62 from ExtendRealityLtd/feat/disable-delay
feat(SpatialTarget): add option to delay the auto deselect on activate
2 parents a55a135 + e3e19c0 commit 491169f

File tree

6 files changed

+104
-15
lines changed

6 files changed

+104
-15
lines changed

Documentation/API/SpatialTarget.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ A target in a spatial location that can react to given SurfaceData.
1919
* [Properties]
2020
* [ActivatingDispatcher]
2121
* [ApplySelectedTargetProperties]
22+
* [DeactivateDelay]
2223
* [DeactivateOtherSpatialTargetsOnActivated]
2324
* [DeactivateSelfOnActivated]
2425
* [ExitAllHoveringOnActivated]
@@ -34,6 +35,7 @@ A target in a spatial location that can react to given SurfaceData.
3435
* [CreateHoverPayload(SurfaceData)]
3536
* [CreateSelectedPayload(SurfaceData)]
3637
* [Deselect(Boolean)]
38+
* [DoDeselect()]
3739
* [DoDeselect(Boolean)]
3840
* [DoEnter(SurfaceData)]
3941
* [DoExit(SurfaceData)]
@@ -166,6 +168,16 @@ The Transform properties to apply the selected target overrides on.
166168
public TransformProperties ApplySelectedTargetProperties { get; set; }
167169
```
168170

171+
#### DeactivateDelay
172+
173+
The delay duration to wait before deactivating.
174+
175+
##### Declaration
176+
177+
```
178+
public float DeactivateDelay { get; set; }
179+
```
180+
169181
#### DeactivateOtherSpatialTargetsOnActivated
170182

171183
Deactivates any other [SpatialTarget] connected to the same [SpatialTargetDispatcher] when this [SpatialTarget] is activated.
@@ -324,7 +336,7 @@ protected virtual SurfaceData CreateSelectedPayload(SurfaceData data)
324336

325337
#### Deselect(Boolean)
326338

327-
Deselects this [SpatialTarget] if it is in a selected state.
339+
De-selects this [SpatialTarget] if it is in a selected state.
328340

329341
##### Declaration
330342

@@ -342,16 +354,26 @@ public virtual bool Deselect(bool keepInActivatingDispatcher = false)
342354

343355
| Type | Description |
344356
| --- | --- |
345-
| System.Boolean | Whether the deselect was successful. |
357+
| System.Boolean | Whether the de-select was successful. |
358+
359+
#### DoDeselect()
360+
361+
De-selects this [SpatialTarget] if it is in a selected state.
362+
363+
##### Declaration
364+
365+
```
366+
public virtual void DoDeselect()
367+
```
346368

347369
#### DoDeselect(Boolean)
348370

349-
Deselects this [SpatialTarget] if it is in a selected state.
371+
De-selects this [SpatialTarget] if it is in a selected state.
350372

351373
##### Declaration
352374

353375
```
354-
public virtual void DoDeselect(bool keepInActivatingDispatcher = false)
376+
public virtual void DoDeselect(bool keepInActivatingDispatcher)
355377
```
356378

357379
##### Parameters
@@ -563,6 +585,7 @@ public virtual bool Select(SpatialTargetDispatcher dispatcher, SurfaceData data)
563585
[Properties]: #Properties
564586
[ActivatingDispatcher]: #ActivatingDispatcher
565587
[ApplySelectedTargetProperties]: #ApplySelectedTargetProperties
588+
[DeactivateDelay]: #DeactivateDelay
566589
[DeactivateOtherSpatialTargetsOnActivated]: #DeactivateOtherSpatialTargetsOnActivated
567590
[DeactivateSelfOnActivated]: #DeactivateSelfOnActivated
568591
[ExitAllHoveringOnActivated]: #ExitAllHoveringOnActivated
@@ -578,6 +601,7 @@ public virtual bool Select(SpatialTargetDispatcher dispatcher, SurfaceData data)
578601
[CreateHoverPayload(SurfaceData)]: #CreateHoverPayloadSurfaceData
579602
[CreateSelectedPayload(SurfaceData)]: #CreateSelectedPayloadSurfaceData
580603
[Deselect(Boolean)]: #DeselectBoolean
604+
[DoDeselect()]: #DoDeselect
581605
[DoDeselect(Boolean)]: #DoDeselectBoolean
582606
[DoEnter(SurfaceData)]: #DoEnterSurfaceData
583607
[DoExit(SurfaceData)]: #DoExitSurfaceData

Documentation/API/SpatialTargetFacade.ActivationActions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ public enum ActivationActions
2727
| Name | Description |
2828
| --- | --- |
2929
| ClearHoveringState | Clears any existing hover state on this target. |
30-
| DeselectOtherTargets | Deselects any other activated targets associated with the calling dispatcher. |
31-
| DeselectSelf | Deselects this target upon activating this target. |
30+
| DeselectOtherTargets | De-selects any other activated targets associated with the calling dispatcher. |
31+
| DeselectSelf | De-selects this target upon activating this target. |
3232
| DisableCollisionsOnActivate | Prevents the pointer from continuing to collide with the target when it is activated. |
3333
| HideActiveState | Hides the target active visual state. |
3434

Documentation/API/SpatialTargetFacade.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The public interface into the SpatialTarget Prefab.
1818
* [ActionsOnActivate]
1919
* [ActionsOnHover]
2020
* [Configuration]
21+
* [DeselectSelfDelay]
2122
* [IsEnabled]
2223
* [SourceValidity]
2324
* [UseSourcePointOverride]
@@ -26,6 +27,7 @@ The public interface into the SpatialTarget Prefab.
2627
* [Deselect(Boolean)]
2728
* [OnAfterActionOnHoverChange()]
2829
* [OnAfterActionOnSelectChange()]
30+
* [OnAfterDeselectSelfDelayChange()]
2931
* [OnAfterIsEnabledChange()]
3032
* [OnAfterSourceValidityChange()]
3133
* [OnAfterUseSourcePointOverrideChange()]
@@ -142,6 +144,16 @@ The linked Internal Setup.
142144
public SpatialTargetConfigurator Configuration { get; protected set; }
143145
```
144146

147+
#### DeselectSelfDelay
148+
149+
The amount of time to delay de-selecting this Spatial Target after it has been activated if the [ActionsOnActivate] [DeselectSelf] is enabled.
150+
151+
##### Declaration
152+
153+
```
154+
public float DeselectSelfDelay { get; set; }
155+
```
156+
145157
#### IsEnabled
146158

147159
Whether the [SpatialTargetFacade] is in the enabled state.
@@ -186,7 +198,7 @@ public bool UseTargetOverride { get; set; }
186198

187199
#### Deselect(Boolean)
188200

189-
Deselects the containing [SpatialTarget] if it is in a selected state.
201+
De-selects the containing [SpatialTarget] if it is in a selected state.
190202

191203
##### Declaration
192204

@@ -220,6 +232,16 @@ Called after [ActionsOnActivate] has been changed.
220232
protected virtual void OnAfterActionOnSelectChange()
221233
```
222234

235+
#### OnAfterDeselectSelfDelayChange()
236+
237+
Called after [DeselectSelfDelay] has been changed.
238+
239+
##### Declaration
240+
241+
```
242+
protected virtual void OnAfterDeselectSelfDelayChange()
243+
```
244+
223245
#### OnAfterIsEnabledChange()
224246

225247
Called after [IsEnabled] has been changed.
@@ -265,10 +287,13 @@ protected virtual void OnAfterUseTargetOverrideChange()
265287
[SpatialTargetFacade.ActivationActions]: SpatialTargetFacade.ActivationActions.md
266288
[SpatialTargetFacade.HoverActions]: SpatialTargetFacade.HoverActions.md
267289
[SpatialTargetConfigurator]: SpatialTargetConfigurator.md
290+
[ActionsOnActivate]: SpatialTargetFacade.md#ActionsOnActivate
291+
[DeselectSelf]: SpatialTargetFacade.ActivationActions.md#ActivationActions_DeselectSelf
268292
[SpatialTargetFacade]: SpatialTargetFacade.md
269293
[SpatialTarget]: SpatialTarget.md
270294
[ActionsOnHover]: SpatialTargetFacade.md#ActionsOnHover
271295
[ActionsOnActivate]: SpatialTargetFacade.md#ActionsOnActivate
296+
[DeselectSelfDelay]: SpatialTargetFacade.md#DeselectSelfDelay
272297
[IsEnabled]: SpatialTargetFacade.md#IsEnabled
273298
[SourceValidity]: SpatialTargetFacade.md#SourceValidity
274299
[UseSourcePointOverride]: SpatialTargetFacade.md#UseSourcePointOverride
@@ -287,6 +312,7 @@ protected virtual void OnAfterUseTargetOverrideChange()
287312
[ActionsOnActivate]: #ActionsOnActivate
288313
[ActionsOnHover]: #ActionsOnHover
289314
[Configuration]: #Configuration
315+
[DeselectSelfDelay]: #DeselectSelfDelay
290316
[IsEnabled]: #IsEnabled
291317
[SourceValidity]: #SourceValidity
292318
[UseSourcePointOverride]: #UseSourcePointOverride
@@ -295,6 +321,7 @@ protected virtual void OnAfterUseTargetOverrideChange()
295321
[Deselect(Boolean)]: #DeselectBoolean
296322
[OnAfterActionOnHoverChange()]: #OnAfterActionOnHoverChange
297323
[OnAfterActionOnSelectChange()]: #OnAfterActionOnSelectChange
324+
[OnAfterDeselectSelfDelayChange()]: #OnAfterDeselectSelfDelayChange
298325
[OnAfterIsEnabledChange()]: #OnAfterIsEnabledChange
299326
[OnAfterSourceValidityChange()]: #OnAfterSourceValidityChange
300327
[OnAfterUseSourcePointOverrideChange()]: #OnAfterUseSourcePointOverrideChange

Runtime/SharedResources/Scripts/SpatialTarget.cs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ public class SurfaceDataUnityEvent : UnityEvent<SurfaceData> { }
4545
[field: DocumentedByXml]
4646
public bool DeactivateSelfOnActivated { get; set; } = true;
4747
/// <summary>
48+
/// The delay duration to wait before deactivating.
49+
/// </summary>
50+
[Serialized]
51+
[field: DocumentedByXml]
52+
public float DeactivateDelay { get; set; }
53+
/// <summary>
4854
/// Deactivates any other <see cref="SpatialTarget"/> connected to the same <see cref="SpatialTargetDispatcher"/> when this <see cref="SpatialTarget"/> is activated.
4955
/// </summary>
5056
[Serialized]
@@ -288,7 +294,15 @@ public virtual bool Select(SurfaceData data)
288294

289295
if (DeactivateSelfOnActivated)
290296
{
291-
return Deselect();
297+
if (DeactivateDelay.ApproxEquals(0f))
298+
{
299+
return Deselect();
300+
}
301+
else
302+
{
303+
Invoke("DoDeselect", DeactivateDelay);
304+
return true;
305+
}
292306
}
293307

294308
return true;
@@ -304,10 +318,10 @@ public virtual void DoSelect(SurfaceData data)
304318
}
305319

306320
/// <summary>
307-
/// Deselects this <see cref="SpatialTarget"/> if it is in a selected state.
321+
/// De-selects this <see cref="SpatialTarget"/> if it is in a selected state.
308322
/// </summary>
309323
/// <param name="keepInActivatingDispatcher">Whether to keep this in the <see cref="ActivatingDispatcher.SelectedTargets"/> collection.</param>
310-
/// <returns>Whether the deselect was successful.</returns>
324+
/// <returns>Whether the de-select was successful.</returns>
311325
[RequiresBehaviourState]
312326
public virtual bool Deselect(bool keepInActivatingDispatcher = false)
313327
{
@@ -331,14 +345,22 @@ public virtual bool Deselect(bool keepInActivatingDispatcher = false)
331345
}
332346

333347
/// <summary>
334-
/// Deselects this <see cref="SpatialTarget"/> if it is in a selected state.
348+
/// De-selects this <see cref="SpatialTarget"/> if it is in a selected state.
335349
/// </summary>
336350
/// <param name="keepInActivatingDispatcher">Whether to keep this in the <see cref="ActivatingDispatcher.SelectedTargets"/> collection.</param>
337-
public virtual void DoDeselect(bool keepInActivatingDispatcher = false)
351+
public virtual void DoDeselect(bool keepInActivatingDispatcher)
338352
{
339353
Deselect(keepInActivatingDispatcher);
340354
}
341355

356+
/// <summary>
357+
/// De-selects this <see cref="SpatialTarget"/> if it is in a selected state.
358+
/// </summary>
359+
public virtual void DoDeselect()
360+
{
361+
Deselect(false);
362+
}
363+
342364
/// <summary>
343365
/// Whether the given data is valid.
344366
/// </summary>

Runtime/SharedResources/Scripts/SpatialTargetConfigurator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public virtual void ConfigureActivationActions()
108108
{
109109
TargetController.ExitAllHoveringOnActivated = (Facade.ActionsOnActivate & SpatialTargetFacade.ActivationActions.ClearHoveringState) != 0;
110110
TargetController.DeactivateSelfOnActivated = (Facade.ActionsOnActivate & SpatialTargetFacade.ActivationActions.DeselectSelf) != 0;
111+
TargetController.DeactivateDelay = Facade.DeselectSelfDelay;
111112
TargetController.DeactivateOtherSpatialTargetsOnActivated = (Facade.ActionsOnActivate & SpatialTargetFacade.ActivationActions.DeselectOtherTargets) != 0;
112113
ActiveStateContainer.SetActive((Facade.ActionsOnActivate & SpatialTargetFacade.ActivationActions.HideActiveState) == 0);
113114
CollisionLogicContainer.SetActive((Facade.ActionsOnActivate & SpatialTargetFacade.ActivationActions.DisableCollisionsOnActivate) != 0);

Runtime/SharedResources/Scripts/SpatialTargetFacade.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ public enum ActivationActions
4343
/// </summary>
4444
ClearHoveringState = 1 << 0,
4545
/// <summary>
46-
/// Deselects this target upon activating this target.
46+
/// De-selects this target upon activating this target.
4747
/// </summary>
4848
DeselectSelf = 1 << 1,
4949
/// <summary>
50-
/// Deselects any other activated targets associated with the calling dispatcher.
50+
/// De-selects any other activated targets associated with the calling dispatcher.
5151
/// </summary>
5252
DeselectOtherTargets = 1 << 2,
5353
/// <summary>
@@ -92,6 +92,12 @@ public enum ActivationActions
9292
[field: DocumentedByXml, UnityFlags]
9393
public ActivationActions ActionsOnActivate { get; set; } = (ActivationActions)(-1);
9494
/// <summary>
95+
/// The amount of time to delay de-selecting this Spatial Target after it has been activated if the <see cref="ActionsOnActivate"/> <see cref="ActivationActions.DeselectSelf"/> is enabled.
96+
/// </summary>
97+
[Serialized]
98+
[field: DocumentedByXml]
99+
public float DeselectSelfDelay { get; set; }
100+
/// <summary>
95101
/// Determine which <see cref="SurfaceData"/> sources can interact with this <see cref="SpatialTargetFacade"/>.
96102
/// </summary>
97103
[Serialized, Cleared]
@@ -142,7 +148,7 @@ public enum ActivationActions
142148
#endregion
143149

144150
/// <summary>
145-
/// Deselects the containing <see cref="SpatialTarget"/> if it is in a selected state.
151+
/// De-selects the containing <see cref="SpatialTarget"/> if it is in a selected state.
146152
/// </summary>
147153
/// <param name="keepInActivatingDispatcher">Whether to keep this in the <see cref="ActivatingDispatcher.SelectedTargets"/> collection.</param>
148154
public virtual void Deselect(bool keepInActivatingDispatcher = false)
@@ -195,6 +201,15 @@ protected virtual void OnAfterActionOnSelectChange()
195201
Configuration.ConfigureActivationActions();
196202
}
197203

204+
/// <summary>
205+
/// Called after <see cref="DeselectSelfDelay"/> has been changed.
206+
/// </summary>
207+
[CalledAfterChangeOf(nameof(DeselectSelfDelay))]
208+
protected virtual void OnAfterDeselectSelfDelayChange()
209+
{
210+
Configuration.ConfigureActivationActions();
211+
}
212+
198213
/// <summary>
199214
/// Called after <see cref="SourceValidity"/> has been changed.
200215
/// </summary>

0 commit comments

Comments
 (0)