//---------------------------------------------------------------------------------------------------------------
    public AudioSource PlaySound(AudioId audioId, float volume = 1)
    {
        SoundCollectionBlock soundCollection;

        clipsCollection.TryGetValue(audioId, out soundCollection);
        if (soundCollection == null)
        {
            Debug.Log(message: "<color=red>UNEXPECTED ERROR:</color> PlaySound was called for ID:" + audioId.ToString() + ", but no collection with this ID exists. Ignored. Check the enum.");
            return(null);
        }

        AudioClip clip;

        clip = soundCollection.GetClip();
        if (clip == null)
        {
            Debug.Log(message: "<color=red>ERROR:</color> PlaySound was called for ID:" + audioId.ToString() + ", but collection has no sounds and returns null. Ignored.");
            return(null);
        }

        AudioSource source = gameObject.AddComponent <AudioSource>();

        source.mute = !Game.Settings.SoundEnabled;
        source.clip = clip;

        source.Play();

        activeSoundSources.Add(source);

        return(source);
    }
Example #2
0
        public void SetBackground(AudioId id)
        {
            var items = _audioLibrary.items.FindAll((obj) => obj.id == id);

            if (items.Count > 0)
            {
                var item = items[0];
                var clip = item.clip;

                if (!_backgroundSource.isPlaying)
                {
                    _backgroundSource.clip   = clip;
                    _backgroundSource.volume = item.volume;
                    _backgroundSource.Play();
                }
                else if (_backgroundSource.isPlaying && _backgroundSource.clip != clip)
                {
                    DOTween.Kill(_backgroundSource);
                    _backgroundSource.DOFade(0f, FADE_DURATION).OnComplete(() =>
                    {
                        _backgroundSource.clip = clip;
                        _backgroundSource.Play();
                        _backgroundSource.DOFade(item.volume, FADE_DURATION);
                    });
                }
            }
            else
            {
                StopBackground();
                Log.WarningFormat("[AudioServiceComponent] Could not find audio clip with id={0}", id);
            }
        }
Example #3
0
 public override byte[] ToBytes()
 {
     return(TLUtils.Combine(
                TLUtils.SignatureToBytes(Signature),
                AudioId.ToBytes(),
                Caption.ToBytes()));
 }
Example #4
0
        public override void ToStream(Stream output)
        {
            output.Write(TLUtils.SignatureToBytes(Signature));

            AudioId.ToStream(output);
            Caption.ToStream(output);
        }
 public void Play(AudioId id)
 {
     if (fxEnabled)
     {
         _audioServiceComponent.Play(id);
     }
 }
 public void PlayClip(AudioId audioId, Transform target, float volume)
 {
     if (audioClipCache != null && audioClipCache.ContainsKey(audioId))
     {
         var audioInfo = audioClipCache[audioId];
         PlayClip(audioInfo.clip, target, volume == -1 ? audioInfo.volume : volume);
     }
 }
 public void PlayClip(AudioId audioId, out AudioSource playedSource, Transform target, float volume)
 {
     playedSource = null;
     if (audioClipCache != null && audioClipCache.ContainsKey(audioId))
     {
         var audioInfo = audioClipCache[audioId];
         PlayClip(audioInfo.clip, out playedSource, target, volume == -1 ? audioInfo.volume : volume, PlayOptions.PlayOnce);
     }
 }
 public void SetBackground(AudioId id)
 {
     if (musicEnabled)
     {
         _audioServiceComponent.SetBackground(id);
     }
     else
     {
         _audioServiceComponent.StopBackground();
     }
 }
        public bool Equals(AudioScriptObject other)
        {
            if (other == null)
            {
                return(false);
            }

            return(Index.Equals(other.Index) &&
                   AudioId.Equals(other.AudioId) &&
                   Position.Equals(other.Position) &&
                   AudioEntity.Equals(other.AudioEntity));
        }
 public void PlayClip(AudioId id)
 {
     if (m_Anim.GetBool("isPrincess"))
     {
         myAudioSource.clip = clipStoragePrincess[(int)id];
     }
     else
     {
         myAudioSource.clip = clipStorageDragon[(int)id];
     }
     myAudioSource.Play();
 }
Example #11
0
        public void Play(AudioId id)
        {
            var items = _audioLibrary.items.FindAll((obj) => obj.id == id);

            if (items.Count == 0)
            {
                Log.WarningFormat("[AudioServiceComponent] Could not find audio clip with id={0}", id);
                return;
            }

            var item = items[_random.Next(0, items.Count)];

            _audioSource.PlayOneShot(item.clip, item.volume);
        }
Example #12
0
    //---------------------------------------------------------------------------------------------------------------
    /// <summary>
    /// Start playing new sound with audioIdas a music track.
    /// </summary>
    /// <param name="audioId"></param>
    /// <param name="loop">if true will try to play another track from a collection attached to this ID.</param>
    /// <param name="volume"></param>

    /// <param name="overrideTime"></param>
    /// Disabled because lead to unpleasant glitches.
    /// <returns></returns>
    public AudioSource PlayMusic(AudioId audioId, bool loop = true, float volume = 1, float overrideTime = 0f)
    {
        // it was preventing proper loop with different tracks, because they have same ID.
        //if (IsPlaying(audioId))
        //{
        //  return GetActiveSourcesById(audioId).FirstOrDefault();
        //}


        SoundCollectionBlock soundCollection;

        clipsCollection.TryGetValue(audioId, out soundCollection);
        if (soundCollection == null)
        {
            Debug.Log(message: "<color=red>UNEXPECTED ERROR:</color> PlayMusic was called for ID:" + audioId.ToString() + ", but no collection with this ID exists. Ignored. Check the enum.");
            return(null);
        }

        AudioClip clip;

        clip          = soundCollection.GetClip(LastMusicClip);
        LastMusicClip = clip;
        if (clip == null)
        {
            Debug.Log(message: "<color=red>ERROR:</color> PlayMusic was called for ID:" + audioId.ToString() + ", but collection has no sounds and returns null. Ignored.");
            return(null);
        }

        AudioSource source = gameObject.AddComponent <AudioSource>();

        source.volume = volume;
        //source.loop = loop;
        source.clip = clip;
        source.mute = !Game.Settings.MusicEnabled;

        this.MusicLoop  = loop;
        this.LoopId     = audioId;
        this.LoopVolume = volume;

        source.Play();

        this.StopAllMusic(overrideTime);

        this.activeMusicSource = source;

        return(source);
    }
Example #13
0
    //---------------------------------------------------------------------------------------------------------------
    private List <AudioSource> GetActiveSourcesById(AudioId id)
    {
        List <AudioSource> result = new List <AudioSource>();

        // Music
        if (activeMusicSource != null)
        {
            if (ClipToId(activeMusicSource.clip) == id)
            {
                result.Add(activeMusicSource);
            }
        }


        // Sound
        result.AddRange(activeSoundSources.Where(a => ClipToId(a.clip) == id));
        return(result);
    }
Example #14
0
        private void Update()
        {
            if (_lazerDownInstance == null)
            {
                return;
            }

            // move lazer towards player
            Vector3 targetPosition = _player.transform.position + _lazerDownOffset;

            _lazerDownInstance.transform.position   = Vector3.MoveTowards(_lazerDownInstance.transform.position, targetPosition, LazerSpeed * Time.deltaTime);
            _lazerScorchInstance.transform.position = Vector3.MoveTowards(_lazerDownInstance.transform.position, targetPosition, LazerSpeed * Time.deltaTime);
            // determine lazer state from animation
            Animator lazerDownAnimator = _lazerDownInstance.GetComponent <Animator>(); _lazerDownInstance.GetComponent <Animator>();
            bool     lazerActive       = lazerDownAnimator.GetCurrentAnimatorStateInfo(0).normalizedTime >= LazerActiveFrame;
            bool     lazerFinished     = lazerDownAnimator.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1.0f;

            if (lazerActive)
            {
                if (_lazerDownInstance.GetComponent <BoxCollider2D>().enabled == false)
                {
                    //_lazerDownInstance.GetComponentsInChildren<TrailRenderer>(true)[0].gameObject.SetActive(true);
                    _lazerScorchInstance.GetComponentInChildren <TrailRenderer>(true).gameObject.SetActive(true);
                    _dischargeSfxId = AudioManager.Play(dischargeSfx, AudioCategory.Effect);
                }

                // enable damage collider
                _lazerDownInstance.GetComponent <BoxCollider2D>().enabled = true;

                _cameraShakeBehaviour.Shake(CameraShakeStrength, 0.1f);
            }

            if (lazerFinished)
            {
                ResetLazer();

                // reset animation
                _animator.Play("Reset");
            }
        }
Example #15
0
 /// <summary>
 /// Fires the chargers lazer prefabs, this is called by a callback
 /// within the enemy charger animation.
 /// </summary>
 public void Fire()
 {
     if (_player.GetComponent <HealthBehaviour>().Value <= 0 && !_animator.GetCurrentAnimatorStateInfo(0).IsName("Idle"))
     {
         _animator.Play("Idle");
     }
     else
     {
         _lazerUpInstance   = GameObject.Instantiate(_lazerUpPrefab, _projectileSpawn.position + _lazerUpOffset, Quaternion.identity);
         _lazerDownInstance = GameObject.Instantiate(_lazerDownPrefab, _player.transform.position + _lazerDownOffset, Quaternion.identity);
         _lazerDownInstance.AddComponent <LazerDownDamageBehaviour>();
         _chargeSfxId = AudioManager.Play(chargeSfx, AudioCategory.Effect);
         if (_lazerScorchInstance != null)
         {
             Destroy(_lazerScorchInstance);
             _lazerScorchInstance = GameObject.Instantiate(_lazerScorchTrail, _player.transform.position + _lazerDownOffset, Quaternion.identity);
         }
         else
         {
             _lazerScorchInstance = GameObject.Instantiate(_lazerScorchTrail, _player.transform.position + _lazerDownOffset, Quaternion.identity);
         }
     }
 }
Example #16
0
 public override string Serialize()
 {
     return(AudioId.ToHex() + ".wem");
 }
Example #17
0
 public static void PlaySound(this AudioId id)
 {
     Game.AudioManager.PlaySound(id);
 }
Example #18
0
 public static string GetPath(this AudioId id)
 {
     return(id.GetDesc());
 }
Example #19
0
 public static void PlayMusic(this AudioId id)
 {
     Game.AudioManager.PlayMusic(id);
 }
    private void ShowMessageOfTheDay()
    {
        if (GameManager.Instance.GameEnded)
        {
            SoundManager.Instance.StopAll();
            var messageForEnd =
                ScriptableObjectHolder.Instance.GameDatabase.MessageForEndGame.Find(
                    m => m.EndOption == GameManager.Instance.End).Message;

            AudioId sound = AudioId.Ambiance;
            switch (GameManager.Instance.End)
            {
            case EndOptions.Win:
                SoundManager.Instance.PlayAudio(AudioId.Win);
                break;

            case EndOptions.ShitterInTheQueue:
            case EndOptions.ShitOverflow:
                SoundManager.Instance.PlayAudio(AudioId.FartLong, AudioId.FartMedium, AudioId.FartShort);
                break;

            case EndOptions.Killed:
                sound = AudioId.Stab;
                break;

            case EndOptions.DenyRoialty:
                sound = AudioId.Hanging;
                break;

            case EndOptions.DenyCleric:
                sound = AudioId.Guillotine;
                break;
            }

            if (sound != AudioId.Ambiance)
            {
                SoundManager.Instance.PlayAudio(AudioId.Horror);
            }

            HouseGuiManager.ShowMessageOfTheDay(messageForEnd, () =>
            {
                if (sound != AudioId.Ambiance)
                {
                    SoundManager.Instance.Stop(AudioId.Horror);
                    SoundManager.Instance.PlayAudio(sound);
                }
            }, true);
            return;
        }

        bool hideDiary = true;

        string messageOfTheDay;
        var    dataBase = ScriptableObjectHolder.Instance.GameDatabase;

        if (!GameManager.Instance.CanDenyCleric && !GameManager.Instance.ClericMessageShowed)
        {
            SoundManager.Instance.PlayAudio(AudioId.Threat);
            messageOfTheDay = dataBase.LetterFromCleric;
            GameManager.Instance.ClericMessageShowed = true;
        }
        else if (GameManager.Instance.ThreatCount > 0)
        {
            messageOfTheDay = dataBase.MessageForHouseThrashed;
            SoundManager.Instance.PlayAudio(AudioId.Threat);
        }
        else
        {
            SoundManager.Instance.PlayAudio(AudioId.Ambiance);
            messageOfTheDay = dataBase.WakeupMessages[Random.Range(0, dataBase.WakeupMessages.Count)];
            hideDiary       = false;
        }

        HouseGuiManager.ShowMessageOfTheDay(messageOfTheDay, null, hideDiary);
    }
Example #21
0
 //---------------------------------------------------------------------------------------------------------------
 public void StopAudio(AudioId id, float duration = 0f)
 {
     GetActiveSourcesById(id).ForEach(s => s.DOFade(0, duration).OnComplete(s.Stop));
 }
Example #22
0
 //---------------------------------------------------------------------------------------------------------------
 private bool IsPlaying(AudioId id)
 {
     return(!GetActiveSourcesById(id).IsEmpty());
 }