// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. // Input simulation service is only built on editor platforms using System; using UnityEngine; namespace Microsoft.MixedReality.Toolkit.Input { /// /// A row of indicator buttons to control input simulation features. /// [Serializable] [AddComponentMenu("Scripts/MRTK/SDK/InputSimulationIndicators")] public class InputSimulationIndicators : MonoBehaviour { /// /// Component displaying the left hand icon. /// public UnityEngine.UI.Image imageHandLeft = null; /// /// Component displaying the right hand icon. /// public UnityEngine.UI.Image imageHandRight = null; /// /// Icon for left hand when under user control. /// public Sprite iconHandActiveLeft = null; /// /// Icon for right hand when under user control. /// public Sprite iconHandActiveRight = null; /// /// Icon for left hand when visible but not actively controlled. /// public Sprite iconHandIdleLeft = null; /// /// Icon for right hand when visible but not actively controlled. /// public Sprite iconHandIdleRight = null; /// /// Icon for left hand when untracked. /// public Sprite iconHandUntrackedLeft = null; /// /// Icon for right hand when untracked. /// public Sprite iconHandUntrackedRight = null; #if UNITY_EDITOR private IInputSimulationService inputSimService = null; private IInputSimulationService InputSimService { get { if (inputSimService == null) { inputSimService = CoreServices.GetInputSystemDataProvider(); } return inputSimService; } } /// /// Updates the left and right hand images according to the tracked state /// private void Update() { if (imageHandLeft) { Sprite iconHandLeft; if (InputSimService.IsSimulatingControllerLeft) { iconHandLeft = iconHandActiveLeft; } else if (InputSimService.HandDataLeft.IsTracked) { iconHandLeft = iconHandIdleLeft; } else { iconHandLeft = iconHandUntrackedLeft; } imageHandLeft.sprite = iconHandLeft; } if (imageHandRight) { Sprite iconHandRight; if (InputSimService.IsSimulatingControllerRight) { iconHandRight = iconHandActiveRight; } else if (InputSimService.HandDataRight.IsTracked) { iconHandRight = iconHandIdleRight; } else { iconHandRight = iconHandUntrackedRight; } imageHandRight.sprite = iconHandRight; } } /// /// Toggle permanent visibility of the left hand. /// public void ToggleLeftHand() { InputSimService.IsAlwaysVisibleControllerLeft = !InputSimService.IsAlwaysVisibleControllerLeft; } /// /// Toggle permanent visibility of the right hand. /// public void ToggleRightHand() { InputSimService.IsAlwaysVisibleControllerRight = !InputSimService.IsAlwaysVisibleControllerRight; } /// /// Reset the state of the left hand to default. /// public void ResetLeftHand() { InputSimService.ResetControllerLeft(); } /// /// Reset the state of the right hand to default. /// public void ResetRightHand() { InputSimService.ResetControllerRight(); } #endif } }