using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AudioCtroller : SingletonMono<AudioCtroller> {
/// <summary>
/// 播放背景音乐
/// </summary>
private AudioSource aud_BGMusic;
/// <summary>
/// 播放特效
/// </summary>
private AudioSource aud_Effect;
/// <summary>
/// 播放器音量设置
/// </summary>
public float aud_BGvolume
{
set
{
aud_BGMusic.volume = value;
}
get
{
return aud_BGMusic.volume;
}
}
public float aud_Efvolume
{
set
{
aud_Effect.volume = value;
}
get
{
return aud_Effect.volume;
}
}
void Start () {
}
/// <summary>
/// 重写父类Awake,初始化播放组件
/// </summary>
protected override void Awake()
{
base.Awake();
//播放组件初始化设置
aud_BGMusic = gameObject.AddComponent<AudioSource>();
aud_BGMusic.loop = true;
aud_BGMusic.playOnAwake = true;
aud_Effect = gameObject.AddComponent<AudioSource>();
aud_Effect.loop = false;
aud_Effect.playOnAwake = true;
}
//播放
public void PlayMusicByName(object name,bool isRestart = false)
{
string currentName = string.Empty;
if (aud_BGMusic.clip != null)
{
currentName = aud_BGMusic.clip.name;
}
//1.根据名字加载资源
AudioClip clip = ResourseLoad.Instance.ResourceLoadObj<AudioClip>(name);
//AudioClip clip = Resources.Load<AudioClip>(name);
if (clip != null)
{
if (currentName == clip.name && !isRestart)
{
return;
}
}
aud_BGMusic.clip = clip;
aud_BGMusic.Play();
}
public void PlayBgMusic(Music.Music_Main BGName, bool isRestart = false)
{
PlayMusicByName(BGName, isRestart);
}
//public void PlayBgMusic(Music.Music_Item BGName, bool isRestart = false)
//{
// PlayMusicByName(BGName, isRestart);
//}
private void PlayEffectByName(object name, bool isEffect = true, float volume = 1f)
{
AudioClip clip = ResourseLoad.Instance.ResourceLoadObj<AudioClip>(name);
if (clip == null)
{
return;
}
if (isEffect)
{
aud_Effect.PlayOneShot(clip, volume);
}
else
{
AudioSource.PlayClipAtPoint(clip, Camera.main.transform.position, volume);
}
}
public void PlayEffect(Music.Music_Main effect, bool isEffect = true, float volume = 1f)
{
PlayEffectByName(effect, isEffect, volume);
}
public void PlayEffect(Music.Music_Item effect, bool isEffect = true, float volume = 1f)
{
PlayEffectByName(effect, isEffect, volume);
}
public void PlayEffect(Music.Music_Feeds effect, bool isEffect = true, float volume = 1f)
{
PlayEffectByName(effect, isEffect, volume);
}
public void PlayEffect(Music.Monsters effect, bool isEffect = true, float volume = 1f)
{
PlayEffectByName(effect, isEffect, volume);
}
public void PlayEffect(Music.Towers effect, bool isEffect = true, float volume = 1f)
{
PlayEffectByName(effect, isEffect, volume);
}
}
游戏音效管理
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 【蝴蝶效应】 蝴蝶效应:上个世纪70年代,美国一个名叫洛伦兹的气象学家在解释空气系统理论时说,亚马逊雨林一只蝴蝶...
- 4.1管理对象 谈到现在,终于可以谈谈我心目中的“游戏式管理”了。 简单来看,一个员工进企业首先是为了良好的职业发...