2026-05-21 23:37:34 +09:00
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.Audio;
|
|
|
|
|
using Platinio.TweenEngine;
|
|
|
|
|
|
|
|
|
|
namespace VRBeats
|
|
|
|
|
{
|
|
|
|
|
[RequireComponent(typeof(AudioSource))]
|
|
|
|
|
public class AudioManager : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
[SerializeField] private AudioMixerGroup mixerGroup = null;
|
|
|
|
|
[SerializeField] private float fadeOutTime = 4.0f;
|
|
|
|
|
|
|
|
|
|
private AudioSource audioSource = null;
|
|
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
|
{
|
|
|
|
|
audioSource = GetComponent<AudioSource>();
|
|
|
|
|
audioSource.outputAudioMixerGroup = mixerGroup;
|
|
|
|
|
|
|
|
|
|
ResetThisComponent();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ResetThisComponent()
|
|
|
|
|
{
|
|
|
|
|
SetAudioMixerPitch(1.0f);
|
|
|
|
|
gameObject.CancelAllTweens();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public BaseTween BlendAudioMixerPitch(float from ,float to)
|
|
|
|
|
{
|
|
|
|
|
return PlatinioTween.instance.ValueTween(from , to , fadeOutTime).SetEase(Ease.EaseOutExpo).SetOnUpdateFloat(delegate (float v)
|
|
|
|
|
{
|
|
|
|
|
if(audioSource != null)
|
|
|
|
|
SetAudioMixerPitch(v);
|
|
|
|
|
}).SetOwner(gameObject);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetAudioMixerPitch(float value)
|
|
|
|
|
{
|
|
|
|
|
audioSource.outputAudioMixerGroup.audioMixer.SetFloat("Pitch", value);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-22 14:32:25 +09:00
|
|
|
public void PlayClip(AudioClip clip)
|
|
|
|
|
{
|
|
|
|
|
audioSource.clip = clip;
|
|
|
|
|
audioSource.Play();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float CurrentTime => audioSource != null ? audioSource.time : 0f;
|
|
|
|
|
|
2026-05-21 23:37:34 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|