Initialer Upload neues Unity-Projekt
This commit is contained in:
@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus 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.Locomotion
|
||||
{
|
||||
[RequireComponent(typeof(AudioSource))]
|
||||
public class AdjustableAudio : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private AudioSource _audioSource = null;
|
||||
|
||||
[SerializeField]
|
||||
private AudioClip _audioClip = null;
|
||||
public AudioClip AudioClip
|
||||
{
|
||||
get
|
||||
{
|
||||
return _audioClip;
|
||||
}
|
||||
set
|
||||
{
|
||||
_audioClip = value;
|
||||
}
|
||||
}
|
||||
[SerializeField, Range(0f,1f)]
|
||||
private float _volumeFactor = 1f;
|
||||
public float VolumeFactor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _volumeFactor;
|
||||
}
|
||||
set
|
||||
{
|
||||
_volumeFactor = value;
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
private AnimationCurve _volumeCurve = AnimationCurve.Linear(0f, 0f, 1f, 1f);
|
||||
public AnimationCurve VolumeCurve
|
||||
{
|
||||
get
|
||||
{
|
||||
return _volumeCurve;
|
||||
}
|
||||
set
|
||||
{
|
||||
_volumeCurve = value;
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
private AnimationCurve _pitchCurve = AnimationCurve.Linear(0f, 0.5f, 1f, 1.5f);
|
||||
public AnimationCurve PitchCurve
|
||||
{
|
||||
get
|
||||
{
|
||||
return _pitchCurve;
|
||||
}
|
||||
set
|
||||
{
|
||||
_pitchCurve = value;
|
||||
}
|
||||
}
|
||||
|
||||
protected bool _started;
|
||||
|
||||
#region Editor events
|
||||
protected virtual void Reset()
|
||||
{
|
||||
_audioSource = gameObject.GetComponent<AudioSource>();
|
||||
_audioClip = _audioSource.clip;
|
||||
}
|
||||
#endregion
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
this.BeginStart(ref _started);
|
||||
this.AssertField(_audioSource, nameof(_audioSource));
|
||||
this.EndStart(ref _started);
|
||||
}
|
||||
|
||||
public void PlayAudio(float volumeT, float pitchT, float pan = 0f)
|
||||
{
|
||||
if (!_audioSource.isActiveAndEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_audioSource.volume = _volumeCurve.Evaluate(volumeT) * VolumeFactor;
|
||||
_audioSource.pitch = _pitchCurve.Evaluate(pitchT);
|
||||
_audioSource.panStereo = pan;
|
||||
_audioSource.PlayOneShot(_audioClip);
|
||||
}
|
||||
|
||||
#region Inject
|
||||
public void InjectAllAdjustableAudio(AudioSource audioSource)
|
||||
{
|
||||
InjectAudioSource(audioSource);
|
||||
}
|
||||
|
||||
public void InjectAudioSource(AudioSource audioSource)
|
||||
{
|
||||
_audioSource = audioSource;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c686f13208596eb4b8272d78e582aec9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus 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 LocomotionTutorialAnimationUnityEventWrapper : MonoBehaviour
|
||||
{
|
||||
public UnityEvent WhenEnableTeleportRay;
|
||||
public UnityEvent WhenDisableTeleportRay;
|
||||
public UnityEvent WhenEnableTurningRing;
|
||||
public UnityEvent WhenDisableTurningRing;
|
||||
|
||||
public void EnableTeleportRay()
|
||||
{
|
||||
WhenEnableTeleportRay.Invoke();
|
||||
}
|
||||
|
||||
public void DisableTeleportRay()
|
||||
{
|
||||
WhenDisableTeleportRay.Invoke();
|
||||
}
|
||||
|
||||
public void EnableTurningRing()
|
||||
{
|
||||
WhenEnableTurningRing.Invoke();
|
||||
}
|
||||
|
||||
public void DisableTurningRing()
|
||||
{
|
||||
WhenDisableTurningRing.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5e71d82996a6bf84e94d1cd4dc728f5d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,184 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus 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.Locomotion;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Oculus.Interaction.Samples
|
||||
{
|
||||
public class LocomotionTutorialProgressTracker : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private Image[] _dots;
|
||||
[SerializeField]
|
||||
private Sprite _pendingSprite;
|
||||
[SerializeField]
|
||||
private Sprite _currentSprite;
|
||||
[SerializeField]
|
||||
private Sprite _completedSprite;
|
||||
|
||||
[SerializeField]
|
||||
private List<LocomotionEvent.TranslationType> _consumeTranslationEvents = new List<LocomotionEvent.TranslationType>();
|
||||
[SerializeField]
|
||||
private List<LocomotionEvent.RotationType> _consumeRotationEvents = new List<LocomotionEvent.RotationType>();
|
||||
|
||||
[SerializeField, Interface(typeof(ILocomotionEventHandler))]
|
||||
private UnityEngine.Object _locomotionHandler;
|
||||
private ILocomotionEventHandler LocomotionHandler;
|
||||
|
||||
public UnityEvent WhenCompleted;
|
||||
|
||||
protected bool _started;
|
||||
|
||||
private int _currentProgress = 0;
|
||||
private int _totalProgress = 0;
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
LocomotionHandler = _locomotionHandler as ILocomotionEventHandler;
|
||||
}
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
this.BeginStart(ref _started);
|
||||
this.AssertCollectionField(_dots, nameof(_dots));
|
||||
this.AssertCollectionItems(_consumeTranslationEvents, nameof(_consumeTranslationEvents));
|
||||
this.AssertCollectionItems(_consumeRotationEvents, nameof(_consumeRotationEvents));
|
||||
this.AssertField(_pendingSprite, nameof(_pendingSprite));
|
||||
this.AssertField(_currentSprite, nameof(_currentSprite));
|
||||
this.AssertField(_completedSprite, nameof(_completedSprite));
|
||||
this.AssertField(LocomotionHandler, nameof(LocomotionHandler));
|
||||
|
||||
_totalProgress = _dots.Length;
|
||||
this.EndStart(ref _started);
|
||||
}
|
||||
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
if (_started)
|
||||
{
|
||||
LocomotionHandler.WhenLocomotionEventHandled += LocomotionEventHandled;
|
||||
ResetProgress();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnDisable()
|
||||
{
|
||||
if (_started)
|
||||
{
|
||||
LocomotionHandler.WhenLocomotionEventHandled -= LocomotionEventHandled;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void LocomotionEventHandled(LocomotionEvent arg1, Pose arg2)
|
||||
{
|
||||
if (_consumeRotationEvents.Contains(arg1.Rotation)
|
||||
|| _consumeTranslationEvents.Contains(arg1.Translation))
|
||||
{
|
||||
Progress();
|
||||
}
|
||||
}
|
||||
|
||||
private void Progress()
|
||||
{
|
||||
_currentProgress++;
|
||||
if (_currentProgress <= _totalProgress)
|
||||
{
|
||||
_dots[_currentProgress - 1].sprite = _completedSprite;
|
||||
}
|
||||
if (_currentProgress < _totalProgress)
|
||||
{
|
||||
_dots[_currentProgress].sprite = _currentSprite;
|
||||
}
|
||||
|
||||
if (_currentProgress >= _totalProgress)
|
||||
{
|
||||
WhenCompleted.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetProgress()
|
||||
{
|
||||
_currentProgress = 0;
|
||||
for (int i = 0; i < _dots.Length; i++)
|
||||
{
|
||||
_dots[i].sprite = i == 0 ? _currentSprite : _pendingSprite;
|
||||
}
|
||||
}
|
||||
|
||||
#region Inject
|
||||
public void InjectAllLocomotionTutorialProgressTracker(Image[] dots,
|
||||
Sprite pendingSprite, Sprite currentSprite, Sprite completedSprite,
|
||||
List<LocomotionEvent.TranslationType> consumeTranslationEvents,
|
||||
List<LocomotionEvent.RotationType> consumeRotationEvents,
|
||||
ILocomotionEventHandler locomotionHandler)
|
||||
{
|
||||
InjectDots(dots);
|
||||
InjectPendingSprite(pendingSprite);
|
||||
InjectCurrentSprite(currentSprite);
|
||||
InjectCompletedSprite(completedSprite);
|
||||
InjectConsumeTranslationEvents(consumeTranslationEvents);
|
||||
InjectConsumeRotationEvents(consumeRotationEvents);
|
||||
InjectLocomotionHandler(locomotionHandler);
|
||||
}
|
||||
|
||||
public void InjectDots(Image[] dots)
|
||||
{
|
||||
_dots = dots;
|
||||
}
|
||||
|
||||
public void InjectPendingSprite(Sprite pendingSprite)
|
||||
{
|
||||
_pendingSprite = pendingSprite;
|
||||
}
|
||||
|
||||
public void InjectCurrentSprite(Sprite currentSprite)
|
||||
{
|
||||
_currentSprite = currentSprite;
|
||||
}
|
||||
|
||||
public void InjectCompletedSprite(Sprite completedSprite)
|
||||
{
|
||||
_completedSprite = completedSprite;
|
||||
}
|
||||
|
||||
public void InjectConsumeTranslationEvents(List<LocomotionEvent.TranslationType> consumeTranslationEvents)
|
||||
{
|
||||
_consumeTranslationEvents = consumeTranslationEvents;
|
||||
}
|
||||
|
||||
public void InjectConsumeRotationEvents(List<LocomotionEvent.RotationType> consumeRotationEvents)
|
||||
{
|
||||
_consumeRotationEvents = consumeRotationEvents;
|
||||
}
|
||||
|
||||
public void InjectLocomotionHandler(ILocomotionEventHandler locomotionHandler)
|
||||
{
|
||||
_locomotionHandler = locomotionHandler as UnityEngine.Object;
|
||||
LocomotionHandler = locomotionHandler;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de6bd207a644f864b8cc682622c8af52
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,226 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus 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 LocomotionTutorialTurnVisual : MonoBehaviour
|
||||
{
|
||||
[SerializeField, Range(-1f, 1f)]
|
||||
private float _value;
|
||||
[SerializeField, Range(0f, 1f)]
|
||||
private float _progress;
|
||||
|
||||
[Header("Visual renderers")]
|
||||
[SerializeField]
|
||||
private Renderer _leftArrow;
|
||||
[SerializeField]
|
||||
private Renderer _rightArrow;
|
||||
[SerializeField]
|
||||
private TubeRenderer _leftTrail;
|
||||
[SerializeField]
|
||||
private TubeRenderer _rightTrail;
|
||||
|
||||
[SerializeField]
|
||||
private MaterialPropertyBlockEditor _leftMaterialBlock;
|
||||
[SerializeField]
|
||||
private MaterialPropertyBlockEditor _rightMaterialBlock;
|
||||
|
||||
[Header("Visual parameters")]
|
||||
[SerializeField]
|
||||
private float _verticalOffset = 0.02f;
|
||||
public float VerticalOffset
|
||||
{
|
||||
get => _verticalOffset;
|
||||
set => _verticalOffset = value;
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
private float _radius = 0.07f;
|
||||
[SerializeField]
|
||||
private float _margin = 2f;
|
||||
[SerializeField]
|
||||
private float _trailLength = 15f;
|
||||
[SerializeField]
|
||||
private float _maxAngle = 45f;
|
||||
[SerializeField]
|
||||
private float _railGap = 0.005f;
|
||||
[SerializeField]
|
||||
private float _squeezeLength = 5f;
|
||||
|
||||
[SerializeField]
|
||||
private Color _disabledColor = new Color(1f, 1f, 1f, 0.2f);
|
||||
public Color DisabledColor
|
||||
{
|
||||
get => _disabledColor;
|
||||
set => _disabledColor = value;
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
private Color _enabledColor = new Color(1f, 1f, 1f, 0.6f);
|
||||
public Color EnabledColor
|
||||
{
|
||||
get => _enabledColor;
|
||||
set => _enabledColor = value;
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
private Color _highligtedColor = new Color(1f, 1f, 1f, 1f);
|
||||
public Color HighligtedColor
|
||||
{
|
||||
get => _highligtedColor;
|
||||
set => _highligtedColor = value;
|
||||
}
|
||||
|
||||
|
||||
private const float _degreesPerSegment = 1f;
|
||||
|
||||
private static readonly Quaternion _rotationCorrectionLeft = Quaternion.Euler(0f, -90f, 0f);
|
||||
private static readonly int _colorShaderPropertyID = Shader.PropertyToID("_Color");
|
||||
|
||||
protected bool _started;
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
this.BeginStart(ref _started);
|
||||
this.AssertField(_leftTrail, nameof(_leftTrail));
|
||||
this.AssertField(_rightTrail, nameof(_rightTrail));
|
||||
this.AssertField(_leftArrow, nameof(_leftArrow));
|
||||
this.AssertField(_rightArrow, nameof(_rightArrow));
|
||||
|
||||
this.AssertField(_leftMaterialBlock, nameof(_leftMaterialBlock));
|
||||
this.AssertField(_rightMaterialBlock, nameof(_rightMaterialBlock));
|
||||
|
||||
InitializeVisuals();
|
||||
this.EndStart(ref _started);
|
||||
}
|
||||
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
_leftTrail.enabled = true;
|
||||
_rightTrail.enabled = true;
|
||||
_leftArrow.enabled = true;
|
||||
_rightArrow.enabled = true;
|
||||
}
|
||||
|
||||
protected virtual void OnDisable()
|
||||
{
|
||||
_leftTrail.enabled = false;
|
||||
_rightTrail.enabled = false;
|
||||
_leftArrow.enabled = false;
|
||||
_rightArrow.enabled = false;
|
||||
}
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
UpdateArrows();
|
||||
UpdateColors();
|
||||
}
|
||||
|
||||
private void InitializeVisuals()
|
||||
{
|
||||
TubePoint[] trailPoints = InitializeSegment(new Vector2(_margin, _maxAngle + _squeezeLength));
|
||||
_leftTrail.RenderTube(trailPoints, Space.Self);
|
||||
_rightTrail.RenderTube(trailPoints, Space.Self);
|
||||
}
|
||||
|
||||
private void UpdateArrows()
|
||||
{
|
||||
float value = _value;
|
||||
float angle = Mathf.Lerp(0f, _maxAngle, Mathf.Abs(value));
|
||||
bool isLeft = value < 0;
|
||||
bool isRight = value > 0;
|
||||
bool follow = false;
|
||||
float squeeze = Mathf.Lerp(0f, _squeezeLength, _progress);
|
||||
|
||||
angle = Mathf.Max(angle, _trailLength);
|
||||
|
||||
UpdateArrowPosition(isRight ? angle + squeeze : _trailLength, _rightArrow.transform);
|
||||
RotateTrail(follow && isRight ? angle - _trailLength : 0f, _rightTrail);
|
||||
UpdateTrail(isRight ? (follow ? _trailLength : angle) + squeeze : _trailLength, _rightTrail);
|
||||
|
||||
UpdateArrowPosition(isLeft ? -angle - squeeze : -_trailLength, _leftArrow.transform);
|
||||
RotateTrail(follow && isLeft ? -angle + _trailLength : 0f, _leftTrail);
|
||||
UpdateTrail(isLeft ? (follow ? _trailLength : angle) + squeeze : _trailLength, _leftTrail);
|
||||
}
|
||||
|
||||
private void UpdateArrowPosition(float angle, Transform arrow)
|
||||
{
|
||||
Quaternion rotation = Quaternion.AngleAxis(angle, Vector3.up);
|
||||
arrow.localPosition = rotation * Vector3.forward * _radius;
|
||||
arrow.localRotation = rotation * _rotationCorrectionLeft;
|
||||
}
|
||||
|
||||
private void RotateTrail(float angle, TubeRenderer trail)
|
||||
{
|
||||
trail.transform.localRotation = Quaternion.AngleAxis(angle, Vector3.up);
|
||||
}
|
||||
|
||||
private void UpdateTrail(float angle, TubeRenderer trail)
|
||||
{
|
||||
float max = _maxAngle + _squeezeLength;
|
||||
float segmentLenght = trail.TotalLength;
|
||||
float start = -100;
|
||||
float end = (max - angle - _margin) / max;
|
||||
|
||||
trail.StartFadeThresold = segmentLenght * start;
|
||||
trail.EndFadeThresold = segmentLenght * end;
|
||||
trail.InvertThreshold = false;
|
||||
trail.RedrawFadeThresholds();
|
||||
}
|
||||
|
||||
private void UpdateColors()
|
||||
{
|
||||
bool isSelection = Mathf.Abs(_progress) >= 1f;
|
||||
bool isLeft = _value < 0;
|
||||
bool isRight = _value > 0;
|
||||
|
||||
Color activeColor = isSelection? _highligtedColor : _enabledColor;
|
||||
|
||||
_leftMaterialBlock.MaterialPropertyBlock.SetColor(_colorShaderPropertyID, isLeft ? activeColor : _disabledColor);
|
||||
_rightMaterialBlock.MaterialPropertyBlock.SetColor(_colorShaderPropertyID, isRight ? activeColor : _disabledColor);
|
||||
|
||||
_leftMaterialBlock.UpdateMaterialPropertyBlock();
|
||||
_rightMaterialBlock.UpdateMaterialPropertyBlock();
|
||||
}
|
||||
|
||||
private TubePoint[] InitializeSegment(Vector2 minMax)
|
||||
{
|
||||
float lowLimit = minMax.x;
|
||||
float upLimit = minMax.y;
|
||||
int segments = Mathf.RoundToInt(Mathf.Repeat(upLimit - lowLimit, 360f) / _degreesPerSegment);
|
||||
TubePoint[] tubePoints = new TubePoint[segments];
|
||||
float segmentLenght = 1f / segments;
|
||||
for (int i = 0; i < segments; i++)
|
||||
{
|
||||
Quaternion rotation = Quaternion.AngleAxis(-i * _degreesPerSegment - lowLimit, Vector3.up);
|
||||
tubePoints[i] = new TubePoint()
|
||||
{
|
||||
position = rotation * Vector3.forward * _radius,
|
||||
rotation = rotation * _rotationCorrectionLeft,
|
||||
relativeLength = i * segmentLenght
|
||||
};
|
||||
}
|
||||
return tubePoints;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4c1459b1323037f40adf896ae60f0a57
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus 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.Locomotion
|
||||
{
|
||||
public class LocomotorSound : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private PlayerLocomotor _locomotor;
|
||||
|
||||
[SerializeField]
|
||||
private AdjustableAudio _translationSound;
|
||||
[SerializeField]
|
||||
private AdjustableAudio _translationDeniedSound;
|
||||
[SerializeField]
|
||||
private AdjustableAudio _snapTurnSound;
|
||||
|
||||
[SerializeField]
|
||||
private AnimationCurve _translationCurve = AnimationCurve.EaseInOut(0f, 0f, 2f, 1f);
|
||||
[SerializeField]
|
||||
private AnimationCurve _rotationCurve = AnimationCurve.EaseInOut(0f, 0f, 180f, 1f);
|
||||
[SerializeField]
|
||||
private float _pitchVariance = 0.05f;
|
||||
|
||||
protected bool _started;
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
this.BeginStart(ref _started);
|
||||
this.AssertField(_locomotor, nameof(_locomotor));
|
||||
this.EndStart(ref _started);
|
||||
}
|
||||
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
if (_started)
|
||||
{
|
||||
_locomotor.WhenLocomotionEventHandled += HandleLocomotionEvent;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnDisable()
|
||||
{
|
||||
if (_started)
|
||||
{
|
||||
_locomotor.WhenLocomotionEventHandled -= HandleLocomotionEvent;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleLocomotionEvent(LocomotionEvent locomotionEvent, Pose delta)
|
||||
{
|
||||
if (locomotionEvent.Translation > LocomotionEvent.TranslationType.Velocity)
|
||||
{
|
||||
PlayTranslationSound(delta.position.magnitude);
|
||||
}
|
||||
if (locomotionEvent.Rotation > LocomotionEvent.RotationType.Velocity)
|
||||
{
|
||||
PlayRotationSound(delta.rotation.y * delta.rotation.w);
|
||||
}
|
||||
if (locomotionEvent.Translation == LocomotionEvent.TranslationType.None
|
||||
&& locomotionEvent.Rotation == LocomotionEvent.RotationType.None)
|
||||
{
|
||||
PlayDenialSound(delta.position.magnitude);
|
||||
}
|
||||
}
|
||||
|
||||
private void PlayTranslationSound(float translationDistance)
|
||||
{
|
||||
float t = _translationCurve.Evaluate(translationDistance);
|
||||
float pitch = t + Random.Range(-_pitchVariance, _pitchVariance);
|
||||
_translationSound.PlayAudio(t, pitch);
|
||||
}
|
||||
|
||||
private void PlayDenialSound(float translationDistance)
|
||||
{
|
||||
float t = _translationCurve.Evaluate(translationDistance);
|
||||
float pitch = t + Random.Range(-_pitchVariance, _pitchVariance);
|
||||
_translationDeniedSound.PlayAudio(t, pitch);
|
||||
}
|
||||
|
||||
private void PlayRotationSound(float rotationLength)
|
||||
{
|
||||
float t = _rotationCurve.Evaluate(Mathf.Abs(rotationLength));
|
||||
float pitch = t + Random.Range(-_pitchVariance, _pitchVariance);
|
||||
_snapTurnSound.PlayAudio(t, pitch, rotationLength);
|
||||
}
|
||||
|
||||
#region Inject
|
||||
|
||||
public void InjectAllLocomotorSound(PlayerLocomotor locomotor)
|
||||
{
|
||||
InjectPlayerLocomotor(locomotor);
|
||||
}
|
||||
|
||||
public void InjectPlayerLocomotor(PlayerLocomotor locomotor)
|
||||
{
|
||||
_locomotor = locomotor;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 84f47d10845aedc409ea9f6cec618b5a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user