//TODO Sound.SLOTに対応 public void PlaySE(Sound.ID sound_id) { AudioClip clip = this.clips[(int)sound_id]; Slot slot = this.slots[0]; slot.source.PlayOneShot(clip); }
public void playSE(Sound.ID sound_id,Sound.SLOT slot_index = Sound.SLOT.SE0) { if (this.is_play_sound) { do { AudioClip clip = this.clips[(int)sound_id]; if (clip == null) { break; } Slot slot = this.slots[(int)slot_index]; if (slot.single_shot) { if (slot.source.isPlaying) { break; } slot.source.clip = clip; slot.source.Play(); } else { slot.source.PlayOneShot(clip); } } while(false); } }
public void playSE(Sound.ID sound_id) { if (this.is_play_sound) { AudioClip clip = this.clips[(int)sound_id]; if (clip != null && this.slots != null) { this.slots[(int)Sound.SLOT.SE0].source.PlayOneShot(clip); } } }
// ================================================================ // public void playBGM(Sound.ID sound_id) { if (this.is_play_sound) { AudioClip clip = this.clips[(int)sound_id]; if (clip != null && this.slots != null) { Slot slot = this.slots[(int)Sound.SLOT.BGM]; slot.source.clip = clip; slot.source.Play(); } } }
// ================================================================ // // MonoBehaviour에서 상속. void Awake() { // enum과 같은 순서가 되게 clip을 정렬한다. var temp_clips = new List <AudioClip>(); for (int i = 0; i < (int)Sound.ID.NUM; i++) { Sound.ID sound_id = (Sound.ID)i; string clip_name; if (i == (int)Sound.ID.SYSTEM00) { clip_name = "all_system00"; } else { clip_name = sound_id.ToString().ToLower(); } AudioClip clip = this.clips.Find(x => x.name == clip_name); temp_clips.Add(clip); } this.clips = temp_clips; // 슬롯(AudioSource). this.slots = new List <Slot>(); for (int i = 0; i < (int)Sound.SLOT.NUM; i++) { Slot slot = new Slot(); slot.source = this.gameObject.AddComponent <AudioSource>(); slot.timer = 0.0f; this.slots.Add(slot); } this.slots[(int)Sound.SLOT.BGM].source.loop = true; this.slots[(int)Sound.SLOT.SE_GET_ITEM].single_shot = true; }
// 일정 간격으로 효과음을 울립니다. // (매 프레임 호출해도 일정 간격으로 울립니다). public void playSEInterval(Sound.ID sound_id,float interval,Sound.SLOT slot_id) { if (this.is_play_sound && this.slots != null) { Slot slot = this.slots[(int)slot_id]; if (slot.timer == 0.0f) { AudioClip clip = this.clips[(int)sound_id]; if (clip != null) { slot.source.PlayOneShot(clip); } } slot.timer += Time.deltaTime; if (slot.timer >= interval) { slot.timer = 0.0f; } } }