Add ultimate xr
This commit is contained in:
48
Assets/UltimateXR/Runtime/Scripts/Audio/UxrAudioBoxVolume.cs
Normal file
48
Assets/UltimateXR/Runtime/Scripts/Audio/UxrAudioBoxVolume.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="UxrAudioBoxVolume.cs" company="VRMADA">
|
||||
// Copyright (c) VRMADA, All rights reserved.
|
||||
// </copyright>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
using System.Linq;
|
||||
using UltimateXR.Avatar;
|
||||
using UltimateXR.Core.Components;
|
||||
using UltimateXR.Extensions.System.Collections;
|
||||
using UltimateXR.Extensions.Unity.Math;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UltimateXR.Audio
|
||||
{
|
||||
/// <summary>
|
||||
/// Component that allows to define inside and outside volumes for different audio sources.
|
||||
/// </summary>
|
||||
public class UxrAudioBoxVolume : UxrComponent
|
||||
{
|
||||
#region Inspector Properties/Serialized Fields
|
||||
|
||||
[SerializeField] private AudioSource[] _audioSources;
|
||||
[SerializeField] private BoxCollider[] _boxVolumes;
|
||||
[SerializeField] private float _volumeWhenOutside = 1.0f;
|
||||
[SerializeField] private float _volumeWhenInside = 0.5f;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Unity
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether the avatar is inside any of the box colliders and adjusts the volumes accordingly.
|
||||
/// </summary>
|
||||
private void Update()
|
||||
{
|
||||
if (UxrAvatar.LocalAvatar == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool isInside = _boxVolumes.Any(boxCollider => UxrAvatar.LocalAvatar.CameraPosition.IsInsideBox(boxCollider));
|
||||
|
||||
_audioSources.ForEach(a => a.volume = isInside ? _volumeWhenInside : _volumeWhenOutside);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d8bc7c0c8f6bf2e4badd58f768290c7c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
125
Assets/UltimateXR/Runtime/Scripts/Audio/UxrAudioManipulation.cs
Normal file
125
Assets/UltimateXR/Runtime/Scripts/Audio/UxrAudioManipulation.cs
Normal file
@@ -0,0 +1,125 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="UxrAudioManipulation.cs" company="VRMADA">
|
||||
// Copyright (c) VRMADA, All rights reserved.
|
||||
// </copyright>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
using UltimateXR.Avatar;
|
||||
using UltimateXR.Core.Components;
|
||||
using UltimateXR.Manipulation;
|
||||
using UnityEngine;
|
||||
|
||||
#pragma warning disable 414 // Disable warnings due to unused values
|
||||
|
||||
namespace UltimateXR.Audio
|
||||
{
|
||||
/// <summary>
|
||||
/// Component that enables to play audio depending on the grab and manipulation events of the
|
||||
/// <see cref="UxrGrabbableObject" /> in the same <see cref="GameObject" />.
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(UxrGrabbableObject))]
|
||||
public class UxrAudioManipulation : UxrComponent
|
||||
{
|
||||
#region Inspector Properties/Serialized Fields
|
||||
|
||||
[Header("Events:")] [SerializeField] private UxrAudioSample _audioOnGrab = new UxrAudioSample();
|
||||
[SerializeField] private UxrAudioSample _audioOnPlace = new UxrAudioSample();
|
||||
[SerializeField] private UxrAudioSample _audioOnRelease = new UxrAudioSample();
|
||||
|
||||
[Header("Continuous Manipulation:")] [SerializeField] private bool _continuousManipulationAudio;
|
||||
[SerializeField] private AudioClip _audioLoopClip;
|
||||
[SerializeField] [Range(0, 1)] private float _minVolume = 0.3f;
|
||||
[SerializeField] [Range(0, 1)] private float _maxVolume = 1.0f;
|
||||
[SerializeField] private float _minFrequency = 1.0f;
|
||||
[SerializeField] private float _maxFrequency = 1.0f;
|
||||
[SerializeField] private float _minSpeed = 0.01f;
|
||||
[SerializeField] private float _maxSpeed = 1.0f;
|
||||
[SerializeField] private float _minAngularSpeed = 1.0f;
|
||||
[SerializeField] private float _maxAngularSpeed = 1800.0f;
|
||||
[SerializeField] private bool _useExternalRigidbody;
|
||||
[SerializeField] private Rigidbody _externalRigidbody;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Types & Data
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="UxrGrabbableObject" /> component in the same <see cref="GameObject" />.
|
||||
/// </summary>
|
||||
public UxrGrabbableObject GrabbableObject => GetCachedComponent<UxrGrabbableObject>();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Unity
|
||||
|
||||
/// <summary>
|
||||
/// Subscribes to manipulation events.
|
||||
/// </summary>
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
|
||||
GrabbableObject.Grabbed += Object_Grabbed;
|
||||
GrabbableObject.Placed += Object_Placed;
|
||||
GrabbableObject.Released += Object_Released;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unsubscribes from manipulation events.
|
||||
/// </summary>
|
||||
protected override void OnDisable()
|
||||
{
|
||||
base.OnDisable();
|
||||
|
||||
GrabbableObject.Grabbed -= Object_Grabbed;
|
||||
GrabbableObject.Placed -= Object_Placed;
|
||||
GrabbableObject.Released -= Object_Released;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Event Handling Methods
|
||||
|
||||
/// <summary>
|
||||
/// Called when the object was grabbed.
|
||||
/// </summary>
|
||||
/// <param name="sender">Grabbable object that sent the event</param>
|
||||
/// <param name="e">Event arguments</param>
|
||||
private void Object_Grabbed(object sender, UxrManipulationEventArgs e)
|
||||
{
|
||||
if (e.Grabber.Avatar == UxrAvatar.LocalAvatar)
|
||||
{
|
||||
_audioOnGrab.Play(transform.position);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the object was placed on an <see cref="UxrGrabbableObjectAnchor" />.
|
||||
/// </summary>
|
||||
/// <param name="sender">Grabbable object that sent the event</param>
|
||||
/// <param name="e">Event arguments</param>
|
||||
private void Object_Placed(object sender, UxrManipulationEventArgs e)
|
||||
{
|
||||
if (e.Grabber != null && e.Grabber.Avatar == UxrAvatar.LocalAvatar)
|
||||
{
|
||||
_audioOnPlace.Play(transform.position);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the object was released in the air.
|
||||
/// </summary>
|
||||
/// <param name="sender">Grabbable object that sent the event</param>
|
||||
/// <param name="e">Event arguments</param>
|
||||
private void Object_Released(object sender, UxrManipulationEventArgs e)
|
||||
{
|
||||
if (e.Grabber != null && e.Grabber.Avatar == UxrAvatar.LocalAvatar)
|
||||
{
|
||||
_audioOnRelease.Play(transform.position);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning restore 414
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de9b9b50632dc364ba61a4632566e267
|
||||
timeCreated: 1539274236
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
75
Assets/UltimateXR/Runtime/Scripts/Audio/UxrAudioSample.cs
Normal file
75
Assets/UltimateXR/Runtime/Scripts/Audio/UxrAudioSample.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="UxrAudioSample.cs" company="VRMADA">
|
||||
// Copyright (c) VRMADA, All rights reserved.
|
||||
// </copyright>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UltimateXR.Audio
|
||||
{
|
||||
/// <summary>
|
||||
/// Describes an audio clip that can be played and its parameters.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class UxrAudioSample
|
||||
{
|
||||
#region Inspector Properties/Serialized Fields
|
||||
|
||||
[SerializeField] private AudioClip _clip;
|
||||
[SerializeField] [Range(0, 1)] private float _volume = 1.0f;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Types & Data
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the audio clip.
|
||||
/// </summary>
|
||||
public AudioClip Clip
|
||||
{
|
||||
get => _clip;
|
||||
set => _clip = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the volume used when playing the clip.
|
||||
/// </summary>
|
||||
public float Volume
|
||||
{
|
||||
get => _volume;
|
||||
set => _volume = value;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors & Finalizer
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor.
|
||||
/// </summary>
|
||||
public UxrAudioSample()
|
||||
{
|
||||
Clip = null;
|
||||
Volume = 1.0f;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Plays the audio in a given position in space.
|
||||
/// </summary>
|
||||
/// <param name="position">World space coordinates where the audio will be played.</param>
|
||||
public void Play(Vector3 position)
|
||||
{
|
||||
if (Clip != null)
|
||||
{
|
||||
AudioSource.PlayClipAtPoint(Clip, position, Volume);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4900625d54a768478b5a3fcd8c935ed
|
||||
timeCreated: 1539273697
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,75 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="UxrAudioSourceStartPos.cs" company="VRMADA">
|
||||
// Copyright (c) VRMADA, All rights reserved.
|
||||
// </copyright>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
using UltimateXR.Core.Components;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UltimateXR.Audio
|
||||
{
|
||||
/// <summary>
|
||||
/// Component that allows to make an <see cref="AudioSource" /> start playing at a fixed time or a random time. It
|
||||
/// can be used for example to scatter multiple environment audio sources around that share the same loop and make them
|
||||
/// start playing at different times.
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(AudioSource))]
|
||||
public class UxrAudioSourceStartPos : UxrComponent
|
||||
{
|
||||
#region Inspector Properties/Serialized Fields
|
||||
|
||||
[SerializeField] private bool _random;
|
||||
[SerializeField] private float _startTime;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Types & Data
|
||||
|
||||
/// <summary>
|
||||
/// Gets the target <see cref="AudioSource" />.
|
||||
/// </summary>
|
||||
public AudioSource AudioSourceTarget => GetCachedComponent<AudioSource>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether to start playing from a random position in the audio interval.
|
||||
/// </summary>
|
||||
public bool UseRandomStartTime
|
||||
{
|
||||
get => _random;
|
||||
set => _random = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the start time position to start playing from. <see cref="UseRandomStartTime" /> needs to be false to
|
||||
/// use it.
|
||||
/// </summary>
|
||||
public float StartTime
|
||||
{
|
||||
get => _startTime;
|
||||
set => _startTime = value;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Unity
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="AudioSource" /> play time using the current parameters.
|
||||
/// </summary>
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
|
||||
if (UseRandomStartTime)
|
||||
{
|
||||
AudioSourceTarget.time = Random.Range(0.0f, AudioSourceTarget.clip.length);
|
||||
}
|
||||
else
|
||||
{
|
||||
AudioSourceTarget.time = StartTime;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e30cf4433bc842f4c8177b2b732f61a3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user