private void RemoveOldEventInstanceIfKeyHasChanged() { if (!_soundEventInstance || _soundEventInstance.GetSoundEvent().key == key) { return; } _soundEventInstance.StopAndDestroy(); _soundEventInstance = null; }
public SoundEventInstance CreateSoundEventInstance(GameObject gameObject, SoundEvent soundEvent) { SoundEventInstance soundEventInstance = gameObject.AddComponent <SoundEventInstance>(); soundEventInstance.Initialize(soundEvent); if (!_soundEventInstances.ContainsKey(soundEvent.key)) { _soundEventInstances[soundEvent.key] = new List <SoundEventInstance>(); } RemoveOldInstanceIfApplicable(soundEvent); _soundEventInstances[soundEvent.key].Add(soundEventInstance); return(soundEventInstance); }
public SoundEventInstance CreateOneShotSoundEventInstance(SoundEvent soundEvent, Vector3 position) { if (!IsAllowedToPlay(soundEvent)) { return(null); } GameObject oneShotGameObject = new GameObject("One Shot - " + soundEvent.key); oneShotGameObject.transform.position = position; SoundEventInstance soundEventInstance = CreateSoundEventInstance(oneShotGameObject, soundEvent); soundEventInstance.MarkAsOneShot(); return(soundEventInstance); }
public void Play() { SoundEvent soundEvent = SoundAccess.GetInstance().RetrieveSoundEvent(key); RemoveOldEventInstanceIfKeyHasChanged(); if (!SoundEventInstanceManager.GetInstance().IsAllowedToPlay(soundEvent)) { return; } if (_soundEventInstance) { _soundEventInstance.Play(); return; } _soundEventInstance = SoundEventInstanceManager.GetInstance().CreateSoundEventInstance(gameObject, soundEvent); _soundEventInstance.Play(); }
public void Unregister(SoundEventInstance soundEventInstance) { SoundEvent soundEvent = soundEventInstance.GetSoundEvent(); _soundEventInstances[soundEvent.key].Remove(soundEventInstance); }