Super Knight : Enter the Dungeon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

78 lines
1.8 KiB

using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(AudioSource))]
public class SoundPlayer : MonoBehaviour
{
public AudioSource audioSource;
float volume;
private void Awake()
{
if (audioSource == null)
audioSource = GetComponent<AudioSource>();
volume = audioSource.volume;
}
public void Play(float pitch = 1, bool PLAY = true)
{
if(audioSource == null)
audioSource = GetComponent<AudioSource>();
audioSource.pitch = pitch;
audioSource.volume = volume;
if (PLAY)
{
audioSource.Play();
Play_Sync();
}
else
audioSource.Stop();
}
public float durationFadeOut = 0.5f;
public void Play_Fade(bool PLAY = true)
{
if (audioSource == null)
audioSource = GetComponent<AudioSource>();
if (PLAY)
{
audioSource.Play();
Play_Sync();
}
else
{
float vol2 = audioSource.volume;
audioSource.DOFade(0, durationFadeOut).OnComplete(() =>
{
audioSource.Stop();
audioSource.volume = vol2;
});
}
}
public List<SoundPlayer> syncs;
public void Play_Sync()
{
for (int i = 0; i < syncs.Count; i++)
SoundManager.Instance.EffectPlay(syncs[i].gameObject);
}
public void Volume(float rate, System.Action OnEnd)
{
audioSource.DOFade(volume * rate, durationFadeOut).OnComplete(() =>
{
audioSource.volume = volume * rate;
if (OnEnd != null)
OnEnd();
});
}
public void Volume(float rate)
{
audioSource.volume = volume * rate;
}
}