コード例 #1
0
        /// <summary>
        ///     Plays the sound effect for the specified SFX type. Can be played in 2D or 3D.
        /// </summary>
        /// <param name="sfxType">The type of Sound Effect to play</param>
        /// <param name="emitterPosition">The location to emit the sound from</param>
        private void PlaySoundEffect(SfxType sfxType, Vector3?emitterPosition = null)
        {
            if (!soundEffects.ContainsKey(sfxType))
            {
                Debug.WriteLine("No Sound for the key" + sfxType.ToString("G") + " found!");
                return;
            }

            SoundEffect sfx = soundEffects[sfxType];

            if (sfx != null)
            {
                SoundEffectInstance sei = sfx.CreateInstance();
                float volumeToApply     = currentSfxVolume;
                if (emitterPosition != null)
                {
                    emitter.Position  = (Vector3)emitterPosition;
                    listener.Position = listenerTransform.Translation;
                    sei.Apply3D(listener, emitter);
                }

                sei.Volume = volumeToApply;
                sei.Play();
                sfxInstances.Add(sei);
            }
        }
コード例 #2
0
    public void Play(SfxType type)
    {
        if (clips.ContainsKey(type) == false)
        {
            Debug.LogError("Sfx not loaded, type : " + type.ToString());
            return;
        }

        source.PlayOneShot(clips[type], source.volume);
    }
コード例 #3
0
ファイル: SfxManager.cs プロジェクト: penspanic/DDPGamejam
    public void Initialize()
    {
        if (IsInitialized == true)
        {
            return;
        }
        IsInitialized = true;

        for (int i = (int)SfxType.Undefined + 1; i < (int)SfxType.End_Of_Sfx; ++i)
        {
            SfxType type = (SfxType)i;
            clips.Add(type, Resources.Load <AudioClip>("Sounds/Sfx/" + type.ToString()));
        }

        Debug.Log("SfxManager Load end.");
    }
コード例 #4
0
    public void PlayLoop(SfxType type)
    {
        if (clips.ContainsKey(type) == false)
        {
            Debug.LogError("Sfx not loaded, type : " + type.ToString());
            return;
        }
        if (loopSourcesPool.RemainCount == 0)
        {
            AddLoopSource();
        }

        AudioSource loopSource = loopSourcesPool.Get();

        loopSource.volume = SoundManager.Instance.SfxVolume;
        loopSource.clip   = clips[type];
        loopSource.loop   = true;
        loopSource.Play();

        loopingSources.Add(new KeyValuePair <SfxType, AudioSource>(type, loopSource));
    }
コード例 #5
0
 public void PlaySE(SfxType audio, float delay = 0.0f)
 {
     PlaySE(audio.ToString(), delay);
 }