Skip to content

Commit

Permalink
v1.0.0-preview.2: Updated docs and some variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
Uralstech committed Dec 8, 2024
1 parent e53696b commit badf592
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ public class XRKeyboardManager : Singleton<XRKeyboardManager>
/// </summary>
[Header("Callbacks")]
[Tooltip("Called when the keyboard is created.")]
public UnityEvent OnKeyboardCreated = new();
[FormerlySerializedAs("OnKeyboardCreated")] public UnityEvent OnKeyboardShown = new();

/// <summary>
/// Called when the keyboard is destroyed.
/// </summary>
[Tooltip("Called when the keyboard is destroyed.")]
public UnityEvent OnKeyboardDestroyed = new();
[FormerlySerializedAs("OnKeyboardDestroyed")] public UnityEvent OnKeyboardHidden = new();

/// <summary>
/// The current instance of the <see cref="OVRVirtualKeyboard"/>.
Expand Down Expand Up @@ -172,7 +172,7 @@ private void ShowKeyboard()
SimpleMovementController.Instance.MovementEnabled = false;

SetHandMaterial(TypingHandMaterial);
OnKeyboardCreated.Invoke();
OnKeyboardShown.Invoke();
}

private void HideKeyboard()
Expand All @@ -191,7 +191,7 @@ private void HideKeyboard()
SimpleMovementController.Instance.MovementEnabled = true;

SetHandMaterial(NormalHandMaterial);
OnKeyboardDestroyed.Invoke();
OnKeyboardHidden.Invoke();
}

/// <summary>
Expand All @@ -213,7 +213,7 @@ public void SetListener(OVRVirtualKeyboard.ITextHandler listener)
/// <summary>
/// Unbinds the given object from the keyboard.
/// </summary>
/// <param name="listener">The object to unbind from the keyboard.</param>
/// <param name="listener">The object to unbind from the keyboard. Must be the same as <see cref="CurrentListener"/>.</param>
public void RemoveListener(OVRVirtualKeyboard.ITextHandler listener)
{
if (!ReferenceEquals(CurrentListener, listener) || listener == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private void LateUpdate()
|| verticalSeperationDistance < _adjustedLowerHeightOffset
|| angle > RotationDelayAngle)
{
_targetPosition = _playerHeadTransform.position + Quaternion.Euler(0f, _playerHeadTransform.eulerAngles.y, 0f) * Vector3.forward * DistanceOffset + Vector3.up * HeightOffset;
_targetPosition = _playerHeadTransform.position + (Quaternion.Euler(0f, _playerHeadTransform.eulerAngles.y, 0f) * Vector3.forward * DistanceOffset) + (Vector3.up * HeightOffset);
_targetRotation = Quaternion.Euler(0f, _playerHeadTransform.rotation.eulerAngles.y, 0f) * Quaternion.Euler(RotationOffset);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UnityEngine;
using UnityEngine.Serialization;
using Uralstech.Utils.Singleton;

namespace Uralstech.UXR.Utilities
Expand All @@ -12,18 +13,19 @@ public class SimpleMovementController : DontCreateNewSingleton<SimpleMovementCon
/// <summary>
/// Use this boolean to toggle movement.
/// </summary>
[Tooltip("Boolean to toggle movement.")]
public bool MovementEnabled = true;

/// <summary>
/// The movement speed.
/// </summary>
[Tooltip("The movement speed.")]
public float MoveSpeed = 3f;
[FormerlySerializedAs("MoveSpeed")] public float MovementSpeed = 3f;

/// <summary>
/// Snap turn angle.
/// </summary>
[Tooltip("Snap turn angle")]
[Tooltip("Snap turn angle.")]
public float RotationSnapAngle = 30f;

private Transform _playerHeadTransform;
Expand Down Expand Up @@ -51,7 +53,7 @@ private void FixedUpdate()
{
Vector2 primaryThumbstick = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick);
Vector3 moveDirection = ((_playerHeadTransform.forward * primaryThumbstick.y) + (_playerHeadTransform.right * primaryThumbstick.x)).normalized;
_rigidbody.linearVelocity = new Vector3(moveDirection.x * MoveSpeed, _rigidbody.linearVelocity.y, moveDirection.z * MoveSpeed);
_rigidbody.linearVelocity = new Vector3(moveDirection.x * MovementSpeed, _rigidbody.linearVelocity.y, moveDirection.z * MovementSpeed);
}

Vector2 secondaryThumbstick = OVRInput.Get(OVRInput.Axis2D.SecondaryThumbstick);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class TextInputField : Selectable, IPointerClickHandler, OVRVirtualKeyboa
public Action<string> OnTextChanged { get; set; }

/// <inheritdoc/>
[field: SerializeField] public bool SubmitOnEnter { get; set; } = true;
[field: SerializeField] public bool SubmitOnEnter { get; set; } = true;

/// <inheritdoc/>
public bool IsFocused { get; private set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,42 @@

namespace Uralstech.UXR.Utilities
{
/// <summary>
/// Sister-script to <see cref="TextInputField"/> which adds support for voice typing through Meta's Voice SDK.
/// </summary>
/// <remarks>
/// Requires a <see cref="DictationService"/> somewhere in the scene.
/// </remarks>
[AddComponentMenu("Uralstech/UXR/Utilities/UI/Text Input Field Voice Handler"), RequireComponent(typeof(TextInputField))]
public class TextInputFieldVoiceHandler : MonoBehaviour
{
/// <summary>
/// Is the user currently voice typing?
/// </summary>
public bool IsRecording { get; private set; } = false;

/// <summary>
/// The button to toggle voice typing.
/// </summary>
[Tooltip("The button to toggle voice typing.")]
public Button ToggleButton;

/// <summary>
/// Optional, the icon for <see cref="ToggleButton"/> that will be changed based on the current recording state.
/// </summary>
[Tooltip("Optional, the icon for ToggleButton that will be changed based on the current recording state.")]
public Image ToggleButtonIcon;

/// <summary>
/// Optional, icon to set for <see cref="ToggleButtonIcon"/> while not recording the user's audio.
/// </summary>
[Tooltip("Optional, icon to set for ToggleButtonIcon while not recording the user's audio.")]
public Sprite StartRecordingIcon;

/// <summary>
/// Optional, icon to set for <see cref="ToggleButtonIcon"/> while recording the user's audio.
/// </summary>
[Tooltip("Optional, icon to set for ToggleButtonIcon while recording the user's audio.")]
public Sprite StopRecordingIcon;

private TextInputField _inputField;
Expand All @@ -24,7 +51,9 @@ public class TextInputFieldVoiceHandler : MonoBehaviour
private void Start()
{
ToggleButton.onClick.AddListener(OnToggleRecording);
ToggleButtonIcon.sprite = StartRecordingIcon;

if (ToggleButtonIcon != null)
ToggleButtonIcon.sprite = StartRecordingIcon;

_dictation = FindAnyObjectByType<DictationService>();
_inputField = GetComponent<TextInputField>();
Expand Down Expand Up @@ -67,9 +96,11 @@ private void StartRecording()

Debug.Log($"{nameof(TextInputFieldVoiceHandler)}: Starting dictation.");
_previousPartialTranscription = string.Empty;
ToggleButtonIcon.sprite = StopRecordingIcon;
IsRecording = true;

if (ToggleButtonIcon != null)
ToggleButtonIcon.sprite = StopRecordingIcon;

VoiceServiceRequestEvents events = new();
events.OnFullTranscription.AddListener(OnFullTranscription);
events.OnComplete.AddListener(_ => StopRecording());
Expand All @@ -79,9 +110,11 @@ private void StartRecording()
private void StopRecording()
{
Debug.Log($"{nameof(TextInputFieldVoiceHandler)}: Stopping dictation.");
ToggleButtonIcon.sprite = StartRecordingIcon;
IsRecording = false;

if (ToggleButtonIcon != null)
ToggleButtonIcon.sprite = StartRecordingIcon;

if (_dictation.Active)
_dictation.Deactivate();
}
Expand All @@ -97,7 +130,7 @@ private void OnPartialTranscription(string transcription, bool overrideRecording

_previousPartialTranscription = transcription;
}

private void OnFullTranscription(string transcription)
{
OnPartialTranscription(transcription, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"displayName": "UXR.Utilities",
"description": "Random helper scripts I made for Meta Quest XR projects.",
"keywords": [ ],
"version": "1.0.0-preview.1",
"version": "1.0.0-preview.2",
"unity": "6000.0",
"hideInEditor": false,
"documentationUrl": "https://uralstech.github.io/UXR.Utilities/",
Expand Down
3 changes: 3 additions & 0 deletions UXR.Utilities/Packages/manifest.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
{
"dependencies": {
"com.meta.xr.sdk.interaction": "71.0.0",
"com.meta.xr.sdk.interaction.ovr": "71.0.0",
"com.unity.ide.visualstudio": "2.0.22",
"com.unity.test-framework": "1.4.5",
"com.unity.xr.oculus": "4.4.0",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
"com.unity.modules.animation": "1.0.0",
"com.unity.modules.assetbundle": "1.0.0",
"com.unity.modules.audio": "1.0.0",
"com.unity.modules.imageconversion": "1.0.0",
"com.unity.modules.particlesystem": "1.0.0",
"com.unity.modules.physics": "1.0.0",
"com.unity.modules.physics2d": "1.0.0",
"com.unity.modules.unitywebrequest": "1.0.0",
Expand Down
22 changes: 22 additions & 0 deletions UXR.Utilities/Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
},
"url": "https://packages.unity.com"
},
"com.meta.xr.sdk.interaction.ovr": {
"version": "71.0.0",
"depth": 0,
"source": "registry",
"dependencies": {
"com.meta.xr.sdk.core": "71.0.0",
"com.meta.xr.sdk.interaction": "71.0.0"
},
"url": "https://packages.unity.com"
},
"com.meta.xr.sdk.voice": {
"version": "71.0.0",
"depth": 1,
Expand Down Expand Up @@ -117,6 +127,12 @@
"com.unity.ugui": "2.0.0"
}
},
"com.unity.modules.ai": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.androidjni": {
"version": "1.0.0",
"depth": 0,
Expand Down Expand Up @@ -159,6 +175,12 @@
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.particlesystem": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.physics": {
"version": "1.0.0",
"depth": 0,
Expand Down

0 comments on commit badf592

Please sign in to comment.