clean project
This commit is contained in:
141
Assets/Oculus/Interaction/Samples/Scripts/AudioTrigger.cs
Normal file
141
Assets/Oculus/Interaction/Samples/Scripts/AudioTrigger.cs
Normal file
@@ -0,0 +1,141 @@
|
||||
/************************************************************************************
|
||||
Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
|
||||
|
||||
Your use of this SDK or tool is subject to the Oculus SDK License Agreement, available at
|
||||
https://developer.oculus.com/licenses/oculussdk/
|
||||
|
||||
Unless required by applicable law or agreed to in writing, the Utilities SDK distributed
|
||||
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
||||
ANY KIND, either express or implied. See the License for the specific language governing
|
||||
permissions and limitations under the License.
|
||||
************************************************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
using UnityEngine.Assertions;
|
||||
using Oculus.Interaction;
|
||||
|
||||
namespace Oculus.Interaction
|
||||
{
|
||||
[RequireComponent(typeof(AudioSource))]
|
||||
public class AudioTrigger : MonoBehaviour
|
||||
{
|
||||
// Private
|
||||
private AudioSource _audioSource = null;
|
||||
private List<AudioClip> _randomAudioClipPool = new List<AudioClip>();
|
||||
private AudioClip _previousAudioClip = null;
|
||||
|
||||
// Serialized
|
||||
[Tooltip("Audio clip arrays with a value greater than 1 will have randomized playback.")]
|
||||
[SerializeField]
|
||||
private AudioClip[] _audioClips;
|
||||
[Tooltip("Volume set here will override the volume set on the attached sound source component.")]
|
||||
[Range(0f, 1f)]
|
||||
[SerializeField]
|
||||
private float _volume = 0.7f;
|
||||
[Tooltip("Check the 'Use Random Range' bool to and adjust the min and max slider values for randomized volume level playback.")]
|
||||
[SerializeField]
|
||||
private MinMaxPair _volumeRandomization;
|
||||
[Tooltip("Pitch set here will override the volume set on the attached sound source component.")]
|
||||
[SerializeField]
|
||||
[Range(-3f,3f)]
|
||||
[Space(10)]
|
||||
private float _pitch = 1f;
|
||||
[Tooltip("Check the 'Use Random Range' bool to and adjust the min and max slider values for randomized volume level playback.")]
|
||||
[SerializeField]
|
||||
private MinMaxPair _pitchRandomization;
|
||||
[Tooltip("True by default. Set to false for sounds to bypass the spatializer plugin. Will override settings on attached audio source.")]
|
||||
[SerializeField]
|
||||
[Space(10)]
|
||||
private bool _spatialize = true;
|
||||
[Tooltip("False by default. Set to true to enable looping on this sound. Will override settings on attached audio source.")]
|
||||
[SerializeField]
|
||||
private bool _loop = false;
|
||||
[Tooltip("100% by default. Sets likelyhood sample will actually play when called")]
|
||||
[SerializeField]
|
||||
private float _chanceToPlay = 100;
|
||||
[Tooltip("If enabled, audio will play automatically when this gameobject is enabled")]
|
||||
[SerializeField]
|
||||
private bool _playOnStart = false;
|
||||
protected virtual void Start()
|
||||
{
|
||||
_audioSource = gameObject.GetComponent<AudioSource>();
|
||||
// Validate that we have audio to play
|
||||
Assert.IsTrue(_audioClips.Length > 0, "An AudioTrigger instance in the scene has no audio clips.");
|
||||
// Add all audio clips in the populated array into an audio clip list for randomization purposes
|
||||
for (int i = 0; i < _audioClips.Length; i++)
|
||||
{
|
||||
_randomAudioClipPool.Add(_audioClips[i]);
|
||||
}
|
||||
// Copy over values from the audio trigger to the audio source
|
||||
_audioSource.volume = _volume;
|
||||
_audioSource.pitch = _pitch;
|
||||
_audioSource.spatialize = _spatialize;
|
||||
_audioSource.loop = _loop;
|
||||
Random.InitState((int)Time.time);
|
||||
// Play audio on start if enabled
|
||||
if (_playOnStart)
|
||||
{
|
||||
PlayAudio();
|
||||
}
|
||||
}
|
||||
public void PlayAudio()
|
||||
{
|
||||
// Early out if our audio source is disabled
|
||||
if (!_audioSource.isActiveAndEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Check if random chance is set
|
||||
float pick = Random.Range(0.0f, 100.0f);
|
||||
if (_chanceToPlay < 100 && pick > _chanceToPlay)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Check if volume randomization is set
|
||||
if (_volumeRandomization.UseRandomRange == true)
|
||||
{
|
||||
_audioSource.volume = Random.Range(_volumeRandomization.Min, _volumeRandomization.Max);
|
||||
}
|
||||
// Check if pitch randomization is set
|
||||
if (_pitchRandomization.UseRandomRange == true)
|
||||
{
|
||||
_audioSource.pitch = Random.Range(_pitchRandomization.Min, _pitchRandomization.Max);
|
||||
}
|
||||
// If the audio trigger has one clip, play it. Otherwise play a random without repeat clip
|
||||
AudioClip clipToPlay = _audioClips.Length == 1 ? _audioClips[0] : RandomClipWithoutRepeat();
|
||||
_audioSource.clip = clipToPlay;
|
||||
// Play the audio
|
||||
_audioSource.Play();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Choose a random clip without repeating the last clip
|
||||
/// </summary>
|
||||
private AudioClip RandomClipWithoutRepeat()
|
||||
{
|
||||
int randomIndex = Random.Range(0, _randomAudioClipPool.Count);
|
||||
AudioClip randomClip = _randomAudioClipPool[randomIndex];
|
||||
_randomAudioClipPool.RemoveAt(randomIndex);
|
||||
if (_previousAudioClip != null) {
|
||||
_randomAudioClipPool.Add(_previousAudioClip);
|
||||
}
|
||||
_previousAudioClip = randomClip;
|
||||
return randomClip;
|
||||
}
|
||||
}
|
||||
[System.Serializable]
|
||||
public struct MinMaxPair
|
||||
{
|
||||
[SerializeField]
|
||||
private bool _useRandomRange;
|
||||
[SerializeField]
|
||||
private float _min;
|
||||
[SerializeField]
|
||||
private float _max;
|
||||
public bool UseRandomRange => _useRandomRange;
|
||||
public float Min => _min;
|
||||
public float Max => _max;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 925ef87c5bafc37469a2f7ec825dee4b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
83
Assets/Oculus/Interaction/Samples/Scripts/CountdownTimer.cs
Normal file
83
Assets/Oculus/Interaction/Samples/Scripts/CountdownTimer.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
/************************************************************************************
|
||||
Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
|
||||
|
||||
Your use of this SDK or tool is subject to the Oculus SDK License Agreement, available at
|
||||
https://developer.oculus.com/licenses/oculussdk/
|
||||
|
||||
Unless required by applicable law or agreed to in writing, the Utilities SDK distributed
|
||||
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
||||
ANY KIND, either express or implied. See the License for the specific language governing
|
||||
permissions and limitations under the License.
|
||||
************************************************************************************/
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.Assertions;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace Oculus.Interaction.Samples
|
||||
{
|
||||
/// <summary>
|
||||
/// Performs a callback after a countdown timer has elapsed.
|
||||
/// The countdown can be enabled or disabled by an external party.
|
||||
/// </summary>
|
||||
public class CountdownTimer : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private float _countdownTime = 1.0f;
|
||||
|
||||
[SerializeField]
|
||||
private bool _countdownOn = false;
|
||||
|
||||
[SerializeField]
|
||||
private UnityEvent _callback;
|
||||
|
||||
[SerializeField]
|
||||
private UnityEvent<float> _progressCallback;
|
||||
|
||||
private float _countdownTimer;
|
||||
|
||||
|
||||
public bool CountdownOn
|
||||
{
|
||||
get => _countdownOn;
|
||||
|
||||
set
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
if (!_countdownOn)
|
||||
{
|
||||
_countdownTimer = _countdownTime;
|
||||
}
|
||||
}
|
||||
|
||||
_countdownOn = value;
|
||||
}
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Assert.IsTrue(_countdownTime >= 0, "Countdown Time must be positive.");
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!_countdownOn || _countdownTimer < 0)
|
||||
{
|
||||
_progressCallback.Invoke(0);
|
||||
return;
|
||||
}
|
||||
|
||||
_countdownTimer -= Time.deltaTime;
|
||||
if (_countdownTimer < 0f)
|
||||
{
|
||||
_countdownTimer = -1f;
|
||||
_callback.Invoke();
|
||||
_progressCallback.Invoke(1);
|
||||
return;
|
||||
}
|
||||
|
||||
_progressCallback.Invoke(1 - _countdownTimer / _countdownTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 80adaa84dcdec2b41981fa223dab63f0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,41 @@
|
||||
/************************************************************************************
|
||||
Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
|
||||
|
||||
Your use of this SDK or tool is subject to the Oculus SDK License Agreement, available at
|
||||
https://developer.oculus.com/licenses/oculussdk/
|
||||
|
||||
Unless required by applicable law or agreed to in writing, the Utilities SDK distributed
|
||||
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
||||
ANY KIND, either express or implied. See the License for the specific language governing
|
||||
permissions and limitations under the License.
|
||||
************************************************************************************/
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace Oculus.Interaction.Samples
|
||||
{
|
||||
public class EnableTargetOnStart : MonoBehaviour
|
||||
{
|
||||
public MonoBehaviour[] _components;
|
||||
public GameObject[] _gameObjects;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (_components != null)
|
||||
{
|
||||
foreach (MonoBehaviour target in _components)
|
||||
{
|
||||
target.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (_gameObjects != null)
|
||||
{
|
||||
foreach (GameObject target in _gameObjects)
|
||||
{
|
||||
target.SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2e81f6da227209c49bdc78260f44e85b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,44 @@
|
||||
/************************************************************************************
|
||||
Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
|
||||
|
||||
Your use of this SDK or tool is subject to the Oculus SDK License Agreement, available at
|
||||
https://developer.oculus.com/licenses/oculussdk/
|
||||
|
||||
Unless required by applicable law or agreed to in writing, the Utilities SDK distributed
|
||||
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
||||
ANY KIND, either express or implied. See the License for the specific language governing
|
||||
permissions and limitations under the License.
|
||||
************************************************************************************/
|
||||
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Oculus.Interaction.Samples
|
||||
{
|
||||
public class FadeTextAfterActive : MonoBehaviour
|
||||
{
|
||||
[SerializeField] float _fadeOutTime;
|
||||
[SerializeField] TextMeshPro _text;
|
||||
|
||||
float _timeLeft;
|
||||
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
_timeLeft = _fadeOutTime;
|
||||
_text.fontMaterial.color = new Color(_text.color.r, _text.color.g, _text.color.b, 255);
|
||||
}
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
if (_timeLeft <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float percentDone = 1 - _timeLeft / _fadeOutTime;
|
||||
float alpha = Mathf.SmoothStep(1, 0, percentDone);
|
||||
_text.color = new Color(_text.color.r, _text.color.g, _text.color.b, alpha);
|
||||
_timeLeft -= Time.deltaTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5a540e547f62942468b7ff96e6e12bc1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,77 @@
|
||||
/************************************************************************************
|
||||
Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
|
||||
|
||||
Your use of this SDK or tool is subject to the Oculus SDK License Agreement, available at
|
||||
https://developer.oculus.com/licenses/oculussdk/
|
||||
|
||||
Unless required by applicable law or agreed to in writing, the Utilities SDK distributed
|
||||
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
||||
ANY KIND, either express or implied. See the License for the specific language governing
|
||||
permissions and limitations under the License.
|
||||
************************************************************************************/
|
||||
|
||||
using Oculus.Interaction.HandPosing;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Assertions;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace Oculus.Interaction.Samples
|
||||
{
|
||||
public class HideHandVisualOnGrab : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private HandGrabInteractor _handGrabInteractor;
|
||||
|
||||
[SerializeField]
|
||||
private HandVisual _handVisual;
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
Assert.IsNotNull(_handVisual);
|
||||
}
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
GameObject volume = null;
|
||||
|
||||
if (_handGrabInteractor.State == InteractorState.Select)
|
||||
{
|
||||
volume = _handGrabInteractor.SelectedInteractable?.gameObject;
|
||||
}
|
||||
|
||||
if (volume)
|
||||
{
|
||||
if (volume.TryGetComponent(out ShouldHideHandOnGrab component))
|
||||
{
|
||||
_handVisual.ForceOffVisibility = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_handVisual.ForceOffVisibility = false;
|
||||
}
|
||||
}
|
||||
|
||||
#region Inject
|
||||
|
||||
public void InjectAll(HandGrabInteractor handGrabInteractor,
|
||||
HandVisual handVisual)
|
||||
{
|
||||
InjectHandGrabInteractor(handGrabInteractor);
|
||||
InjectHandVisual(handVisual);
|
||||
}
|
||||
private void InjectHandGrabInteractor(HandGrabInteractor handGrabInteractor)
|
||||
{
|
||||
_handGrabInteractor = handGrabInteractor;
|
||||
}
|
||||
|
||||
private void InjectHandVisual(HandVisual handVisual)
|
||||
{
|
||||
_handVisual = handVisual;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b637179e0cc734442bf0e50111bcc634
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
67
Assets/Oculus/Interaction/Samples/Scripts/PoseUseSample.cs
Normal file
67
Assets/Oculus/Interaction/Samples/Scripts/PoseUseSample.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
/************************************************************************************
|
||||
Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
|
||||
|
||||
Your use of this SDK or tool is subject to the Oculus SDK License Agreement, available at
|
||||
https://developer.oculus.com/licenses/oculussdk/
|
||||
|
||||
Unless required by applicable law or agreed to in writing, the Utilities SDK distributed
|
||||
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
||||
ANY KIND, either express or implied. See the License for the specific language governing
|
||||
permissions and limitations under the License.
|
||||
************************************************************************************/
|
||||
|
||||
using Oculus.Interaction.Input;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Oculus.Interaction.Samples
|
||||
{
|
||||
public class PoseUseSample : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private ActiveStateSelector[] _poses;
|
||||
[SerializeField] private Material[] _onSelectIcons;
|
||||
[SerializeField] private GameObject _poseActiveVisualPrefab;
|
||||
|
||||
private GameObject[] _poseActiveVisuals;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_poseActiveVisuals = new GameObject[_poses.Length];
|
||||
for (int i = 0; i < _poses.Length; i++)
|
||||
{
|
||||
_poseActiveVisuals[i] = Instantiate(_poseActiveVisualPrefab);
|
||||
_poseActiveVisuals[i].GetComponentInChildren<TextMeshPro>().text = _poses[i].name;
|
||||
_poseActiveVisuals[i].GetComponentInChildren<ParticleSystemRenderer>().material = _onSelectIcons[i];
|
||||
_poseActiveVisuals[i].SetActive(false);
|
||||
|
||||
int poseNumber = i;
|
||||
_poses[i].WhenSelected += () => ShowVisuals(poseNumber);
|
||||
_poses[i].WhenUnselected += () => HideVisuals(poseNumber);
|
||||
}
|
||||
}
|
||||
private void ShowVisuals(int poseNumber)
|
||||
{
|
||||
var centerEyePos = FindObjectOfType<OVRCameraRig>().centerEyeAnchor.position;
|
||||
Vector3 spawnSpot = centerEyePos + FindObjectOfType<OVRCameraRig>().centerEyeAnchor.forward;
|
||||
|
||||
_poseActiveVisuals[poseNumber].transform.position = spawnSpot;
|
||||
_poseActiveVisuals[poseNumber].transform.LookAt(2 * _poseActiveVisuals[poseNumber].transform.position - centerEyePos);
|
||||
|
||||
var hands = _poses[poseNumber].GetComponents<HandRef>();
|
||||
Vector3 visualsPos = Vector3.zero;
|
||||
foreach (var hand in hands)
|
||||
{
|
||||
hand.GetRootPose(out Pose wristPose);
|
||||
Vector3 forward = hand.Handedness == Handedness.Left ? wristPose.right : -wristPose.right;
|
||||
visualsPos += wristPose.position + forward * .15f + Vector3.up * .02f;
|
||||
}
|
||||
_poseActiveVisuals[poseNumber].transform.position = visualsPos / hands.Length;
|
||||
_poseActiveVisuals[poseNumber].gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
private void HideVisuals(int poseNumber)
|
||||
{
|
||||
_poseActiveVisuals[poseNumber].gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 14e32a77be61d8b4e906c12d189faef7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
68
Assets/Oculus/Interaction/Samples/Scripts/RespawnOnDrop.cs
Normal file
68
Assets/Oculus/Interaction/Samples/Scripts/RespawnOnDrop.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
/************************************************************************************
|
||||
Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
|
||||
|
||||
Your use of this SDK or tool is subject to the Oculus SDK License Agreement, available at
|
||||
https://developer.oculus.com/licenses/oculussdk/
|
||||
|
||||
Unless required by applicable law or agreed to in writing, the Utilities SDK distributed
|
||||
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
||||
ANY KIND, either express or implied. See the License for the specific language governing
|
||||
permissions and limitations under the License.
|
||||
************************************************************************************/
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace Oculus.Interaction.Samples
|
||||
{
|
||||
public class RespawnOnDrop : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private float _yThresholdForRespawn;
|
||||
|
||||
[SerializeField]
|
||||
private UnityEvent _whenRespawned = new UnityEvent();
|
||||
|
||||
public UnityEvent WhenRespawned => _whenRespawned;
|
||||
|
||||
// cached starting transform
|
||||
private Vector3 _initialPosition;
|
||||
private Quaternion _initialRotation;
|
||||
private Vector3 _initialScale;
|
||||
|
||||
private TwoHandFreeTransformer[] _freeTransformers;
|
||||
private Rigidbody _rigidBody;
|
||||
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
_initialPosition = transform.position;
|
||||
_initialRotation = transform.rotation;
|
||||
_initialScale = transform.localScale;
|
||||
_freeTransformers = GetComponents<TwoHandFreeTransformer>();
|
||||
_rigidBody = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
if (transform.position.y < _yThresholdForRespawn)
|
||||
{
|
||||
transform.position = _initialPosition;
|
||||
transform.rotation = _initialRotation;
|
||||
transform.localScale = _initialScale;
|
||||
|
||||
if (_rigidBody)
|
||||
{
|
||||
_rigidBody.velocity = Vector3.zero;
|
||||
_rigidBody.angularVelocity = Vector3.zero;
|
||||
}
|
||||
|
||||
foreach (var freeTransformer in _freeTransformers)
|
||||
{
|
||||
freeTransformer.MarkAsBaseScale();
|
||||
}
|
||||
|
||||
_whenRespawned.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eeb09e4f18fd0954796cd0b766d28fa4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
182
Assets/Oculus/Interaction/Samples/Scripts/RotationAudioEvents.cs
Normal file
182
Assets/Oculus/Interaction/Samples/Scripts/RotationAudioEvents.cs
Normal file
@@ -0,0 +1,182 @@
|
||||
/************************************************************************************
|
||||
Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
|
||||
|
||||
Your use of this SDK or tool is subject to the Oculus SDK License Agreement, available at
|
||||
https://developer.oculus.com/licenses/oculussdk/
|
||||
|
||||
Unless required by applicable law or agreed to in writing, the Utilities SDK distributed
|
||||
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
||||
ANY KIND, either express or implied. See the License for the specific language governing
|
||||
permissions and limitations under the License.
|
||||
************************************************************************************/
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.Assertions;
|
||||
|
||||
namespace Oculus.Interaction.Samples
|
||||
{
|
||||
/// <summary>
|
||||
/// Raises events when an object is rotated relative to a provided transform. Rotated
|
||||
/// events will be raised when the rotation exceeds a provided angle threshold, in degrees.
|
||||
/// Events are raised only once per directional sweep, so if an event was fired while angle
|
||||
/// was increasing, the next must fire while angle decreases.
|
||||
/// </summary>
|
||||
public class RotationAudioEvents : MonoBehaviour
|
||||
{
|
||||
private enum Direction
|
||||
{
|
||||
None,
|
||||
Opening,
|
||||
Closing,
|
||||
}
|
||||
|
||||
[SerializeField, Interface(typeof(IInteractableView))]
|
||||
private MonoBehaviour _interactableView;
|
||||
|
||||
[Tooltip("Transform to track rotation of. If not provided, transform of this component is used.")]
|
||||
[SerializeField, Optional]
|
||||
private Transform _trackedTransform;
|
||||
|
||||
[SerializeField]
|
||||
private Transform _relativeTo;
|
||||
|
||||
[Tooltip("The angle delta at which the threshold crossed event will be fired.")]
|
||||
[SerializeField]
|
||||
private float _thresholdDeg = 20f;
|
||||
|
||||
[Tooltip("Maximum rotation arc within which the crossed event will be triggered.")]
|
||||
[SerializeField, Range(1f, 150f)]
|
||||
private float _maxRangeDeg = 150f;
|
||||
|
||||
[SerializeField]
|
||||
private UnityEvent _whenRotationStarted = new UnityEvent();
|
||||
|
||||
[SerializeField]
|
||||
private UnityEvent _whenRotationEnded = new UnityEvent();
|
||||
|
||||
[SerializeField]
|
||||
private UnityEvent _whenRotatedOpen = new UnityEvent();
|
||||
|
||||
[SerializeField]
|
||||
private UnityEvent _whenRotatedClosed = new UnityEvent();
|
||||
|
||||
public UnityEvent WhenRotationStarted => _whenRotationStarted;
|
||||
|
||||
public UnityEvent WhenRotationEnded => _whenRotationEnded;
|
||||
|
||||
public UnityEvent WhenRotatedOpen => _whenRotatedOpen;
|
||||
|
||||
public UnityEvent WhenRotatedClosed => _whenRotatedClosed;
|
||||
|
||||
private IInteractableView InteractableView;
|
||||
|
||||
private Transform TrackedTransform
|
||||
{
|
||||
get => _trackedTransform == null ? transform : _trackedTransform;
|
||||
}
|
||||
|
||||
private float _baseDelta;
|
||||
private bool _isRotating;
|
||||
private Direction _lastCrossedDirection;
|
||||
|
||||
protected bool _started;
|
||||
|
||||
private void RotationStarted()
|
||||
{
|
||||
_baseDelta = GetTotalDelta();
|
||||
_lastCrossedDirection = Direction.None;
|
||||
_whenRotationStarted.Invoke();
|
||||
}
|
||||
|
||||
private void RotationEnded()
|
||||
{
|
||||
_whenRotationEnded.Invoke();
|
||||
}
|
||||
|
||||
private Quaternion GetCurrentRotation()
|
||||
{
|
||||
return Quaternion.Inverse(_relativeTo.rotation) * TrackedTransform.rotation;
|
||||
}
|
||||
|
||||
private float GetTotalDelta()
|
||||
{
|
||||
return Quaternion.Angle(_relativeTo.rotation, GetCurrentRotation());
|
||||
}
|
||||
|
||||
private void UpdateRotation()
|
||||
{
|
||||
float totalDelta = GetTotalDelta();
|
||||
|
||||
if (totalDelta > _maxRangeDeg)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Mathf.Abs(totalDelta - _baseDelta) > _thresholdDeg)
|
||||
{
|
||||
var _direction = totalDelta - _baseDelta > 0 ?
|
||||
Direction.Opening :
|
||||
Direction.Closing;
|
||||
|
||||
if (_direction != _lastCrossedDirection)
|
||||
{
|
||||
_lastCrossedDirection = _direction;
|
||||
if (_direction == Direction.Opening)
|
||||
{
|
||||
_whenRotatedOpen.Invoke();
|
||||
}
|
||||
else
|
||||
{
|
||||
_whenRotatedClosed.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_lastCrossedDirection == Direction.Opening)
|
||||
{
|
||||
_baseDelta = Mathf.Max(_baseDelta, totalDelta);
|
||||
}
|
||||
else if (_lastCrossedDirection == Direction.Closing)
|
||||
{
|
||||
_baseDelta = Mathf.Min(_baseDelta, totalDelta);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
InteractableView = _interactableView as IInteractableView;
|
||||
}
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
this.BeginStart(ref _started);
|
||||
Assert.IsNotNull(InteractableView);
|
||||
Assert.IsNotNull(TrackedTransform);
|
||||
Assert.IsNotNull(_relativeTo);
|
||||
this.EndStart(ref _started);
|
||||
}
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
bool wasRotating = _isRotating;
|
||||
_isRotating = InteractableView.State == InteractableState.Select;
|
||||
|
||||
if (!_isRotating)
|
||||
{
|
||||
if (wasRotating)
|
||||
{
|
||||
RotationEnded();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!wasRotating)
|
||||
{
|
||||
RotationStarted();
|
||||
}
|
||||
UpdateRotation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 328b20022c3885e43a8861c57af4caf5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
174
Assets/Oculus/Interaction/Samples/Scripts/ScaleAudioEvents.cs
Normal file
174
Assets/Oculus/Interaction/Samples/Scripts/ScaleAudioEvents.cs
Normal file
@@ -0,0 +1,174 @@
|
||||
/************************************************************************************
|
||||
Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
|
||||
|
||||
Your use of this SDK or tool is subject to the Oculus SDK License Agreement, available at
|
||||
https://developer.oculus.com/licenses/oculussdk/
|
||||
|
||||
Unless required by applicable law or agreed to in writing, the Utilities SDK distributed
|
||||
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
||||
ANY KIND, either express or implied. See the License for the specific language governing
|
||||
permissions and limitations under the License.
|
||||
************************************************************************************/
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.Assertions;
|
||||
|
||||
namespace Oculus.Interaction.Samples
|
||||
{
|
||||
/// <summary>
|
||||
/// Raises events when an object is scaled up or down. Events are raised in steps,
|
||||
/// meaning scale changes are only responded to when the scale magnitude delta since
|
||||
/// last step exceeds a provided amount.
|
||||
/// </summary>
|
||||
public class ScaleAudioEvents : MonoBehaviour
|
||||
{
|
||||
private enum Direction
|
||||
{
|
||||
None,
|
||||
ScaleUp,
|
||||
ScaleDown,
|
||||
}
|
||||
|
||||
[SerializeField, Interface(typeof(IInteractableView))]
|
||||
private MonoBehaviour _interactableView;
|
||||
|
||||
[Tooltip("Transform to track scale of. If not provided, transform of this component is used.")]
|
||||
[SerializeField, Optional]
|
||||
private Transform _trackedTransform;
|
||||
|
||||
[Tooltip("The increase in scale magnitude that will fire the step event")]
|
||||
[SerializeField]
|
||||
private float _stepSize = 0.4f;
|
||||
|
||||
[Tooltip("Events will not be fired more frequently than this many times per second")]
|
||||
[SerializeField]
|
||||
private int _maxEventFreq = 20;
|
||||
|
||||
[SerializeField]
|
||||
private UnityEvent _whenScalingStarted = new UnityEvent();
|
||||
|
||||
[SerializeField]
|
||||
private UnityEvent _whenScalingEnded = new UnityEvent();
|
||||
|
||||
[SerializeField]
|
||||
private UnityEvent _whenScaledUp = new UnityEvent();
|
||||
|
||||
[SerializeField]
|
||||
private UnityEvent _whenScaledDown = new UnityEvent();
|
||||
|
||||
public UnityEvent WhenScalingStarted => _whenScalingStarted;
|
||||
|
||||
public UnityEvent WhenScalingEnded => _whenScalingEnded;
|
||||
|
||||
public UnityEvent WhenScaledUp => _whenScaledUp;
|
||||
|
||||
public UnityEvent WhenScaledDown => _whenScaledDown;
|
||||
|
||||
private IInteractableView InteractableView;
|
||||
|
||||
private Transform TrackedTransform
|
||||
{
|
||||
get => _trackedTransform == null ? transform : _trackedTransform;
|
||||
}
|
||||
|
||||
private bool _isScaling;
|
||||
private Vector3 _lastStep;
|
||||
private float _lastEventTime;
|
||||
private Direction _direction = Direction.None;
|
||||
|
||||
protected bool _started;
|
||||
|
||||
private void ScalingStarted()
|
||||
{
|
||||
_lastStep = TrackedTransform.localScale;
|
||||
_whenScalingStarted.Invoke();
|
||||
}
|
||||
|
||||
private void ScalingEnded()
|
||||
{
|
||||
_whenScalingEnded.Invoke();
|
||||
}
|
||||
|
||||
private float GetTotalDelta(out Direction direction)
|
||||
{
|
||||
float prevMagnitude = _lastStep.magnitude;
|
||||
float newMagnitude = TrackedTransform.localScale.magnitude;
|
||||
if (newMagnitude == prevMagnitude)
|
||||
{
|
||||
direction = Direction.None;
|
||||
}
|
||||
else
|
||||
{
|
||||
direction = newMagnitude > prevMagnitude ? Direction.ScaleUp : Direction.ScaleDown;
|
||||
}
|
||||
|
||||
return direction == Direction.ScaleUp ?
|
||||
newMagnitude - prevMagnitude :
|
||||
prevMagnitude - newMagnitude;
|
||||
}
|
||||
|
||||
private void UpdateScaling()
|
||||
{
|
||||
if (_stepSize <= 0 || _maxEventFreq <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float effectiveStepSize = _stepSize;
|
||||
float totalDelta = GetTotalDelta(out _direction);
|
||||
if (totalDelta > effectiveStepSize)
|
||||
{
|
||||
_lastStep = TrackedTransform.localScale;
|
||||
float timeSince = Time.time - _lastEventTime;
|
||||
if (timeSince >= 1f / _maxEventFreq)
|
||||
{
|
||||
_lastEventTime = Time.time;
|
||||
if (_direction == Direction.ScaleUp)
|
||||
{
|
||||
_whenScaledUp.Invoke();
|
||||
}
|
||||
else
|
||||
{
|
||||
_whenScaledDown.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
InteractableView = _interactableView as IInteractableView;
|
||||
}
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
this.BeginStart(ref _started);
|
||||
Assert.IsNotNull(InteractableView);
|
||||
Assert.IsNotNull(TrackedTransform);
|
||||
this.EndStart(ref _started);
|
||||
}
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
bool wasScaling = _isScaling;
|
||||
_isScaling = InteractableView.State == InteractableState.Select;
|
||||
|
||||
if (!_isScaling)
|
||||
{
|
||||
if (wasScaling)
|
||||
{
|
||||
ScalingEnded();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!wasScaling)
|
||||
{
|
||||
ScalingStarted();
|
||||
}
|
||||
UpdateScaling();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ced30fb0d3378c442934280394576509
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
32
Assets/Oculus/Interaction/Samples/Scripts/ScaleModifier.cs
Normal file
32
Assets/Oculus/Interaction/Samples/Scripts/ScaleModifier.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
/************************************************************************************
|
||||
Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
|
||||
|
||||
Your use of this SDK or tool is subject to the Oculus SDK License Agreement, available at
|
||||
https://developer.oculus.com/licenses/oculussdk/
|
||||
|
||||
Unless required by applicable law or agreed to in writing, the Utilities SDK distributed
|
||||
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
||||
ANY KIND, either express or implied. See the License for the specific language governing
|
||||
permissions and limitations under the License.
|
||||
************************************************************************************/
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace Oculus.Interaction.Samples
|
||||
{
|
||||
public class ScaleModifier : MonoBehaviour
|
||||
{
|
||||
public void SetScaleX(float x)
|
||||
{
|
||||
transform.localScale = new Vector3(x, transform.localScale.y, transform.localScale.z);
|
||||
}
|
||||
public void SetScaleY(float y)
|
||||
{
|
||||
transform.localScale = new Vector3(transform.localScale.x, y, transform.localScale.z);
|
||||
}
|
||||
public void SetScaleZ(float z)
|
||||
{
|
||||
transform.localScale = new Vector3(transform.localScale.x, transform.localScale.y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 586427432b00198488881015ab3989b6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
39
Assets/Oculus/Interaction/Samples/Scripts/SceneLoader.cs
Normal file
39
Assets/Oculus/Interaction/Samples/Scripts/SceneLoader.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
/************************************************************************************
|
||||
Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
|
||||
|
||||
Your use of this SDK or tool is subject to the Oculus SDK License Agreement, available at
|
||||
https://developer.oculus.com/licenses/oculussdk/
|
||||
|
||||
Unless required by applicable law or agreed to in writing, the Utilities SDK distributed
|
||||
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
||||
ANY KIND, either express or implied. See the License for the specific language governing
|
||||
permissions and limitations under the License.
|
||||
************************************************************************************/
|
||||
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Oculus.Interaction.Samples
|
||||
{
|
||||
public class SceneLoader : MonoBehaviour
|
||||
{
|
||||
private bool _loading = false;
|
||||
|
||||
public void Load(string sceneName)
|
||||
{
|
||||
if (_loading) return;
|
||||
_loading = true;
|
||||
StartCoroutine(LoadSceneAsync(sceneName));
|
||||
}
|
||||
|
||||
private IEnumerator LoadSceneAsync(string sceneName)
|
||||
{
|
||||
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(sceneName);
|
||||
while (!asyncLoad.isDone)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8c4c1b38c49ffa449b585d54fcdc4a8c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,19 @@
|
||||
/************************************************************************************
|
||||
Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
|
||||
|
||||
Your use of this SDK or tool is subject to the Oculus SDK License Agreement, available at
|
||||
https://developer.oculus.com/licenses/oculussdk/
|
||||
|
||||
Unless required by applicable law or agreed to in writing, the Utilities SDK distributed
|
||||
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
||||
ANY KIND, either express or implied. See the License for the specific language governing
|
||||
permissions and limitations under the License.
|
||||
************************************************************************************/
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace Oculus.Interaction.Samples
|
||||
{
|
||||
// Place on the same GameObject as the VolumeInteractable
|
||||
public class ShouldHideHandOnGrab : MonoBehaviour {}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a2b5b0c4a3ad10941918d5e111f95b70
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
37
Assets/Oculus/Interaction/Samples/Scripts/StayInView.cs
Normal file
37
Assets/Oculus/Interaction/Samples/Scripts/StayInView.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
/************************************************************************************
|
||||
Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
|
||||
|
||||
Your use of this SDK or tool is subject to the Oculus SDK License Agreement, available at
|
||||
https://developer.oculus.com/licenses/oculussdk/
|
||||
|
||||
Unless required by applicable law or agreed to in writing, the Utilities SDK distributed
|
||||
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
||||
ANY KIND, either express or implied. See the License for the specific language governing
|
||||
permissions and limitations under the License.
|
||||
************************************************************************************/
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace Oculus.Interaction.Samples
|
||||
{
|
||||
public class StayInView : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private Transform _eyeCenter;
|
||||
|
||||
[SerializeField]
|
||||
private float _extraDistanceForward = 0;
|
||||
|
||||
[SerializeField]
|
||||
private bool _zeroOutEyeHeight = true;
|
||||
void Update()
|
||||
{
|
||||
transform.rotation = Quaternion.identity;
|
||||
transform.position = _eyeCenter.position;
|
||||
transform.Rotate(0, _eyeCenter.rotation.eulerAngles.y, 0, Space.Self);
|
||||
transform.position = _eyeCenter.position + transform.forward.normalized * _extraDistanceForward;
|
||||
if (_zeroOutEyeHeight)
|
||||
transform.position = new Vector3(transform.position.x, 0, transform.position.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Oculus/Interaction/Samples/Scripts/StayInView.cs.meta
Normal file
11
Assets/Oculus/Interaction/Samples/Scripts/StayInView.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 56687da4eed4f0541b3e4a77d8008acd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user