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.
66 lines
1.4 KiB
66 lines
1.4 KiB
3 years ago
|
using UnityEngine;
|
||
|
using System.Collections;
|
||
|
|
||
|
|
||
|
public enum BoomType : int
|
||
|
{
|
||
|
None = 0,
|
||
|
/// <summary>
|
||
|
/// 爆炸类型
|
||
|
/// </summary>
|
||
|
Expolsion = 1,
|
||
|
/// <summary>
|
||
|
/// 变形类型
|
||
|
/// </summary>
|
||
|
Twist = 2
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 声音控制类
|
||
|
/// </summary>
|
||
|
public class AudioManager
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 单例
|
||
|
/// </summary>
|
||
|
private static AudioManager instance;
|
||
|
private static AudioSource audio;
|
||
|
public static AudioManager Instance
|
||
|
{
|
||
|
get
|
||
|
{
|
||
|
if (null == instance || null == audio)
|
||
|
{
|
||
|
instance = new AudioManager();
|
||
|
GameObject obj = new GameObject();
|
||
|
obj.hideFlags = HideFlags.HideAndDontSave;
|
||
|
|
||
|
audio = obj.AddComponent<AudioSource>();
|
||
|
|
||
|
}
|
||
|
return instance;
|
||
|
}
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 播放声音
|
||
|
/// </summary>
|
||
|
/// <param name="audio">音源</param>
|
||
|
public void Play(BoomType type)
|
||
|
{
|
||
|
switch (type)
|
||
|
{
|
||
|
case BoomType.Expolsion:
|
||
|
var exp = Resources.Load<AudioClip>("Audio/explosion");
|
||
|
audio.clip = exp;
|
||
|
break;
|
||
|
case BoomType.Twist:
|
||
|
var twist = Resources.Load<AudioClip>("Audio/twist");
|
||
|
audio.clip = twist;
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
audio.Play();
|
||
|
}
|
||
|
|
||
|
}
|