增加A2WToolBox工具集,增加Launch场景核LaunchPanel
This commit is contained in:
133
Assets/A2WToolBox/Runtime/AudioManager/AudioPlayer.cs
Normal file
133
Assets/A2WToolBox/Runtime/AudioManager/AudioPlayer.cs
Normal file
@@ -0,0 +1,133 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace A2W
|
||||
{
|
||||
public class AudioPlayer : Singleton<AudioPlayer>
|
||||
{
|
||||
public float bgmVolume
|
||||
{
|
||||
get
|
||||
{
|
||||
return _bgmVolume;
|
||||
}
|
||||
set
|
||||
{
|
||||
_bgmVolume = value;
|
||||
if (bgmPlayer is null) return;
|
||||
bgmPlayer.volume = _bgmVolume;
|
||||
}
|
||||
}
|
||||
public float soundVolume
|
||||
{
|
||||
get
|
||||
{
|
||||
return _soundVolume;
|
||||
}
|
||||
set
|
||||
{
|
||||
_soundVolume = value;
|
||||
if (soundPlayers is null) return;
|
||||
foreach (var player in soundPlayers)
|
||||
{
|
||||
player.volume = _soundVolume;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private float _bgmVolume = 0.5f;
|
||||
private float _soundVolume = 0.5f;
|
||||
|
||||
private AudioSource bgmPlayer;
|
||||
private List<AudioSource> soundPlayers;
|
||||
|
||||
public void PlayBGM(AudioClip clip)
|
||||
{
|
||||
if (bgmPlayer is null)
|
||||
{
|
||||
bgmPlayer = CreateAudioSource("BGMPlayer");
|
||||
}
|
||||
bgmPlayer.clip = clip;
|
||||
bgmPlayer.loop = true;
|
||||
bgmPlayer.volume = bgmVolume;
|
||||
bgmPlayer.Play();
|
||||
}
|
||||
|
||||
public void PauseBGM()
|
||||
{
|
||||
bgmPlayer.Pause();
|
||||
}
|
||||
|
||||
public void UnPauseBGM()
|
||||
{
|
||||
bgmPlayer.UnPause();
|
||||
}
|
||||
|
||||
public void StopBGM()
|
||||
{
|
||||
bgmPlayer.Stop();
|
||||
}
|
||||
|
||||
public void PlaySound(AudioClip clip)
|
||||
{
|
||||
AudioSource soundPlayer = GetEmptyAudioSource();
|
||||
soundPlayer.volume = soundVolume;
|
||||
soundPlayer.PlayOneShot(clip);
|
||||
}
|
||||
|
||||
public void PauseAllSound()
|
||||
{
|
||||
foreach (var player in soundPlayers)
|
||||
{
|
||||
player.Pause();
|
||||
}
|
||||
}
|
||||
|
||||
public void UnPauseAllSound()
|
||||
{
|
||||
foreach (var player in soundPlayers)
|
||||
{
|
||||
player.UnPause();
|
||||
}
|
||||
}
|
||||
|
||||
public void StopAllSound()
|
||||
{
|
||||
foreach (var player in soundPlayers)
|
||||
{
|
||||
player.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
private AudioSource GetEmptyAudioSource()
|
||||
{
|
||||
if (soundPlayers is null)
|
||||
{
|
||||
soundPlayers = new List<AudioSource>();
|
||||
}
|
||||
|
||||
foreach (var player in soundPlayers)
|
||||
{
|
||||
if (player.isPlaying is false)
|
||||
{
|
||||
return player;
|
||||
}
|
||||
}
|
||||
|
||||
AudioSource audioSource = CreateAudioSource("SoundPlayer");
|
||||
soundPlayers.Add(audioSource);
|
||||
return audioSource;
|
||||
}
|
||||
|
||||
private AudioSource CreateAudioSource(string name)
|
||||
{
|
||||
GameObject go = new GameObject();
|
||||
go.name = name;
|
||||
go.transform.SetParent(transform, false);
|
||||
return go.AddComponent<AudioSource>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
11
Assets/A2WToolBox/Runtime/AudioManager/AudioPlayer.cs.meta
Normal file
11
Assets/A2WToolBox/Runtime/AudioManager/AudioPlayer.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2a9a44b3a4ac8264aa439ae804a1fe64
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user