Пример #1
0
        private void RemoveOldEventInstanceIfKeyHasChanged()
        {
            if (!_soundEventInstance || _soundEventInstance.GetSoundEvent().key == key)
            {
                return;
            }

            _soundEventInstance.StopAndDestroy();

            _soundEventInstance = null;
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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();
        }
Пример #5
0
        public void Unregister(SoundEventInstance soundEventInstance)
        {
            SoundEvent soundEvent = soundEventInstance.GetSoundEvent();

            _soundEventInstances[soundEvent.key].Remove(soundEventInstance);
        }