summaryrefslogtreecommitdiff
path: root/Assets/Samples/XR Interaction Toolkit/3.1.2/XR Device Simulator/XRInteractionSimulator/Scripts
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Samples/XR Interaction Toolkit/3.1.2/XR Device Simulator/XRInteractionSimulator/Scripts')
-rw-r--r--Assets/Samples/XR Interaction Toolkit/3.1.2/XR Device Simulator/XRInteractionSimulator/Scripts/XRInteractionSimulatorInputFeedbackUI.cs888
-rw-r--r--Assets/Samples/XR Interaction Toolkit/3.1.2/XR Device Simulator/XRInteractionSimulator/Scripts/XRInteractionSimulatorInputFeedbackUI.cs.meta11
-rw-r--r--Assets/Samples/XR Interaction Toolkit/3.1.2/XR Device Simulator/XRInteractionSimulator/Scripts/XRInteractionSimulatorPlayModeMenu.cs693
-rw-r--r--Assets/Samples/XR Interaction Toolkit/3.1.2/XR Device Simulator/XRInteractionSimulator/Scripts/XRInteractionSimulatorPlayModeMenu.cs.meta11
4 files changed, 1603 insertions, 0 deletions
diff --git a/Assets/Samples/XR Interaction Toolkit/3.1.2/XR Device Simulator/XRInteractionSimulator/Scripts/XRInteractionSimulatorInputFeedbackUI.cs b/Assets/Samples/XR Interaction Toolkit/3.1.2/XR Device Simulator/XRInteractionSimulator/Scripts/XRInteractionSimulatorInputFeedbackUI.cs
new file mode 100644
index 0000000..6939a1c
--- /dev/null
+++ b/Assets/Samples/XR Interaction Toolkit/3.1.2/XR Device Simulator/XRInteractionSimulator/Scripts/XRInteractionSimulatorInputFeedbackUI.cs
@@ -0,0 +1,888 @@
+using System.Collections.Generic;
+using UnityEngine.InputSystem;
+using UnityEngine.UI;
+using UnityEngine.XR.Interaction.Toolkit.Inputs.Readers;
+using UnityEngine.XR.Interaction.Toolkit.Inputs.Simulation;
+
+namespace UnityEngine.XR.Interaction.Toolkit.Samples.DeviceSimulator
+{
+ class XRInteractionSimulatorInputFeedbackUI : MonoBehaviour
+ {
+ [Header("Input Device Modes")]
+
+ [SerializeField]
+ GameObject m_HMDPanel;
+
+ [SerializeField]
+ GameObject m_MirrorModePanel;
+
+ [SerializeField]
+ GameObject m_RightHandPanel;
+
+ [SerializeField]
+ GameObject m_LeftHandPanel;
+
+ [SerializeField]
+ GameObject m_RightControllerPanel;
+
+ [SerializeField]
+ GameObject m_LeftControllerPanel;
+
+ [SerializeField]
+ GameObject m_BothControllersPanel;
+
+ [SerializeField]
+ GameObject m_BothHandsPanel;
+
+ [Header("Controller Input Modes")]
+
+ [SerializeField]
+ GameObject m_TriggerPanel;
+ [SerializeField]
+ Image m_TriggerBg;
+
+ [SerializeField]
+ GameObject m_GripPanel;
+ [SerializeField]
+ Image m_GripBg;
+
+ [SerializeField]
+ GameObject m_PrimaryPanel;
+ [SerializeField]
+ Image m_PrimaryBg;
+
+ [SerializeField]
+ GameObject m_SecondaryPanel;
+ [SerializeField]
+ Image m_SecondaryBg;
+
+ [SerializeField]
+ GameObject m_MenuPanel;
+ [SerializeField]
+ Image m_MenuBg;
+
+ [SerializeField]
+ GameObject m_Primary2DAxisClickPanel;
+ [SerializeField]
+ Image m_Primary2DAxisClickBg;
+
+ [SerializeField]
+ GameObject m_Secondary2DAxisClickPanel;
+ [SerializeField]
+ Image m_Secondary2DAxisClickBg;
+
+ [SerializeField]
+ GameObject m_Primary2DAxisTouchPanel;
+ [SerializeField]
+ Image m_Primary2DAxisTouchBg;
+
+ [SerializeField]
+ GameObject m_Secondary2DAxisTouchPanel;
+ [SerializeField]
+ Image m_Secondary2DAxisTouchBg;
+
+ [SerializeField]
+ GameObject m_PrimaryTouchPanel;
+ [SerializeField]
+ Image m_PrimaryTouchBg;
+
+ [SerializeField]
+ GameObject m_SecondaryTouchPanel;
+ [SerializeField]
+ Image m_SecondaryTouchBg;
+
+ [SerializeField]
+ GameObject m_ControllerHotkeyPanel;
+ [SerializeField]
+ Image m_ControllerHotkeyBg;
+ [SerializeField]
+ Image m_ControllerHotkeyIcon;
+ [SerializeField]
+ Text m_ControllerHotkeyText;
+ [SerializeField]
+ Sprite m_LeftControllerSprite;
+ [SerializeField]
+ Sprite m_RightControllerSprite;
+
+ [SerializeField]
+ GameObject m_ControllerInputRow;
+
+ [Header("Hand Input Modes")]
+
+ [SerializeField]
+ GameObject m_PokePanel;
+ [SerializeField]
+ Image m_PokePanelBg;
+
+ [SerializeField]
+ GameObject m_PinchPanel;
+ [SerializeField]
+ Image m_PinchPanelBg;
+
+ [SerializeField]
+ GameObject m_GrabPanel;
+ [SerializeField]
+ Image m_GrabPanelBg;
+
+ [SerializeField]
+ GameObject m_ThumbPanel;
+ [SerializeField]
+ Image m_ThumbPanelBg;
+
+ [SerializeField]
+ GameObject m_OpenPanel;
+ [SerializeField]
+ Image m_OpenPanelBg;
+
+ [SerializeField]
+ GameObject m_FistPanel;
+ [SerializeField]
+ Image m_FistPanelBg;
+
+ [SerializeField]
+ GameObject m_CustomPanel;
+
+ [SerializeField]
+ GameObject m_HandHotkeyPanel;
+ [SerializeField]
+ Image m_HandHotkeyBg;
+ [SerializeField]
+ Image m_HandHotkeyIcon;
+ [SerializeField]
+ Text m_HandHotkeyText;
+ [SerializeField]
+ Sprite m_LeftHandSprite;
+ [SerializeField]
+ Sprite m_RightHandSprite;
+
+
+ [SerializeField]
+ GameObject m_HandInputRow;
+
+ [Header("General Input")]
+
+ [SerializeField]
+ GameObject m_TranslateForwardPanel;
+
+ [SerializeField]
+ GameObject m_TranslateBackwardPanel;
+
+ [SerializeField]
+ GameObject m_TranslateUpPanel;
+
+ [SerializeField]
+ GameObject m_TranslateDownPanel;
+
+ [SerializeField]
+ GameObject m_TranslateLeftPanel;
+
+ [SerializeField]
+ GameObject m_TranslateRightPanel;
+
+ [SerializeField]
+ GameObject m_RotateUpPanel;
+
+ [SerializeField]
+ GameObject m_RotateDownPanel;
+
+ [SerializeField]
+ GameObject m_RotateLeftPanel;
+
+ [SerializeField]
+ GameObject m_RotateRightPanel;
+
+ enum ActiveDeviceMode
+ {
+ LeftController,
+ RightController,
+ BothControllers,
+ LeftHand,
+ RightHand,
+ BothHands,
+ HMD,
+ None,
+ }
+
+ XRInteractionSimulator m_Simulator;
+ ActiveDeviceMode m_ActiveDeviceMode = ActiveDeviceMode.None;
+ SimulatedDeviceLifecycleManager.DeviceMode m_PreviousDeviceMode = SimulatedDeviceLifecycleManager.DeviceMode.None;
+ ControllerInputMode m_PreviousControllerInputMode;
+ SimulatedHandExpression m_PreviousHandExpression;
+
+ Dictionary<ControllerInputMode, GameObject> m_ControllerInputPanels;
+ Dictionary<ControllerInputMode, Image> m_ControllerInputBgs;
+ Dictionary<string, GameObject> m_HandExpressionPanels;
+ Dictionary<string, Image> m_HandExpressionBgs;
+
+ SimulatedDeviceLifecycleManager m_DeviceLifecycleManager;
+ SimulatedHandExpressionManager m_HandExpressionManager;
+
+ bool m_IsPerformingInput;
+ bool m_ToggleMousePressed;
+
+ // ReSharper disable InconsistentNaming -- Treat as constants
+ static readonly Color k_DefaultPanelColor = new Color(0x55 / 255f, 0x55 / 255f, 0x55 / 255f);
+ static readonly Color k_SelectedColor = new Color(0x4F / 255f, 0x65 / 255f, 0x7F / 255f);
+ static readonly Color k_EnabledColor = new Color(0x88 / 255f, 0x88 / 255f, 0x88 / 255f);
+ // ReSharper restore InconsistentNaming
+
+ /// <summary>
+ /// See <see cref="MonoBehaviour"/>.
+ /// </summary>
+ protected void Start()
+ {
+#if HAS_FIND_FIRST_OBJECT_BY_TYPE
+ var simulator = Object.FindFirstObjectByType<XRInteractionSimulator>();
+#else
+ var simulator = Object.FindObjectOfType<XRInteractionSimulator>();
+#endif
+ if (simulator != null)
+ {
+ m_Simulator = simulator;
+ }
+ else
+ {
+ Debug.LogError($"Could not find the XRInteractionSimulator component, disabling simulator UI.", this);
+ gameObject.SetActive(false);
+ return;
+ }
+
+ if (!m_Simulator.gameObject.TryGetComponent(out m_DeviceLifecycleManager))
+ {
+ Debug.LogError($"Could not find SimulatedDeviceLifecycleManager component on {m_Simulator.name}, disabling simulator UI.", this);
+ gameObject.SetActive(false);
+ return;
+ }
+
+ if (!m_Simulator.gameObject.TryGetComponent(out m_HandExpressionManager))
+ {
+ Debug.LogError($"Could not find SimulatedHandExpressionManager component on {m_Simulator.name}, disabling simulator UI.", this);
+ gameObject.SetActive(false);
+ return;
+ }
+
+ InitializeUIDictionaries();
+ ActivateControllerPanels();
+ ActivateHandPanels();
+ }
+
+ /// <summary>
+ /// See <see cref="MonoBehaviour"/>.
+ /// </summary>
+ protected void Update()
+ {
+ HandleActiveDeviceModePanels();
+ HandleGeneralInputFeedback();
+ HandleActiveInputModePanels();
+
+ if (m_DeviceLifecycleManager.deviceMode == SimulatedDeviceLifecycleManager.DeviceMode.Controller)
+ HandleDeviceHotkeyPanels();
+ else if (m_DeviceLifecycleManager.deviceMode == SimulatedDeviceLifecycleManager.DeviceMode.Hand)
+ HandleHandHotkeyPanels();
+ }
+
+ void HandleGeneralInputFeedback()
+ {
+ if (m_Simulator.toggleMouseInput.ReadWasCompletedThisFrame())
+ m_ToggleMousePressed = false;
+
+ if (!m_ToggleMousePressed)
+ ClearActiveGeneralInputPanels();
+
+ HandleKeyboardInputFeedback();
+ HandleMouseInputFeedback();
+ }
+
+ void HandleKeyboardInputFeedback()
+ {
+ if (m_Simulator.translateXInput.TryReadValue(out var xValue))
+ {
+ m_ToggleMousePressed = false;
+
+ if (xValue >= 0f)
+ m_TranslateRightPanel.SetActive(true);
+ else
+ m_TranslateLeftPanel.SetActive(true);
+ }
+
+ if (m_Simulator.translateYInput.TryReadValue(out var yValue))
+ {
+ m_ToggleMousePressed = false;
+
+ if (yValue >= 0f)
+ m_TranslateUpPanel.SetActive(true);
+ else
+ m_TranslateDownPanel.SetActive(true);
+ }
+
+ if (m_Simulator.translateZInput.TryReadValue(out var zValue))
+ {
+ m_ToggleMousePressed = false;
+
+ if (zValue >= 0f)
+ m_TranslateForwardPanel.SetActive(true);
+ else
+ m_TranslateBackwardPanel.SetActive(true);
+ }
+
+ if (m_Simulator.keyboardRotationDeltaInput.TryReadValue(out var rotValue))
+ {
+ m_ToggleMousePressed = false;
+
+ if (rotValue.x > 0f)
+ m_RotateRightPanel.SetActive(true);
+ else if (rotValue.x < 0f)
+ m_RotateLeftPanel.SetActive(true);
+
+ if (rotValue.y > 0f)
+ m_RotateUpPanel.SetActive(true);
+ else if (rotValue.y < 0f)
+ m_RotateDownPanel.SetActive(true);
+ }
+ }
+
+ void HandleMouseInputFeedback()
+ {
+ if (m_Simulator.toggleMouseInput.ReadIsPerformed() && m_Simulator.mouseRotationDeltaInput.TryReadValue(out var rotValue))
+ {
+ m_ToggleMousePressed = true;
+
+ m_TranslateBackwardPanel.SetActive(false);
+ m_TranslateForwardPanel.SetActive(false);
+ m_TranslateUpPanel.SetActive(false);
+ m_TranslateDownPanel.SetActive(false);
+ m_TranslateRightPanel.SetActive(false);
+ m_TranslateLeftPanel.SetActive(false);
+
+ if (rotValue.x > 0f)
+ {
+ m_RotateLeftPanel.SetActive(false);
+ m_RotateRightPanel.SetActive(true);
+ }
+ else if (rotValue.x < 0f)
+ {
+ m_RotateRightPanel.SetActive(false);
+ m_RotateLeftPanel.SetActive(true);
+ }
+
+ if (rotValue.y > 0f)
+ {
+ m_RotateDownPanel.SetActive(false);
+ m_RotateUpPanel.SetActive(true);
+ }
+ else if (rotValue.y < 0f)
+ {
+ m_RotateUpPanel.SetActive(false);
+ m_RotateDownPanel.SetActive(true);
+ }
+ }
+
+ if (m_Simulator.toggleMouseInput.ReadIsPerformed() && m_Simulator.mouseScrollInput.TryReadValue(out var scrollValue))
+ {
+ m_ToggleMousePressed = true;
+
+ m_RotateLeftPanel.SetActive(false);
+ m_RotateRightPanel.SetActive(false);
+ m_RotateDownPanel.SetActive(false);
+ m_RotateUpPanel.SetActive(false);
+
+ if (scrollValue.y >= 0f)
+ {
+ m_TranslateBackwardPanel.SetActive(false);
+ m_TranslateForwardPanel.SetActive(true);
+ }
+ else
+ {
+ m_TranslateForwardPanel.SetActive(false);
+ m_TranslateBackwardPanel.SetActive(true);
+ }
+ }
+ }
+
+ void HandleActiveDeviceModePanels()
+ {
+ if (m_Simulator.manipulatingFPS || m_Simulator.manipulatingHMD)
+ {
+ if (m_ActiveDeviceMode == ActiveDeviceMode.HMD)
+ return;
+
+ ClearActiveInputModePanels();
+ m_HMDPanel.SetActive(true);
+ m_ActiveDeviceMode = ActiveDeviceMode.HMD;
+ }
+ else if (m_Simulator.manipulatingLeftController && m_Simulator.manipulatingRightController)
+ {
+ if (m_ActiveDeviceMode == ActiveDeviceMode.BothControllers)
+ return;
+
+ ClearActiveInputModePanels();
+ m_BothControllersPanel.SetActive(true);
+ m_ActiveDeviceMode = ActiveDeviceMode.BothControllers;
+ }
+ else if (m_Simulator.manipulatingLeftController)
+ {
+ if (m_ActiveDeviceMode == ActiveDeviceMode.LeftController)
+ return;
+
+ ClearActiveInputModePanels();
+ m_LeftControllerPanel.SetActive(true);
+ m_ActiveDeviceMode = ActiveDeviceMode.LeftController;
+ }
+ else if (m_Simulator.manipulatingRightController)
+ {
+ if (m_ActiveDeviceMode == ActiveDeviceMode.RightController)
+ return;
+
+ ClearActiveInputModePanels();
+ m_RightControllerPanel.SetActive(true);
+ m_ActiveDeviceMode = ActiveDeviceMode.RightController;
+ }
+ else if (m_Simulator.manipulatingLeftHand && m_Simulator.manipulatingRightHand)
+ {
+ if (m_ActiveDeviceMode == ActiveDeviceMode.BothHands)
+ return;
+
+ ClearActiveInputModePanels();
+ m_BothHandsPanel.SetActive(true);
+ m_ActiveDeviceMode = ActiveDeviceMode.BothHands;
+ }
+ else if (m_Simulator.manipulatingLeftHand)
+ {
+ if (m_ActiveDeviceMode == ActiveDeviceMode.LeftHand)
+ return;
+
+ ClearActiveInputModePanels();
+ m_LeftHandPanel.SetActive(true);
+ m_ActiveDeviceMode = ActiveDeviceMode.LeftHand;
+ }
+ else if (m_Simulator.manipulatingRightHand)
+ {
+ if (m_ActiveDeviceMode == ActiveDeviceMode.RightHand)
+ return;
+
+ ClearActiveInputModePanels();
+ m_RightHandPanel.SetActive(true);
+ m_ActiveDeviceMode = ActiveDeviceMode.RightHand;
+ }
+ }
+
+ void HandleActiveInputModePanels()
+ {
+ if (m_Simulator.manipulatingFPS || m_Simulator.manipulatingHMD)
+ {
+ m_ControllerInputRow.SetActive(false);
+ m_HandInputRow.SetActive(false);
+ return;
+ }
+
+ if (!m_ControllerInputRow.activeSelf && m_DeviceLifecycleManager.deviceMode == SimulatedDeviceLifecycleManager.DeviceMode.Controller)
+ m_ControllerInputRow.SetActive(true);
+
+ if (!m_HandInputRow.activeSelf && m_DeviceLifecycleManager.deviceMode == SimulatedDeviceLifecycleManager.DeviceMode.Hand)
+ m_HandInputRow.SetActive(true);
+
+ if (!m_IsPerformingInput)
+ {
+ if (m_PreviousDeviceMode != m_DeviceLifecycleManager.deviceMode)
+ {
+ m_ControllerInputRow.SetActive(false);
+ m_HandInputRow.SetActive(false);
+
+ if (m_DeviceLifecycleManager.deviceMode == SimulatedDeviceLifecycleManager.DeviceMode.Controller)
+ {
+ m_ControllerInputRow.SetActive(true);
+ HighlightActiveControllerInputMode(k_SelectedColor);
+ }
+ else if (m_DeviceLifecycleManager.deviceMode == SimulatedDeviceLifecycleManager.DeviceMode.Hand)
+ {
+ m_HandInputRow.SetActive(true);
+ HighlightActiveHandInputMode(k_SelectedColor);
+ }
+
+ m_PreviousDeviceMode = m_DeviceLifecycleManager.deviceMode;
+ }
+ else if (m_DeviceLifecycleManager.deviceMode == SimulatedDeviceLifecycleManager.DeviceMode.Controller && m_PreviousControllerInputMode != m_Simulator.controllerInputMode)
+ {
+ HighlightActiveControllerInputMode(k_SelectedColor);
+ }
+ else if (m_DeviceLifecycleManager.deviceMode == SimulatedDeviceLifecycleManager.DeviceMode.Hand && m_PreviousHandExpression != m_Simulator.currentHandExpression)
+ {
+ HighlightActiveHandInputMode(k_SelectedColor);
+ }
+ }
+
+ if (m_Simulator.togglePerformQuickActionInput.ReadWasPerformedThisFrame())
+ {
+ m_IsPerformingInput = !m_IsPerformingInput;
+
+ if (m_DeviceLifecycleManager.deviceMode == SimulatedDeviceLifecycleManager.DeviceMode.Controller)
+ {
+ if (m_IsPerformingInput)
+ HighlightActiveControllerInputMode(k_EnabledColor);
+ else
+ HighlightActiveControllerInputMode(k_SelectedColor);
+ }
+ else if (m_DeviceLifecycleManager.deviceMode == SimulatedDeviceLifecycleManager.DeviceMode.Hand)
+ {
+ if (m_IsPerformingInput)
+ HighlightActiveHandInputMode(k_EnabledColor);
+ else
+ HighlightActiveHandInputMode(k_SelectedColor);
+ }
+ }
+
+ if (m_Simulator.cycleQuickActionInput.ReadWasPerformedThisFrame())
+ {
+ m_IsPerformingInput = false;
+ }
+ }
+
+ void HandleDeviceHotkeyPanels()
+ {
+ if (m_Simulator.gripInput.ReadIsPerformed())
+ {
+ ApplyHotkeyText(m_Simulator.gripInput, SimulatedDeviceLifecycleManager.DeviceMode.Controller);
+ m_ControllerHotkeyPanel.SetActive(true);
+ }
+ else if (m_Simulator.gripInput.ReadWasCompletedThisFrame())
+ {
+ m_ControllerHotkeyPanel.SetActive(false);
+ }
+
+ if (m_Simulator.triggerInput.ReadIsPerformed())
+ {
+ ApplyHotkeyText(m_Simulator.triggerInput, SimulatedDeviceLifecycleManager.DeviceMode.Controller);
+ m_ControllerHotkeyPanel.SetActive(true);
+ }
+ else if (m_Simulator.triggerInput.ReadWasCompletedThisFrame())
+ {
+ m_ControllerHotkeyPanel.SetActive(false);
+ }
+
+ if (m_Simulator.primaryButtonInput.ReadIsPerformed())
+ {
+ ApplyHotkeyText(m_Simulator.primaryButtonInput, SimulatedDeviceLifecycleManager.DeviceMode.Controller);
+ m_ControllerHotkeyPanel.SetActive(true);
+ }
+ else if (m_Simulator.primaryButtonInput.ReadWasCompletedThisFrame())
+ {
+ m_ControllerHotkeyPanel.SetActive(false);
+ }
+
+ if (m_Simulator.secondaryButtonInput.ReadIsPerformed())
+ {
+ ApplyHotkeyText(m_Simulator.secondaryButtonInput, SimulatedDeviceLifecycleManager.DeviceMode.Controller);
+ m_ControllerHotkeyPanel.SetActive(true);
+ }
+ else if (m_Simulator.secondaryButtonInput.ReadWasCompletedThisFrame())
+ {
+ m_ControllerHotkeyPanel.SetActive(false);
+ }
+
+ if (m_Simulator.menuInput.ReadIsPerformed())
+ {
+ ApplyHotkeyText(m_Simulator.menuInput, SimulatedDeviceLifecycleManager.DeviceMode.Controller);
+ m_ControllerHotkeyPanel.SetActive(true);
+ }
+ else if (m_Simulator.menuInput.ReadWasCompletedThisFrame())
+ {
+ m_ControllerHotkeyPanel.SetActive(false);
+ }
+
+ if (m_Simulator.primary2DAxisClickInput.ReadIsPerformed())
+ {
+ ApplyHotkeyText(m_Simulator.primary2DAxisClickInput, SimulatedDeviceLifecycleManager.DeviceMode.Controller);
+ m_ControllerHotkeyPanel.SetActive(true);
+ }
+ else if (m_Simulator.primary2DAxisClickInput.ReadWasCompletedThisFrame())
+ {
+ m_ControllerHotkeyPanel.SetActive(false);
+ }
+
+ if (m_Simulator.secondary2DAxisClickInput.ReadIsPerformed())
+ {
+ ApplyHotkeyText(m_Simulator.secondary2DAxisClickInput, SimulatedDeviceLifecycleManager.DeviceMode.Controller);
+ m_ControllerHotkeyPanel.SetActive(true);
+ }
+ else if (m_Simulator.secondary2DAxisClickInput.ReadWasCompletedThisFrame())
+ {
+ m_ControllerHotkeyPanel.SetActive(false);
+ }
+
+ if (m_Simulator.primary2DAxisTouchInput.ReadIsPerformed())
+ {
+ ApplyHotkeyText(m_Simulator.primary2DAxisTouchInput, SimulatedDeviceLifecycleManager.DeviceMode.Controller);
+ m_ControllerHotkeyPanel.SetActive(true);
+ }
+ else if (m_Simulator.primary2DAxisTouchInput.ReadWasCompletedThisFrame())
+ {
+ m_ControllerHotkeyPanel.SetActive(false);
+ }
+
+ if (m_Simulator.secondary2DAxisTouchInput.ReadIsPerformed())
+ {
+ ApplyHotkeyText(m_Simulator.secondary2DAxisTouchInput, SimulatedDeviceLifecycleManager.DeviceMode.Controller);
+ m_ControllerHotkeyPanel.SetActive(true);
+ }
+ else if (m_Simulator.secondary2DAxisTouchInput.ReadWasCompletedThisFrame())
+ {
+ m_ControllerHotkeyPanel.SetActive(false);
+ }
+
+ if (m_Simulator.primaryTouchInput.ReadIsPerformed())
+ {
+ ApplyHotkeyText(m_Simulator.primaryTouchInput, SimulatedDeviceLifecycleManager.DeviceMode.Controller);
+ m_ControllerHotkeyPanel.SetActive(true);
+ }
+ else if (m_Simulator.primaryTouchInput.ReadWasCompletedThisFrame())
+ {
+ m_ControllerHotkeyPanel.SetActive(false);
+ }
+
+ if (m_Simulator.secondaryTouchInput.ReadIsPerformed())
+ {
+ ApplyHotkeyText(m_Simulator.secondaryTouchInput, SimulatedDeviceLifecycleManager.DeviceMode.Controller);
+ m_ControllerHotkeyPanel.SetActive(true);
+ }
+ else if (m_Simulator.secondaryTouchInput.ReadWasCompletedThisFrame())
+ {
+ m_ControllerHotkeyPanel.SetActive(false);
+ }
+ }
+
+ void HandleHandHotkeyPanels()
+ {
+ foreach (var handExpression in m_HandExpressionManager.simulatedHandExpressions)
+ {
+ if (handExpression.toggleInput.ReadIsPerformed())
+ {
+ ApplyHotkeyText(handExpression.toggleInput, SimulatedDeviceLifecycleManager.DeviceMode.Hand);
+ m_HandHotkeyPanel.SetActive(true);
+ }
+ else if (handExpression.toggleInput.ReadWasCompletedThisFrame())
+ {
+ m_HandHotkeyPanel.SetActive(false);
+ }
+ }
+ }
+
+ void ApplyHotkeyText(XRInputButtonReader inputReader, SimulatedDeviceLifecycleManager.DeviceMode mode)
+ {
+ string bindingText = inputReader.inputActionReferencePerformed.action.GetBindingDisplayString(0);
+
+ if (mode == SimulatedDeviceLifecycleManager.DeviceMode.Controller)
+ {
+ if (m_Simulator.leftDeviceActionsInput.ReadIsPerformed())
+ m_ControllerHotkeyIcon.sprite = m_LeftControllerSprite;
+ else
+ m_ControllerHotkeyIcon.sprite = m_RightControllerSprite;
+
+ m_ControllerHotkeyText.text = $"{bindingText}";
+ }
+ else if (mode == SimulatedDeviceLifecycleManager.DeviceMode.Hand)
+ {
+ if (m_Simulator.leftDeviceActionsInput.ReadIsPerformed())
+ m_HandHotkeyIcon.sprite = m_LeftHandSprite;
+ else
+ m_HandHotkeyIcon.sprite = m_RightHandSprite;
+
+ m_HandHotkeyText.text = $"{bindingText}";
+ }
+ }
+
+ void ActivateControllerPanels()
+ {
+ for (var i = 0; i < m_Simulator.quickActionControllerInputModes.Count; i++)
+ {
+ if (!m_ControllerInputPanels.ContainsKey(m_Simulator.quickActionControllerInputModes[i]))
+ {
+ string inputModeName = m_Simulator.quickActionControllerInputModes[i].ToString();
+ Debug.LogError($"Panel for the {inputModeName} controller input mode does not exist.", this);
+ }
+
+ var panel = m_ControllerInputPanels[m_Simulator.quickActionControllerInputModes[i]];
+ panel.SetActive(true);
+ panel.transform.SetSiblingIndex(i);
+ }
+ }
+
+ void ActivateHandPanels()
+ {
+ for (var i = 0; i < m_HandExpressionManager.simulatedHandExpressions.Count; i++)
+ {
+ if (m_HandExpressionManager.simulatedHandExpressions[i].isQuickAction)
+ {
+ string handExpressionName = m_HandExpressionManager.simulatedHandExpressions[i].name;
+
+ if (!m_HandExpressionPanels.ContainsKey(handExpressionName))
+ {
+ Debug.LogError($"Panel for the {handExpressionName} hand expression does not exist.", this);
+ }
+
+ var panel = m_HandExpressionPanels[handExpressionName];
+ panel.SetActive(true);
+ panel.transform.SetSiblingIndex(i);
+ }
+ }
+ }
+
+ void InitializeUIDictionaries()
+ {
+ m_ControllerInputPanels = new Dictionary<ControllerInputMode, GameObject>
+ {
+ {ControllerInputMode.Trigger, m_TriggerPanel},
+ {ControllerInputMode.Grip, m_GripPanel},
+ {ControllerInputMode.PrimaryButton, m_PrimaryPanel},
+ {ControllerInputMode.SecondaryButton, m_SecondaryPanel},
+ {ControllerInputMode.Menu, m_MenuPanel},
+ {ControllerInputMode.Primary2DAxisClick, m_Primary2DAxisClickPanel},
+ {ControllerInputMode.Secondary2DAxisClick, m_Secondary2DAxisClickPanel},
+ {ControllerInputMode.Primary2DAxisTouch, m_Primary2DAxisTouchPanel},
+ {ControllerInputMode.Secondary2DAxisTouch, m_Secondary2DAxisTouchPanel},
+ {ControllerInputMode.PrimaryTouch, m_PrimaryTouchPanel},
+ {ControllerInputMode.SecondaryTouch, m_SecondaryTouchPanel},
+ };
+
+ m_ControllerInputBgs = new Dictionary<ControllerInputMode, Image>
+ {
+ {ControllerInputMode.Trigger, m_TriggerBg},
+ {ControllerInputMode.Grip, m_GripBg},
+ {ControllerInputMode.PrimaryButton, m_PrimaryBg},
+ {ControllerInputMode.SecondaryButton, m_SecondaryBg},
+ {ControllerInputMode.Menu, m_MenuBg},
+ {ControllerInputMode.Primary2DAxisClick, m_Primary2DAxisClickBg},
+ {ControllerInputMode.Secondary2DAxisClick, m_Secondary2DAxisClickBg},
+ {ControllerInputMode.Primary2DAxisTouch, m_Primary2DAxisTouchBg},
+ {ControllerInputMode.Secondary2DAxisTouch, m_Secondary2DAxisTouchBg},
+ {ControllerInputMode.PrimaryTouch, m_PrimaryTouchBg},
+ {ControllerInputMode.SecondaryTouch, m_SecondaryTouchBg},
+ };
+
+ m_HandExpressionPanels = new Dictionary<string, GameObject>
+ {
+ {"Poke", m_PokePanel},
+ {"Pinch", m_PinchPanel},
+ {"Grab", m_GrabPanel},
+ {"Thumb", m_ThumbPanel},
+ {"Open", m_OpenPanel},
+ {"Fist", m_FistPanel},
+ };
+
+ m_HandExpressionBgs = new Dictionary<string, Image>
+ {
+ {"Poke", m_PokePanelBg},
+ {"Pinch", m_PinchPanelBg},
+ {"Grab", m_GrabPanelBg},
+ {"Thumb", m_ThumbPanelBg},
+ {"Open", m_OpenPanelBg},
+ {"Fist", m_FistPanelBg},
+ };
+
+ InitializeCustomHandExpressionPanels();
+ }
+
+ void InitializeCustomHandExpressionPanels()
+ {
+ foreach (var handExpression in m_HandExpressionManager.simulatedHandExpressions)
+ {
+ if (!m_HandExpressionPanels.ContainsKey(handExpression.name) && handExpression.isQuickAction)
+ {
+ var panel = Instantiate(m_CustomPanel, m_CustomPanel.transform.parent);
+ panel.name = $"{handExpression.name}Panel";
+
+ var bgImage = panel.GetComponentInChildren<Image>();
+ if (bgImage == null)
+ {
+ var bgImageGO = Instantiate(new GameObject(), panel.transform);
+ bgImageGO.name = "Bg";
+ bgImage = bgImageGO.AddComponent<Image>();
+ }
+
+ var textUI = panel.GetComponentInChildren<Text>();
+ if (textUI == null)
+ {
+ var textGO = Instantiate(new GameObject(), panel.transform);
+ textGO.name = "Text";
+ textUI = textGO.AddComponent<Text>();
+ textUI.fontStyle = FontStyle.Bold;
+ }
+ textUI.text = handExpression.name;
+
+ m_HandExpressionPanels[handExpression.name] = panel;
+ m_HandExpressionBgs[handExpression.name] = bgImage;
+ }
+ }
+ }
+
+ void HighlightActiveControllerInputMode(Color highlightColor)
+ {
+ ClearHighlightedControllerPanels();
+
+ if (!m_ControllerInputBgs.ContainsKey(m_Simulator.controllerInputMode))
+ {
+ string inputModeName = m_Simulator.controllerInputMode.ToString();
+ Debug.LogError($"Background for the {inputModeName} controller input mode panel does not exist.", this);
+ }
+
+ m_ControllerInputBgs[m_Simulator.controllerInputMode].color = highlightColor;
+ m_PreviousControllerInputMode = m_Simulator.controllerInputMode;
+ }
+
+ void HighlightActiveHandInputMode(Color highlightColor)
+ {
+ ClearHighlightedHandPanels();
+
+ var handExpressionName = m_Simulator.currentHandExpression.name;
+ if (string.IsNullOrEmpty(handExpressionName))
+ return;
+
+ if (!m_HandExpressionBgs.ContainsKey(handExpressionName))
+ {
+ Debug.LogError($"Background for the {handExpressionName} hand expression panel does not exist.", this);
+ }
+
+ m_HandExpressionBgs[handExpressionName].color = highlightColor;
+ }
+
+ void ClearActiveInputModePanels()
+ {
+ m_BothControllersPanel.SetActive(false);
+ m_LeftControllerPanel.SetActive(false);
+ m_RightControllerPanel.SetActive(false);
+ m_BothHandsPanel.SetActive(false);
+ m_LeftHandPanel.SetActive(false);
+ m_RightHandPanel.SetActive(false);
+ m_HMDPanel.SetActive(false);
+ }
+
+ void ClearActiveGeneralInputPanels()
+ {
+ m_TranslateForwardPanel.SetActive(false);
+ m_TranslateBackwardPanel.SetActive(false);
+ m_TranslateUpPanel.SetActive(false);
+ m_TranslateDownPanel.SetActive(false);
+ m_TranslateLeftPanel.SetActive(false);
+ m_TranslateRightPanel.SetActive(false);
+ m_RotateUpPanel.SetActive(false);
+ m_RotateDownPanel.SetActive(false);
+ m_RotateLeftPanel.SetActive(false);
+ m_RotateRightPanel.SetActive(false);
+ }
+
+ void ClearHighlightedHandPanels()
+ {
+ foreach (var bg in m_HandExpressionBgs.Values)
+ {
+ bg.color = k_DefaultPanelColor;
+ }
+ }
+
+ void ClearHighlightedControllerPanels()
+ {
+ foreach (var bg in m_ControllerInputBgs.Values)
+ {
+ bg.color = k_DefaultPanelColor;
+ }
+ }
+ }
+}
diff --git a/Assets/Samples/XR Interaction Toolkit/3.1.2/XR Device Simulator/XRInteractionSimulator/Scripts/XRInteractionSimulatorInputFeedbackUI.cs.meta b/Assets/Samples/XR Interaction Toolkit/3.1.2/XR Device Simulator/XRInteractionSimulator/Scripts/XRInteractionSimulatorInputFeedbackUI.cs.meta
new file mode 100644
index 0000000..2226f4a
--- /dev/null
+++ b/Assets/Samples/XR Interaction Toolkit/3.1.2/XR Device Simulator/XRInteractionSimulator/Scripts/XRInteractionSimulatorInputFeedbackUI.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: f4b9da94370444448aa6dcb1598d0dae
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Samples/XR Interaction Toolkit/3.1.2/XR Device Simulator/XRInteractionSimulator/Scripts/XRInteractionSimulatorPlayModeMenu.cs b/Assets/Samples/XR Interaction Toolkit/3.1.2/XR Device Simulator/XRInteractionSimulator/Scripts/XRInteractionSimulatorPlayModeMenu.cs
new file mode 100644
index 0000000..2a5e47a
--- /dev/null
+++ b/Assets/Samples/XR Interaction Toolkit/3.1.2/XR Device Simulator/XRInteractionSimulator/Scripts/XRInteractionSimulatorPlayModeMenu.cs
@@ -0,0 +1,693 @@
+using UnityEngine.UI;
+using UnityEngine.Assertions;
+using UnityEngine.InputSystem;
+#if XR_HANDS_1_1_OR_NEWER
+using UnityEngine.XR.Hands;
+#endif
+using UnityEngine.XR.Interaction.Toolkit.Inputs;
+using UnityEngine.XR.Interaction.Toolkit.Inputs.Readers;
+using UnityEngine.XR.Interaction.Toolkit.Inputs.Simulation;
+using UnityEngine.XR.Interaction.Toolkit.Utilities;
+
+namespace UnityEngine.XR.Interaction.Toolkit.Samples.DeviceSimulator
+{
+ class XRInteractionSimulatorPlayModeMenu : MonoBehaviour
+ {
+ [Header("Menus")]
+
+ [SerializeField]
+ GameObject m_InputSelectionMenu;
+
+ [SerializeField]
+ GameObject m_ClosedInputSelectionMenu;
+
+ [SerializeField]
+ GameObject m_ControllerActionsMenu;
+
+ [SerializeField]
+ GameObject m_ClosedControllerActionsMenu;
+
+ [SerializeField]
+ GameObject m_HandActionsMenu;
+
+ [SerializeField]
+ GameObject m_ClosedHandActionsMenu;
+
+ [Header("Input Readers")]
+
+ [SerializeField]
+ XRInputButtonReader m_ToggleActionMenu;
+
+ [SerializeField]
+ XRInputButtonReader m_ToggleInputSelectionMenu;
+
+ [Header("Device Highlight Panels")]
+
+ [SerializeField]
+ GameObject m_HighlightFullBodyPanel;
+
+ [SerializeField]
+ GameObject m_HighlightLeftControllerPanel;
+
+ [SerializeField]
+ GameObject m_HighlightRightControllerPanel;
+
+ [SerializeField]
+ GameObject m_HighlightLeftHandPanel;
+
+ [SerializeField]
+ GameObject m_HighlightRightHandPanel;
+
+ [SerializeField]
+ GameObject m_HighlightHeadPanel;
+
+ [Header("Controller Action Panels")]
+
+ [SerializeField]
+ GameObject m_ControllerActionHighlightPanel;
+
+ [SerializeField]
+ Text m_FirstControllerActionText;
+
+ [SerializeField]
+ Text m_SecondControllerActionText;
+
+ [SerializeField]
+ Text m_ThirdControllerActionText;
+
+ [SerializeField]
+ Text m_FourthControllerActionText;
+
+ [SerializeField]
+ Text m_FirstControllerBindingText;
+
+ [SerializeField]
+ Text m_SecondControllerBindingText;
+
+ [SerializeField]
+ Text m_ThirdControllerBindingText;
+
+ [SerializeField]
+ Text m_FourthControllerBindingText;
+
+ [SerializeField]
+ GameObject m_FirstControllerBindingGO;
+
+ [SerializeField]
+ GameObject m_SecondControllerBindingGO;
+
+ [SerializeField]
+ GameObject m_ThirdControllerBindingGO;
+
+ [SerializeField]
+ GameObject m_FourthControllerBindingGO;
+
+ [Header("Hand Action Panels")]
+
+ [SerializeField]
+ GameObject m_HandActionHighlightPanel;
+
+ [SerializeField]
+ Text m_FirstHandActionText;
+
+ [SerializeField]
+ Text m_SecondHandActionText;
+
+ [SerializeField]
+ Text m_ThirdHandActionText;
+
+ [SerializeField]
+ Text m_FourthHandActionText;
+
+ [SerializeField]
+ Text m_FirstHandBindingText;
+
+ [SerializeField]
+ Text m_SecondHandBindingText;
+
+ [SerializeField]
+ Text m_ThirdHandBindingText;
+
+ [SerializeField]
+ Text m_FourthHandBindingText;
+
+ [SerializeField]
+ GameObject m_FirstHandBindingGO;
+
+ [SerializeField]
+ GameObject m_SecondHandBindingGO;
+
+ [SerializeField]
+ GameObject m_ThirdHandBindingGO;
+
+ [SerializeField]
+ GameObject m_FourthHandBindingGO;
+
+ [Header("Hand UI")]
+ [SerializeField]
+ Image m_LeftHandIcon;
+
+ [SerializeField]
+ Image m_RightHandIcon;
+
+ [SerializeField]
+ GameObject m_HandPackageWarningPanel;
+
+ [SerializeField]
+ GameObject m_InputModalityManagerWarningPanel;
+
+ [SerializeField]
+ GameObject m_InputMenuHandVisualizerWarningPanel;
+
+ [SerializeField]
+ GameObject m_HandMenuHandVisualizerWarningPanel;
+
+ XRInteractionSimulator m_Simulator;
+ SimulatedDeviceLifecycleManager m_DeviceLifecycleManager;
+ SimulatedHandExpressionManager m_HandExpressionManager;
+
+ SimulatedDeviceLifecycleManager.DeviceMode m_PreviousDeviceMode = SimulatedDeviceLifecycleManager.DeviceMode.None;
+ TargetedDevices m_PreviousTargetedDeviceInput = TargetedDevices.None;
+ ControllerInputMode m_PreviousControllerInputMode = ControllerInputMode.None;
+ SimulatedHandExpression m_PreviousHandExpression = new SimulatedHandExpression();
+
+ int m_ControllerActionIndex = -1;
+ int m_HandActionIndex = -1;
+ int m_QuickActionHandExpressionLength;
+ int[] m_HandExpressionIndices = { -1, -1, -1, -1 };
+ bool m_PreviousControllerMenuState;
+ bool m_PreviousHandMenuState;
+
+ static readonly Color k_DisabledColor = new Color(0x70 / 255f, 0x70 / 255f, 0x70 / 255f);
+
+ /// <summary>
+ /// See <see cref="MonoBehaviour"/>.
+ /// </summary>
+ protected void Start()
+ {
+#if HAS_FIND_FIRST_OBJECT_BY_TYPE
+ var simulator = Object.FindFirstObjectByType<XRInteractionSimulator>();
+#else
+ var simulator = Object.FindObjectOfType<XRInteractionSimulator>();
+#endif
+ if (simulator != null)
+ {
+ m_Simulator = simulator;
+ }
+ else
+ {
+ Debug.LogError($"Could not find the XRInteractionSimulator component, disabling simulator UI.", this);
+ gameObject.SetActive(false);
+ return;
+ }
+
+ if (!m_Simulator.gameObject.TryGetComponent(out m_DeviceLifecycleManager))
+ {
+ Debug.LogError($"Could not find SimulatedDeviceLifecycleManager component on {m_Simulator.name}, disabling simulator UI.", this);
+ gameObject.SetActive(false);
+ return;
+ }
+
+ if (!m_Simulator.gameObject.TryGetComponent(out m_HandExpressionManager))
+ {
+ Debug.LogError($"Could not find SimulatedHandExpressionManager component on {m_Simulator.name}, disabling simulator UI.", this);
+ gameObject.SetActive(false);
+ return;
+ }
+
+ InitializeQuickActionPanels();
+
+#if XR_HANDS_1_1_OR_NEWER
+ CheckInputModalityManager();
+#else
+ m_HandPackageWarningPanel.SetActive(true);
+ m_LeftHandIcon.color = k_DisabledColor;
+ m_RightHandIcon.color = k_DisabledColor;
+#endif
+
+#if XR_HANDS_1_2_OR_NEWER
+ if (!m_HandPackageWarningPanel.activeSelf && !m_InputModalityManagerWarningPanel.activeSelf)
+ CheckHandVisualizer();
+#endif
+ }
+
+ void CheckInputModalityManager()
+ {
+ if (ComponentLocatorUtility<XRInputModalityManager>.TryFindComponent(out var inputModalityManager) &&
+ inputModalityManager.leftHand == null && inputModalityManager.rightHand == null)
+ {
+ m_InputModalityManagerWarningPanel.SetActive(true);
+ m_LeftHandIcon.color = k_DisabledColor;
+ m_RightHandIcon.color = k_DisabledColor;
+ }
+ }
+
+#if XR_HANDS_1_2_OR_NEWER
+ void CheckHandVisualizer()
+ {
+ if (ComponentLocatorUtility<XRInputModalityManager>.TryFindComponent(out var inputModalityManager))
+ {
+ if (inputModalityManager.leftHand == null && inputModalityManager.rightHand == null)
+ return;
+
+ if ((inputModalityManager.leftHand != null &&
+ inputModalityManager.leftHand.GetComponentInChildren<XRHandMeshController>() != null) ||
+ (inputModalityManager.rightHand != null &&
+ inputModalityManager.rightHand.GetComponentInChildren<XRHandMeshController>() != null))
+ {
+ return;
+ }
+
+ m_InputMenuHandVisualizerWarningPanel.SetActive(true);
+ m_HandMenuHandVisualizerWarningPanel.SetActive(true);
+ }
+ }
+#endif
+
+ void InitializeQuickActionPanels()
+ {
+ InitializeControllerQuickActionPanels();
+ InitializeHandQuickActionPanels();
+ }
+
+ void InitializeControllerQuickActionPanels()
+ {
+ var inputModesLength = m_Simulator.quickActionControllerInputModes.Count;
+ if (inputModesLength > 0)
+ {
+ GetControllerQuickActionNames(m_Simulator.quickActionControllerInputModes[0], m_FirstControllerActionText, m_FirstControllerBindingText);
+ }
+ else
+ {
+ m_FirstControllerActionText.gameObject.SetActive(false);
+ m_FirstControllerBindingGO.SetActive(false);
+ }
+
+ if (inputModesLength > 1)
+ {
+ GetControllerQuickActionNames(m_Simulator.quickActionControllerInputModes[1], m_SecondControllerActionText, m_SecondControllerBindingText);
+ }
+ else
+ {
+ m_SecondControllerActionText.gameObject.SetActive(false);
+ m_SecondControllerBindingGO.SetActive(false);
+ }
+
+ if (inputModesLength > 2)
+ {
+ GetControllerQuickActionNames(m_Simulator.quickActionControllerInputModes[2], m_ThirdControllerActionText, m_ThirdControllerBindingText);
+ }
+ else
+ {
+ m_ThirdControllerActionText.gameObject.SetActive(false);
+ m_ThirdControllerBindingGO.SetActive(false);
+ }
+
+ if (inputModesLength > 3)
+ {
+ GetControllerQuickActionNames(m_Simulator.quickActionControllerInputModes[3], m_FourthControllerActionText, m_FourthControllerBindingText);
+ }
+ else
+ {
+ m_FourthControllerActionText.gameObject.SetActive(false);
+ m_FourthControllerBindingGO.SetActive(false);
+ }
+ }
+
+ void InitializeHandQuickActionPanels()
+ {
+ for (int i = 0; i < m_HandExpressionManager.simulatedHandExpressions.Count; i++)
+ {
+ if (m_HandExpressionManager.simulatedHandExpressions[i].isQuickAction)
+ {
+ if (m_QuickActionHandExpressionLength < 4)
+ m_HandExpressionIndices[m_QuickActionHandExpressionLength] = i;
+
+ m_QuickActionHandExpressionLength++;
+ }
+ }
+
+ if (m_QuickActionHandExpressionLength > 0)
+ {
+ var handExpression = m_HandExpressionManager.simulatedHandExpressions[m_HandExpressionIndices[0]];
+ m_FirstHandActionText.text = handExpression.name;
+ m_FirstHandBindingText.text = GetBindingString(handExpression.toggleInput);
+ }
+ else
+ {
+ m_FirstHandActionText.gameObject.SetActive(false);
+ m_FirstHandBindingGO.SetActive(false);
+ }
+
+ if (m_QuickActionHandExpressionLength > 1)
+ {
+ var handExpression = m_HandExpressionManager.simulatedHandExpressions[m_HandExpressionIndices[1]];
+ m_SecondHandActionText.text = handExpression.name;
+ m_SecondHandBindingText.text = GetBindingString(handExpression.toggleInput);
+ }
+ else
+ {
+ m_SecondHandActionText.gameObject.SetActive(false);
+ m_SecondHandBindingGO.SetActive(false);
+ }
+
+ if (m_QuickActionHandExpressionLength > 2)
+ {
+ var handExpression = m_HandExpressionManager.simulatedHandExpressions[m_HandExpressionIndices[2]];
+ m_ThirdHandActionText.text = handExpression.name;
+ m_ThirdHandBindingText.text = GetBindingString(handExpression.toggleInput);
+ }
+ else
+ {
+ m_ThirdHandActionText.gameObject.SetActive(false);
+ m_ThirdHandBindingGO.SetActive(false);
+ }
+
+ if (m_QuickActionHandExpressionLength > 3)
+ {
+ var handExpression = m_HandExpressionManager.simulatedHandExpressions[m_HandExpressionIndices[3]];
+ m_FourthHandActionText.text = handExpression.name;
+ m_FourthHandBindingText.text = GetBindingString(handExpression.toggleInput);
+ }
+ else
+ {
+ m_FourthHandActionText.gameObject.SetActive(false);
+ m_FourthHandBindingGO.SetActive(false);
+ }
+ }
+
+ void GetControllerQuickActionNames(ControllerInputMode inputMode, Text actionText, Text bindingText)
+ {
+ switch (inputMode)
+ {
+ case ControllerInputMode.None:
+ actionText.text = "None";
+ bindingText.text = "?";
+ break;
+ case ControllerInputMode.Trigger:
+ actionText.text = "Trigger";
+ bindingText.text = GetBindingString(m_Simulator.triggerInput);
+ break;
+ case ControllerInputMode.Grip:
+ actionText.text = "Grip";
+ bindingText.text = GetBindingString(m_Simulator.gripInput);
+ break;
+ case ControllerInputMode.PrimaryButton:
+ actionText.text = "Primary";
+ bindingText.text = GetBindingString(m_Simulator.primaryButtonInput);
+ break;
+ case ControllerInputMode.SecondaryButton:
+ actionText.text = "Secondary";
+ bindingText.text = GetBindingString(m_Simulator.secondaryButtonInput);
+ break;
+ case ControllerInputMode.Menu:
+ actionText.text = "Menu";
+ bindingText.text = GetBindingString(m_Simulator.menuInput);
+ break;
+ case ControllerInputMode.Primary2DAxisClick:
+ actionText.text = "Prim2DClick";
+ bindingText.text = GetBindingString(m_Simulator.primary2DAxisClickInput);
+ break;
+ case ControllerInputMode.Secondary2DAxisClick:
+ actionText.text = "Sec2DClick";
+ bindingText.text = GetBindingString(m_Simulator.secondary2DAxisClickInput);
+ break;
+ case ControllerInputMode.Primary2DAxisTouch:
+ actionText.text = "Prim2DTouch";
+ bindingText.text = GetBindingString(m_Simulator.primary2DAxisTouchInput);
+ break;
+ case ControllerInputMode.Secondary2DAxisTouch:
+ actionText.text = "Sec2DTouch";
+ bindingText.text = GetBindingString(m_Simulator.secondary2DAxisTouchInput);
+ break;
+ case ControllerInputMode.PrimaryTouch:
+ actionText.text = "PrimTouch";
+ bindingText.text = GetBindingString(m_Simulator.primaryTouchInput);
+ break;
+ case ControllerInputMode.SecondaryTouch:
+ actionText.text = "SecTouch";
+ bindingText.text = GetBindingString(m_Simulator.secondaryTouchInput);
+ break;
+ default:
+ Assert.IsTrue(false, $"Unhandled {nameof(inputMode)}={inputMode}.");
+ break;
+ }
+ }
+
+ static string GetBindingString(XRInputButtonReader reader)
+ {
+ if (reader == null)
+ return string.Empty;
+
+ InputAction action;
+ switch (reader.inputSourceMode)
+ {
+ case XRInputButtonReader.InputSourceMode.InputActionReference:
+ action = reader.inputActionReferencePerformed != null ? reader.inputActionReferencePerformed.action : null;
+ break;
+ case XRInputButtonReader.InputSourceMode.InputAction:
+ action = reader.inputActionPerformed;
+ break;
+ default:
+ action = null;
+ break;
+ }
+
+ return action != null ? action.GetBindingDisplayString(0) : string.Empty;
+ }
+
+ /// <summary>
+ /// See <see cref="MonoBehaviour"/>.
+ /// </summary>
+ protected void Update()
+ {
+ HandleHighlightedDevicePanels();
+ HandleHighlightedControllerActionPanels();
+ HandleHighlightedHandActionPanels();
+ HandleActiveMenus();
+ }
+
+ /// <summary>
+ /// Toggles the visibility of the input selection menu.
+ /// </summary>
+ public void OpenCloseInputSelectionMenu()
+ {
+ if (m_InputSelectionMenu.activeSelf)
+ {
+ m_ClosedInputSelectionMenu.SetActive(true);
+ m_InputSelectionMenu.SetActive(false);
+ }
+ else
+ {
+ m_ClosedInputSelectionMenu.SetActive(false);
+ m_InputSelectionMenu.SetActive(true);
+ }
+ }
+
+ /// <summary>
+ /// Toggles the visibility of for the controller actions menu.
+ /// </summary>
+ public void OpenCloseControllerActionsMenu()
+ {
+ if (m_ControllerActionsMenu.activeSelf)
+ {
+ m_ClosedControllerActionsMenu.SetActive(true);
+ m_ControllerActionsMenu.SetActive(false);
+ }
+ else
+ {
+ m_ClosedControllerActionsMenu.SetActive(false);
+ m_ControllerActionsMenu.SetActive(true);
+ }
+ }
+
+ /// <summary>
+ /// Toggles the visibility of for the hand actions menu.
+ /// </summary>
+ public void OpenCloseHandActionsMenu()
+ {
+ if (m_HandActionsMenu.activeSelf)
+ {
+ m_ClosedHandActionsMenu.SetActive(true);
+ m_HandActionsMenu.SetActive(false);
+ }
+ else
+ {
+ m_ClosedHandActionsMenu.SetActive(false);
+ m_HandActionsMenu.SetActive(true);
+ }
+ }
+
+ void HandleActiveMenus()
+ {
+ if (m_PreviousDeviceMode != m_DeviceLifecycleManager.deviceMode && !m_Simulator.manipulatingFPS)
+ {
+ if (m_Simulator.manipulatingLeftController || m_Simulator.manipulatingRightController)
+ {
+ m_PreviousHandMenuState = m_HandActionsMenu.activeSelf;
+ m_HandActionsMenu.SetActive(false);
+ m_ClosedHandActionsMenu.SetActive(false);
+
+ if (m_PreviousControllerMenuState)
+ m_ControllerActionsMenu.SetActive(true);
+ else
+ m_ClosedControllerActionsMenu.SetActive(true);
+ }
+ else if (m_Simulator.manipulatingLeftHand || m_Simulator.manipulatingRightHand)
+ {
+ m_PreviousControllerMenuState = m_ControllerActionsMenu.activeSelf;
+ m_ControllerActionsMenu.SetActive(false);
+ m_ClosedControllerActionsMenu.SetActive(false);
+
+ if (m_PreviousHandMenuState)
+ m_HandActionsMenu.SetActive(true);
+ else
+ m_ClosedHandActionsMenu.SetActive(true);
+ }
+
+ m_PreviousDeviceMode = m_DeviceLifecycleManager.deviceMode;
+ }
+
+ if (m_Simulator.manipulatingFPS && m_PreviousDeviceMode != SimulatedDeviceLifecycleManager.DeviceMode.None)
+ {
+ if (m_PreviousDeviceMode == SimulatedDeviceLifecycleManager.DeviceMode.Controller)
+ m_PreviousControllerMenuState = m_ControllerActionsMenu.activeSelf;
+ else if (m_PreviousDeviceMode == SimulatedDeviceLifecycleManager.DeviceMode.Hand)
+ m_PreviousHandMenuState = m_HandActionsMenu.activeSelf;
+
+ m_HandActionsMenu.SetActive(false);
+ m_ClosedHandActionsMenu.SetActive(false);
+ m_ControllerActionsMenu.SetActive(false);
+ m_ClosedControllerActionsMenu.SetActive(false);
+
+ m_PreviousDeviceMode = SimulatedDeviceLifecycleManager.DeviceMode.None;
+ }
+
+ if (m_ToggleActionMenu.ReadWasPerformedThisFrame())
+ {
+ if (m_Simulator.manipulatingLeftController || m_Simulator.manipulatingRightController)
+ OpenCloseControllerActionsMenu();
+ else if (m_Simulator.manipulatingLeftHand || m_Simulator.manipulatingRightHand)
+ OpenCloseHandActionsMenu();
+ }
+
+ if (m_ToggleInputSelectionMenu.ReadWasPerformedThisFrame())
+ OpenCloseInputSelectionMenu();
+ }
+
+ void HandleHighlightedDevicePanels()
+ {
+ if (m_Simulator.targetedDeviceInput != m_PreviousTargetedDeviceInput || m_PreviousDeviceMode != m_DeviceLifecycleManager.deviceMode)
+ {
+ ClearHighlightedDevicePanels();
+
+ if (m_Simulator.manipulatingFPS)
+ {
+ m_HighlightFullBodyPanel.SetActive(true);
+ return;
+ }
+
+ if (m_Simulator.manipulatingLeftController)
+ {
+ m_HighlightLeftControllerPanel.SetActive(true);
+ }
+
+ if (m_Simulator.manipulatingRightController)
+ {
+ m_HighlightRightControllerPanel.SetActive(true);
+ }
+
+ if (m_Simulator.manipulatingLeftHand)
+ {
+ m_HighlightLeftHandPanel.SetActive(true);
+ }
+
+ if (m_Simulator.manipulatingRightHand)
+ {
+ m_HighlightRightHandPanel.SetActive(true);
+ }
+
+ if (m_Simulator.manipulatingHMD)
+ {
+ m_HighlightHeadPanel.SetActive(true);
+ }
+
+ m_PreviousTargetedDeviceInput = m_Simulator.targetedDeviceInput;
+ }
+ }
+
+ void HandleHighlightedControllerActionPanels()
+ {
+ if (m_Simulator.controllerInputMode != m_PreviousControllerInputMode)
+ {
+ m_ControllerActionIndex = m_ControllerActionIndex < m_Simulator.quickActionControllerInputModes.Count - 1 ? m_ControllerActionIndex + 1 : 0;
+ m_ControllerActionHighlightPanel.SetActive(true);
+
+ if (m_ControllerActionIndex == 0)
+ {
+ m_ControllerActionHighlightPanel.transform.position = m_FirstControllerActionText.transform.position;
+ }
+ else if (m_ControllerActionIndex == 1)
+ {
+ m_ControllerActionHighlightPanel.transform.position = m_SecondControllerActionText.transform.position;
+ }
+ else if (m_ControllerActionIndex == 2)
+ {
+ m_ControllerActionHighlightPanel.transform.position = m_ThirdControllerActionText.transform.position;
+ }
+ else if (m_ControllerActionIndex == 3)
+ {
+ m_ControllerActionHighlightPanel.transform.position = m_FourthControllerActionText.transform.position;
+ }
+ else
+ {
+ m_ControllerActionHighlightPanel.SetActive(false);
+ }
+
+ m_PreviousControllerInputMode = m_Simulator.controllerInputMode;
+ }
+ }
+
+ void HandleHighlightedHandActionPanels()
+ {
+ if (m_Simulator.currentHandExpression != m_PreviousHandExpression)
+ {
+ m_HandActionIndex = m_HandActionIndex < m_QuickActionHandExpressionLength - 1 ? m_HandActionIndex + 1 : 0;
+ m_HandActionHighlightPanel.SetActive(true);
+
+ if (m_HandActionIndex == 0)
+ {
+ m_HandActionHighlightPanel.transform.position = m_FirstHandActionText.transform.position;
+ }
+ else if (m_HandActionIndex == 1)
+ {
+ m_HandActionHighlightPanel.transform.position = m_SecondHandActionText.transform.position;
+ }
+ else if (m_HandActionIndex == 2)
+ {
+ m_HandActionHighlightPanel.transform.position = m_ThirdHandActionText.transform.position;
+ }
+ else if (m_HandActionIndex == 3)
+ {
+ m_HandActionHighlightPanel.transform.position = m_FourthHandActionText.transform.position;
+ }
+ else
+ {
+ m_HandActionHighlightPanel.SetActive(false);
+ }
+
+ m_PreviousHandExpression = m_Simulator.currentHandExpression;
+ }
+ }
+
+ void ClearHighlightedDevicePanels()
+ {
+ m_HighlightFullBodyPanel.SetActive(false);
+ m_HighlightLeftControllerPanel.SetActive(false);
+ m_HighlightRightControllerPanel.SetActive(false);
+ m_HighlightLeftHandPanel.SetActive(false);
+ m_HighlightRightHandPanel.SetActive(false);
+ m_HighlightHeadPanel.SetActive(false);
+ }
+ }
+}
diff --git a/Assets/Samples/XR Interaction Toolkit/3.1.2/XR Device Simulator/XRInteractionSimulator/Scripts/XRInteractionSimulatorPlayModeMenu.cs.meta b/Assets/Samples/XR Interaction Toolkit/3.1.2/XR Device Simulator/XRInteractionSimulator/Scripts/XRInteractionSimulatorPlayModeMenu.cs.meta
new file mode 100644
index 0000000..2e1657e
--- /dev/null
+++ b/Assets/Samples/XR Interaction Toolkit/3.1.2/XR Device Simulator/XRInteractionSimulator/Scripts/XRInteractionSimulatorPlayModeMenu.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: cc8177f906fb249e0aaf332f7afba347
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: