Add ultimate xr

This commit is contained in:
2024-08-06 21:58:35 +02:00
parent 864033bf10
commit 7165bacd9d
3952 changed files with 2162037 additions and 35 deletions

View File

@@ -0,0 +1,256 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="UxrDebugControllerPanel.cs" company="VRMADA">
// Copyright (c) VRMADA, All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
using System;
using UltimateXR.Avatar;
using UltimateXR.Core;
using UltimateXR.Core.Components;
using UltimateXR.Extensions.Unity;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.XR;
namespace UltimateXR.Devices.DebugPanels
{
/// <summary>
/// UI panel showing all information related to the current main VR input device.
/// </summary>
public class UxrDebugControllerPanel : UxrComponent
{
#region Inspector Properties/Serialized Fields
[SerializeField] private bool _blinkButtonsOnInput;
[SerializeField] private Text _textDeviceName;
[SerializeField] private Text _textControllerNames;
[SerializeField] private GameObject _containerControllerNames;
[SerializeField] private GameObject _panelInput1D;
[SerializeField] private GameObject _panelInput2D;
[SerializeField] private GameObject _panelInputButtons;
[SerializeField] private GameObject _prefabWidget1D;
[SerializeField] private GameObject _prefabWidget2D;
[SerializeField] private GameObject _prefabWidgetButton;
#endregion
#region Unity
/// <summary>
/// Checks if the current input device changed in order to regenerate the panel.
/// </summary>
private void Update()
{
UxrAvatar avatar = UxrAvatar.LocalAvatar;
UxrControllerInput controllerInput = avatar != null ? avatar.ControllerInput : null;
if (avatar != _avatar || controllerInput != _avatarControllerInput)
{
// Unsubscribe from the current avatar controller events.
if (_avatarControllerInput != null)
{
_avatarControllerInput.ButtonStateChanged -= ControllerInput_ButtonStateChanged;
_avatarControllerInput.Input1DChanged -= ControllerInput_Input1DChanged;
_avatarControllerInput.Input2DChanged -= ControllerInput_Input2DChanged;
}
// Cache the new avatar and regenerate the panel.
_avatar = avatar;
_avatarControllerInput = controllerInput;
RegeneratePanel();
// Subscribe to the input events to update the input UI widgets.
if (_avatarControllerInput != null)
{
_avatarControllerInput.ButtonStateChanged += ControllerInput_ButtonStateChanged;
_avatarControllerInput.Input1DChanged += ControllerInput_Input1DChanged;
_avatarControllerInput.Input2DChanged += ControllerInput_Input2DChanged;
}
}
// This one can change each frame, depending on controllers getting connected/disconnected
UpdateControllerStrings();
}
#endregion
#region Event Handling Methods
/// <summary>
/// Called whenever a VR controller button state changed.
/// </summary>
/// <param name="sender">The controller that generated the event</param>
/// <param name="e">Event arguments</param>
private void ControllerInput_ButtonStateChanged(object sender, UxrInputButtonEventArgs e)
{
UxrControllerInput controllerInput = (UxrControllerInput)sender;
UxrControllerElements controllerElement = UxrControllerInput.ButtonToControllerElement(e.Button);
bool allControllerElementsBlinking = controllerInput.AreAllControllerElementsBlinking(e.HandSide, controllerElement);
if (_blinkButtonsOnInput && controllerElement != UxrControllerElements.None && allControllerElementsBlinking == false)
{
_avatarControllerInput.StartControllerElementsBlinking(e.HandSide, controllerElement, Color.white, 5, 2.0f);
}
}
/// <summary>
/// Called whenever a VR controller single-axis value changed.
/// </summary>
/// <param name="sender">The controller that generated the event</param>
/// <param name="e">Event arguments</param>
private void ControllerInput_Input1DChanged(object sender, UxrInput1DEventArgs e)
{
UxrControllerInput controllerInput = (UxrControllerInput)sender;
UxrControllerElements controllerElement = UxrControllerInput.Input1DToControllerElement(e.Target);
bool allControllerElementsBlinking = controllerInput.AreAllControllerElementsBlinking(e.HandSide, controllerElement);
if (_blinkButtonsOnInput && controllerElement != UxrControllerElements.None && allControllerElementsBlinking == false)
{
_avatarControllerInput.StartControllerElementsBlinking(e.HandSide, controllerElement, Color.white, 5, 2.0f);
}
}
/// <summary>
/// Called whenever a VR controller two-axis value changed.
/// </summary>
/// <param name="sender">The controller that generated the event</param>
/// <param name="e">Event arguments</param>
private void ControllerInput_Input2DChanged(object sender, UxrInput2DEventArgs e)
{
UxrControllerInput controllerInput = (UxrControllerInput)sender;
UxrControllerElements controllerElement = UxrControllerInput.Input2DToControllerElement(e.Target);
bool allControllerElementsBlinking = controllerInput.AreAllControllerElementsBlinking(e.HandSide, controllerElement);
if (_blinkButtonsOnInput && controllerElement != UxrControllerElements.None && allControllerElementsBlinking == false)
{
_avatarControllerInput.StartControllerElementsBlinking(e.HandSide, controllerElement, Color.white, 5, 2.0f);
}
}
#endregion
#region Private Methods
/// <summary>
/// Updates the controller names shown.
/// </summary>
private void UpdateControllerStrings()
{
if (_avatar && _avatarControllerInput)
{
string leftName = _avatarControllerInput.LeftControllerName ?? NoController;
string rightName = _avatarControllerInput.RightControllerName ?? NoController;
_containerControllerNames.SetActive(!string.IsNullOrEmpty(leftName) || !string.IsNullOrEmpty(rightName));
if (_avatarControllerInput.SetupType == UxrControllerSetupType.Single)
{
// Single controller setup. Both sides will return the same name.
_textControllerNames.text = $"Controller: {leftName}";
}
else if (_avatarControllerInput.SetupType == UxrControllerSetupType.Dual)
{
// Dual controller setup.
_textControllerNames.text = $"Left controller: {leftName}, right controller: {rightName}";
}
}
}
/// <summary>
/// Re-generates the panel adding widgets for all input elements present in the current controller(s).
/// </summary>
private void RegeneratePanel()
{
_panelInput1D.transform.DestroyAllChildren();
_panelInput2D.transform.DestroyAllChildren();
_panelInputButtons.transform.DestroyAllChildren();
if (_avatar == null || _avatarControllerInput == null)
{
_textDeviceName.text = $"No {nameof(UxrAvatar)} with an active {nameof(UxrControllerInput)} component found";
return;
}
// Device strings
_textDeviceName.text = $"Device: {UxrTrackingDevice.HeadsetDeviceName}, Loaded: {XRSettings.loadedDeviceName}";
UpdateControllerStrings();
// Dynamically add all current devices' supported Controllers1D elements to the UI
foreach (UxrInput1D input1D in Enum.GetValues(typeof(UxrInput1D)))
{
UxrControllerElements controllerElement = UxrControllerInput.Input1DToControllerElement(input1D);
foreach (UxrHandSide handSide in Enum.GetValues(typeof(UxrHandSide)))
{
if (controllerElement != UxrControllerElements.None && _avatarControllerInput.HasControllerElements(handSide, controllerElement))
{
GameObject newWidget = Instantiate(_prefabWidget1D, _panelInput1D.transform);
UxrDebugInput1dUI uiInput1d = newWidget.GetComponent<UxrDebugInput1dUI>();
uiInput1d.TargetController = _avatarControllerInput;
uiInput1d.TargetHand = handSide;
uiInput1d.Target = input1D;
}
}
}
// Dynamically add all current devices' supported Controllers2D elements to the UI
foreach (UxrInput2D input2D in Enum.GetValues(typeof(UxrInput2D)))
{
UxrControllerElements controllerElement = UxrControllerInput.Input2DToControllerElement(input2D);
foreach (UxrHandSide handSide in Enum.GetValues(typeof(UxrHandSide)))
{
if (controllerElement != UxrControllerElements.None && _avatarControllerInput.HasControllerElements(handSide, controllerElement))
{
GameObject newWidget = Instantiate(_prefabWidget2D, _panelInput2D.transform);
UxrDebugInput2dUI uiInput2d = newWidget.GetComponent<UxrDebugInput2dUI>();
uiInput2d.TargetController = _avatarControllerInput;
uiInput2d.TargetHand = handSide;
uiInput2d.Target = input2D;
}
}
}
// Dynamically add all current devices' supported button elements to the UI
foreach (UxrInputButtons button in Enum.GetValues(typeof(UxrInputButtons)))
{
UxrControllerElements controllerElement = UxrControllerInput.ButtonToControllerElement(button);
foreach (UxrHandSide handSide in Enum.GetValues(typeof(UxrHandSide)))
{
if (controllerElement != UxrControllerElements.None && _avatarControllerInput.HasControllerElements(handSide, controllerElement))
{
GameObject newWidget = Instantiate(_prefabWidgetButton, _panelInputButtons.transform);
UxrDebugInputButtonUI uiButton = newWidget.GetComponent<UxrDebugInputButtonUI>();
uiButton.TargetController = _avatarControllerInput;
uiButton.TargetHand = handSide;
uiButton.Target = button;
}
}
}
}
#endregion
#region Private Types & Data
private const string NoController = "None";
private UxrAvatar _avatar;
private UxrControllerInput _avatarControllerInput;
#endregion
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 1b8190b6241a8e44b82f8b0d6e2de329
timeCreated: 1503571160
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,77 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="UxrDebugInput1dUI.cs" company="VRMADA">
// Copyright (c) VRMADA, All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
using UltimateXR.Core;
using UltimateXR.Core.Components;
using UnityEngine;
using UnityEngine.UI;
namespace UltimateXR.Devices.DebugPanels
{
/// <summary>
/// UI Widget for a single-axis input element in a VR input controller. Examples are trigger buttons, grip buttons...
/// </summary>
public class UxrDebugInput1dUI : UxrComponent
{
#region Inspector Properties/Serialized Fields
[SerializeField] private UxrControllerInput _controllerInput;
[SerializeField] private UxrHandSide _hand;
[SerializeField] private UxrInput1D _target;
[SerializeField] private Text _name;
[SerializeField] private RectTransform _cursor;
[SerializeField] private float _coordAmplitude;
#endregion
#region Public Types & Data
/// <summary>
/// Gets or sets the controller(s) to monitor for input.
/// </summary>
public UxrControllerInput TargetController
{
get => _controllerInput;
set => _controllerInput = value;
}
/// <summary>
/// Gets or sets the hand to monitor for input.
/// </summary>
public UxrHandSide TargetHand
{
get => _hand;
set => _hand = value;
}
/// <summary>
/// Gets or sets the single-axis element to monitor.
/// </summary>
public UxrInput1D Target
{
get => _target;
set => _target = value;
}
#endregion
#region Unity
/// <summary>
/// Updates the widget information.
/// </summary>
private void Update()
{
_name.text = $"{_hand} {_target}";
if (_controllerInput != null)
{
_cursor.anchoredPosition = new Vector2(0.0f, 1.0f) * (_coordAmplitude * _controllerInput.GetInput1D(_hand, _target, true));
}
}
#endregion
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 518e7160296b55242853ce5d0cd3edae
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,77 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="UxrDebugInput2dUI.cs" company="VRMADA">
// Copyright (c) VRMADA, All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
using UltimateXR.Core;
using UltimateXR.Core.Components;
using UnityEngine;
using UnityEngine.UI;
namespace UltimateXR.Devices.DebugPanels
{
/// <summary>
/// UI Widget for a two-axis input element in a VR input controller. Examples are joysticks, trackpads...
/// </summary>
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
/// <summary>
/// Gets the controller to monitor for input.
/// </summary>
public UxrControllerInput TargetController
{
get => _controllerInput;
set => _controllerInput = value;
}
/// <summary>
/// Gets the hand to monitor for input.
/// </summary>
public UxrHandSide TargetHand
{
get => _hand;
set => _hand = value;
}
/// <summary>
/// Gets the two-axis element to monitor for input.
/// </summary>
public UxrInput2D Target
{
get => _target;
set => _target = value;
}
#endregion
#region Unity
/// <summary>
/// Updates the widget information.
/// </summary>
private void Update()
{
_name.text = $"{_hand} {_target}";
if (_controllerInput != null)
{
_cursor.anchoredPosition = Vector2.Scale(Vector2.one * _coordAmplitude, _controllerInput.GetInput2D(_hand, _target, true));
}
}
#endregion
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 156df0def5d48a3489e870c7fb9a1243
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,124 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="UxrDebugInputButtonUI.cs" company="VRMADA">
// Copyright (c) VRMADA, All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
using UltimateXR.Core;
using UltimateXR.Core.Components;
using UnityEngine;
using UnityEngine.UI;
namespace UltimateXR.Devices.DebugPanels
{
/// <summary>
/// UI Widget for a button in a VR input controller.
/// </summary>
public class UxrDebugInputButtonUI : UxrComponent
{
#region Inspector Properties/Serialized Fields
[SerializeField] private UxrControllerInput _controllerInput;
[SerializeField] private UxrHandSide _hand;
[SerializeField] private UxrInputButtons _button;
[SerializeField] private Text _name;
[SerializeField] private Image _imagePressing;
[SerializeField] private Image _imagePressDown;
[SerializeField] private Image _imagePressUp;
[SerializeField] private Image _imageTouching;
[SerializeField] private Image _imageTouchDown;
[SerializeField] private Image _imageTouchUp;
[SerializeField] private Color _colorEnabled;
[SerializeField] private Color _colorDisabled;
[SerializeField] private float _secondsUpAndDownEnabled = 0.1f;
#endregion
#region Public Types & Data
/// <summary>
/// Gets the controller to monitor for input.
/// </summary>
public UxrControllerInput TargetController
{
get => _controllerInput;
set => _controllerInput = value;
}
/// <summary>
/// Gets the hand to monitor for input.
/// </summary>
public UxrHandSide TargetHand
{
get => _hand;
set => _hand = value;
}
/// <summary>
/// Gets the button to monitor for input.
/// </summary>
public UxrInputButtons Target
{
get => _button;
set => _button = value;
}
#endregion
#region Unity
/// <summary>
/// Updates the widget information.
/// </summary>
private void Update()
{
_name.text = $"{_hand} {_button}";
if (_controllerInput != null)
{
_pressDownTimer -= Time.deltaTime;
_pressUpTimer -= Time.deltaTime;
_touchDownTimer -= Time.deltaTime;
_touchUpTimer -= Time.deltaTime;
if (_controllerInput.GetButtonsPressDown(_hand, _button, true))
{
_pressDownTimer = _secondsUpAndDownEnabled;
}
if (_controllerInput.GetButtonsPressUp(_hand, _button, true))
{
_pressUpTimer = _secondsUpAndDownEnabled;
}
if (_controllerInput.GetButtonsTouchDown(_hand, _button, true))
{
_touchDownTimer = _secondsUpAndDownEnabled;
}
if (_controllerInput.GetButtonsTouchUp(_hand, _button, true))
{
_touchUpTimer = _secondsUpAndDownEnabled;
}
_imagePressing.color = _controllerInput.GetButtonsPress(_hand, _button, true) ? _colorEnabled : _colorDisabled;
_imageTouching.color = _controllerInput.GetButtonsTouch(_hand, _button, true) ? _colorEnabled : _colorDisabled;
_imagePressDown.color = _pressDownTimer > 0.0f ? _colorEnabled : _colorDisabled;
_imagePressUp.color = _pressUpTimer > 0.0f ? _colorEnabled : _colorDisabled;
_imageTouchDown.color = _touchDownTimer > 0.0f ? _colorEnabled : _colorDisabled;
_imageTouchUp.color = _touchUpTimer > 0.0f ? _colorEnabled : _colorDisabled;
}
}
#endregion
#region Private Types & Data
private float _pressDownTimer = -1.0f;
private float _pressUpTimer = -1.0f;
private float _touchDownTimer = -1.0f;
private float _touchUpTimer = -1.0f;
#endregion
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 29e64a41519e9de4096778ead33f9a7d
timeCreated: 1503573723
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: