// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) VRMADA, All rights reserved. // // -------------------------------------------------------------------------------------------------------------------- using UltimateXR.Core; using UltimateXR.Core.Components; using UnityEngine; using UnityEngine.UI; namespace UltimateXR.Devices.DebugPanels { /// /// UI Widget for a two-axis input element in a VR input controller. Examples are joysticks, trackpads... /// public class UxrDebugInput2dUI : UxrComponent { #region Inspector Properties/Serialized Fields [SerializeField] private UxrControllerInput _controllerInput; [SerializeField] private UxrHandSide _hand; [SerializeField] private UxrInput2D _target; [SerializeField] private Text _name; [SerializeField] private RectTransform _cursor; [SerializeField] private float _coordAmplitude; #endregion #region Public Types & Data /// /// Gets the controller to monitor for input. /// public UxrControllerInput TargetController { get => _controllerInput; set => _controllerInput = value; } /// /// Gets the hand to monitor for input. /// public UxrHandSide TargetHand { get => _hand; set => _hand = value; } /// /// Gets the two-axis element to monitor for input. /// public UxrInput2D Target { get => _target; set => _target = value; } #endregion #region Unity /// /// Updates the widget information. /// private void Update() { _name.text = $"{_hand} {_target}"; if (_controllerInput != null) { _cursor.anchoredPosition = Vector2.Scale(Vector2.one * _coordAmplitude, _controllerInput.GetInput2D(_hand, _target, true)); } } #endregion } }