EffectAudio.cs 930 B

123456789101112131415161718192021222324252627282930313233
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. namespace HQFPSWeapons
  4. {
  5. public class EffectAudio : MonoBehaviour
  6. {
  7. [SerializeField]
  8. private string m_EffectName = string.Empty;
  9. [SerializeField]
  10. private SoundPlayer m_SoundPlayer = null;
  11. private static Dictionary<string, SoundPlayer> SOUND_PLAYERS = new Dictionary<string, SoundPlayer>();
  12. public void PlayAudio3D(float volume)
  13. {
  14. SOUND_PLAYERS[m_EffectName].PlayAtPosition(ItemSelection.Method.RandomExcludeLast, transform.position, volume);
  15. }
  16. public void PlayAudio2D(float volume)
  17. {
  18. SOUND_PLAYERS[m_EffectName].Play2D(ItemSelection.Method.RandomExcludeLast, volume);
  19. }
  20. private void Awake()
  21. {
  22. if(!SOUND_PLAYERS.ContainsKey(m_EffectName))
  23. SOUND_PLAYERS.Add(m_EffectName, m_SoundPlayer);
  24. }
  25. }
  26. }