| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- /* 音频管理者 */
- public class AudioMgr : MonoBehaviour
- {
- private AudioSource audioSource;
- public static AudioMgr ins;
- public static void Init()
- {
- if (!ins) {
- GameObject audioMgr = new GameObject("AudioMgr");
- ins = audioMgr.AddComponent<AudioMgr>();
- DontDestroyOnLoad(audioMgr);
- }
- }
- void Awake() {
- this.audioSource = this.gameObject.AddComponent<AudioSource>();
- }
- public void Play(string path, AudioSource audioSource) {
- AudioClip audioClip = Resources.Load<AudioClip>(path);
- if (audioSource == null) {
- audioSource = this.audioSource;
- }
- audioSource.clip = audioClip;
- if (UserSettings.ins.openEffect) {
- audioSource.Play();
- }
- }
- public static AudioSource GetAudioSource(GameObject target) {
- AudioSource audioSource = target.GetComponent<AudioSource>();
- if (audioSource == null) {
- audioSource = target.AddComponent<AudioSource>();
- }
- return audioSource;
- }
- public void PlayShoot(AudioSource audioSource) {
- this.Play("Audios/shoot", audioSource);
- }
- public void PlayHit(AudioSource audioSource) {
- this.Play("Audios/hit", audioSource);
- }
- public void PlayCheer(bool cheer) {
- this.Play("Audios/" + (cheer ? "喝彩" : "喝倒彩"), null);
- }
- public void PlayBtn() {
- this.Play("Audios/btn", null);
- }
- public void PlayWin() {
- this.Play("Audios/win", null);
- }
- public void PlayArrowEnter() {
- this.Play("Audios/Animal/arrow_enter", null);
- }
- public void PlayAnimalEffect(string name, AudioSource audioSource) {
- this.Play("Audios/Animal/" + name, audioSource);
- }
- }
|