hand
_1_7_118
4
返回栏目
1k
0.2k
0.5k
0.1k
0k
0.2k
0k
0.7k
0k
0k
0.4k
0.1k
4k
0.2k
0.1k
2k
0.2k
0.2k
0k
0k
0.5k
0k
0.9k
0.1k
1k
0.9k
2k
1k
2k
0.9k
1k
0k
1k
0k
1k
1k
1k
1k
0k
1k
1k
1k
0k
3k
1k
0k
0.3k
1k
0.3k
0.9k
0k
8k
9k
6k
2k
1k
2k
1k
1k
2k
0.6k
1k
0.6k
1k
0.5k
0.2k
2k
2k
2k
1k
2k
0k
0.8k
0.8k
1k
0k
0k
0k
0k
0k
0k
0k
0k
0.3k
0.4k
0.8k
0.3k
5k
1k
3k
7k
6k
3k
3k
1k
0.2k
2k
3k
2k
0.4k
0.5k
3k
2k
7k
3k
4k
2k
1k
6k
6k
1k
1k
0.9k
0.2k
0.3k
0.9k
1k
0k
0.8k
2k
0k
0.4k
0.1k
1k
0.9k
0.2k
1k
1k
0.5k
0k
0k
0.4k
4k
0.4k
2k
3k
1k
1k
1k
3k
5k
0k
1k
2k
0.5k
0k
1k
0k
1k
0.5k
0.8k
返回Unity - 游戏引擎栏目
作者:
贺及楼
成为作者
更新日期:2023-09-17 10:59:05
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AudioManager : BaseManager {
public AudioManager(GameFacade facade) : base(facade) { }
private const string Sound_Prefix = "Sounds/";
public const string Sound_Alert = "Alert";
public const string Sound_ArrowShoot = "ArrowShoot";
public const string Sound_Bg_Fast = "Bg(fast)";
public const string Sound_Bg_Moderate = "Bg(moderate)";
public const string Sound_ButtonClick = "ButtonClick";
public const string Sound_Miss = "Miss";
public const string Sound_ShootPerson = "ShootPerson";
public const string Sound_Timer = "Timer";
private AudioSource bgAudioSource;
private AudioSource normalAudioSource;
public override void OnInit()
{
GameObject audioSourceGO = new GameObject("AudioSource(GameObject)");
bgAudioSource = audioSourceGO.AddComponent<AudioSource>();
normalAudioSource = audioSourceGO.AddComponent<AudioSource>();
PlaySound(bgAudioSource, LoadSound(Sound_Bg_Moderate),0.5f, true);
}
public void PlayBgSound(string soundName)
{
PlaySound(bgAudioSource, LoadSound(soundName), 0.5f, true);
}
public void PlayNormalSound(string soundName)
{
PlaySound(normalAudioSource, LoadSound(soundName), 1f);
}
private void PlaySound( AudioSource audioSource,AudioClip clip,float volume, bool loop=false)
{
audioSource.clip = clip;
audioSource.volume = volume;
audioSource.loop = loop;
audioSource.Play();
}
private AudioClip LoadSound(string soundsName)
{
return Resources.Load<AudioClip>(Sound_Prefix + soundsName);
}
}
Unity - 游戏引擎
整章节共151节
快分享给你的小伙伴吧 ~