forked from MixedRealityToolkit/MixedRealityToolkit-Unity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlatScreenModeDetector.cs
More file actions
69 lines (58 loc) · 3.05 KB
/
Copy pathFlatScreenModeDetector.cs
File metadata and controls
69 lines (58 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) Mixed Reality Toolkit Contributors
// Licensed under the BSD 3-Clause
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;
namespace MixedReality.Toolkit.Input
{
internal class FlatScreenModeDetector : MonoBehaviour, IInteractionModeDetector
{
[SerializeField]
[Tooltip("The interaction mode to be set when the interactor is hovering over an interactable.")]
private InteractionMode flatScreenInteractionMode;
[SerializeField]
[FormerlySerializedAs("controllers")]
[Tooltip("List of XR Base interactor groups that this interaction mode detector has jurisdiction over. Interaction modes will be set on all specified groups.")]
private List<GameObject> interactorGroups;
public InteractionMode ModeOnDetection => flatScreenInteractionMode;
[Obsolete("This field has been deprecated in version 4.0.0. Please use MixedReality.Toolkit.Input.TrackedPoseDriverLookup instead.")]
protected ControllerLookup controllerLookup = null;
protected TrackedPoseDriverLookup trackedPoseDriverLookup = null;
/// <summary>
/// A Unity event function that is called when an enabled script instance is being loaded.
/// </summary>
protected void Awake()
{
#pragma warning disable CS0618 // ControllerLookup is obsolete
controllerLookup = ComponentCache<ControllerLookup>.FindFirstActiveInstance();
#pragma warning restore CS0618 // ControllerLookup is obsolete
trackedPoseDriverLookup = ComponentCache<TrackedPoseDriverLookup>.FindFirstActiveInstance();
}
/// <inheritdoc />
[Obsolete("This function has been deprecated in version 4.0.0 and will be removed in a future version. Please use GetInteractorGroups instead.")]
public List<GameObject> GetControllers() => GetInteractorGroups();
/// <inheritdoc />
public List<GameObject> GetInteractorGroups() => interactorGroups;
public bool IsModeDetected()
{
// Flat screen mode is only active if the Left and Right Hands aren't being tracked
#pragma warning disable CS0618 // Type or member is obsolete
if (controllerLookup != null)
{
return !controllerLookup.LeftHandController.currentControllerState.inputTrackingState.HasPositionAndRotation() && !controllerLookup.RightHandController.currentControllerState.inputTrackingState.HasPositionAndRotation();
}
#pragma warning restore CS0618
else if (trackedPoseDriverLookup != null)
{
return !trackedPoseDriverLookup.LeftHandTrackedPoseDriver.GetInputTrackingState().HasPositionAndRotation() &&
!trackedPoseDriverLookup.RightHandTrackedPoseDriver.GetInputTrackingState().HasPositionAndRotation();
}
else
{
Debug.LogWarning("Neither controllerLookup nor trackedPoseDriverLookup are set, unable to detect mode.");
return false;
}
}
}
}