Example #1
0
 /// <summary>
 ///     Add the sound effect to the SFX Dictionary
 /// </summary>
 /// <param name="sfxType">The key to use in the dictionary</param>
 /// <param name="sfx">The Sound Effect to add</param>
 public void AddSoundEffect(SfxType sfxType, SoundEffect sfx)
 {
     if (!soundEffects.ContainsKey(sfxType) && sfx != null)
     {
         soundEffects.Add(sfxType, sfx);
     }
 }
Example #2
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);
            }
        }
    public void PlaySfxInner(SfxType sfxType, AudioSource audioSource)
    {
        var audioData = GetSfxAudioData(sfxType);

        if (audioData == null)
        {
            return;
        }
        audioSource.PlayOneShot(audioData.Clip);
    }
Example #4
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);
    }
Example #5
0
    public void PlaySfx(SfxType pType)
    {
        if (this.audioSfx.volume == 0)
        {
            return;
        }

        this.audioSfx.clip = this.clips[GetSfxTypeIdx(pType)];
        this.audioSfx.Play();
    }
Example #6
0
 public void Clear()
 {
     this.Reserved = Sfx.NONE;
     this.Playing  = Sfx.NONE;
     this.Priority = 0;
     this.Source   = null;
     this.Type     = 0;
     this.Volume   = 0;
     this.LastX    = Fixed.Zero;
     this.LastY    = Fixed.Zero;
 }
Example #7
0
 public void Clear()
 {
     Reserved = Sfx.NONE;
     Playing  = Sfx.NONE;
     Priority = 0;
     Source   = null;
     Type     = 0;
     Volume   = 0;
     LastX    = Fixed.Zero;
     LastY    = Fixed.Zero;
 }
Example #8
0
    static void Init()
    {
        GameObject obj = new GameObject("SoundManager");

        obj.AddComponent <SoundManager>();
        DontDestroyOnLoad(obj);

        GameObject bgmObj = new GameObject("BGM");

        bgmSource             = bgmObj.AddComponent <AudioSource>();
        bgmSource.playOnAwake = false;
        bgmSource.loop        = true;
        bgmSource.volume      = PlayerPrefs.GetFloat("BGMVolume", 1);
        bgmObj.transform.SetParent(obj.transform);

        GameObject sfxObj = new GameObject("SFX");

        sfxSource             = sfxObj.AddComponent <AudioSource>();
        sfxSource.playOnAwake = false;
        sfxSource.volume      = PlayerPrefs.GetFloat("SFXVolume", 1);
        sfxObj.transform.SetParent(obj.transform);

        // Resource 하위의 Sound들 저장
        AudioClip[] bgmClips = Resources.LoadAll <AudioClip>("Sounds/BGM");
        for (int i = 0; i < bgmClips.Length; i++)
        {
            try
            {
                BgmType bgmType = (BgmType)Enum.Parse(typeof(BgmType), bgmClips[i].name);
                bgmClipDic.Add(bgmType, bgmClips[i]);
            }
            catch
            {
                Debug.LogError("Need BgmType enum :" + bgmClips[i].name);
            }
        }

        AudioClip[] sfxClips = Resources.LoadAll <AudioClip>("Sounds/SFX");
        for (int i = 0; i < sfxClips.Length; i++)
        {
            try
            {
                SfxType sfxType = (SfxType)Enum.Parse(typeof(SfxType), sfxClips[i].name);
                sfxClipDic.Add(sfxType, sfxClips[i]);
            }
            catch
            {
                Debug.LogError("Need SfxType enum :" + sfxClips[i].name);
            }
        }

        SceneManager.sceneLoaded += OnSceneLoadComplete;
    }
Example #9
0
        public void PlaySfx(SfxType sfxType)
        {
            if (_dataManager.UserData.IsMuted == false)
            {
                _audio.clip = _audioSources.First(data => data.SfxType == sfxType).AudioClip;
                _audio.PlayDelayed(_delayTime);
            }

            if (_dataManager.UserData.IsMuted)
            {
                Debug.Log("Mute on");
            }
        }
Example #10
0
    public static void Play(SfxType sfx, bool randomPitch = false)
    {
        foreach (SoundEntry entry in m_instance.m_soundEffects)
        {
            if (entry.GetEffectType() == sfx)
            {
                m_instance.InternalPlay(entry.GetRandomClip(), randomPitch);
                return;
            }
        }

        Debug.LogWarning("No such sfx.");
    }
Example #11
0
    private int GetSfxTypeIdx(SfxType pType)
    {
        switch (pType)
        {
        case SfxType.PUT:
            return(0);

        case SfxType.SCORE:
            return(1);

        default:
            return(0);
        }
    }
Example #12
0
    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.");
    }
Example #13
0
        private float GetPitch(SfxType type, Sfx sfx)
        {
            if (this.random == null)
            {
                return(1.0F);
            }

            if (sfx == Sfx.ITEMUP || sfx == Sfx.TINK || sfx == Sfx.RADIO)
            {
                return(1.0F);
            }

            if (type == SfxType.Voice)
            {
                return(1.0F + 0.075F * (this.random.Next() - 128) / 128);
            }

            return(1.0F + 0.025F * (this.random.Next() - 128) / 128);
        }
Example #14
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));
    }
Example #15
0
    public void PlaySfx(SfxType sfx, int playerId) {

		activeSounds[(int)sfx] += 1;
        sounds[(int)sfx].volume = 1.0f;

        int currentPlayerSound = playerActiveSound[playerId];
        playerActiveSound[playerId] = (int)sfx;

        if (activeSounds[currentPlayerSound] > 0)
        {
            --activeSounds[currentPlayerSound];
            if (activeSounds[currentPlayerSound] == 0)
            {
                Debug.Log("Stopping sound " + currentPlayerSound);
                sounds[currentPlayerSound].volume = 0;
            }
            else
            {
                Debug.Log("_");
            }
        }
    }
Example #16
0
    public void StopLoop(SfxType type)
    {
        int findIndex = int.MinValue;

        for (int i = 0; i < loopingSources.Count; ++i)
        {
            if (loopingSources[i].Key == type)
            {
                findIndex = i;
                break;
            }
        }

        if (findIndex != int.MinValue)
        {
            AudioSource endedSource = loopingSources[findIndex].Value;
            endedSource.Stop();
            endedSource.clip = null;

            loopingSources.RemoveAt(findIndex);

            loopSourcesPool.Add(endedSource);
        }
    }
Example #17
0
 public void StartSound(Mobj mobj, Sfx sfx, SfxType type)
 {
     StartSound(mobj, sfx, type, 100);
 }
Example #18
0
 public void StartSound(Mobj mobj, Sfx sfx, SfxType type, int volume)
 {
 }
Example #19
0
 public void StartSound(Mobj mobj, Sfx sfx, SfxType type)
 {
 }
Example #20
0
 public SFXPlayEvent(SfxType sfx, bool isEnd)
 {
     Sfx   = sfx;
     IsEnd = isEnd;
 }
Example #21
0
        AudioSource IAudioPlayerModel.PlaySfx(SfxType sfxType)
        {
            var sfxInfo = sfxClipsConfig.SfxDictionary[sfxType];

            return(PlaySfx(sfxInfo));
        }
    private SfxAudioData GetSfxAudioData(SfxType sfxType)
    {
        var result = _sfxAudioDataList.Find(sfx => sfx.Type == sfxType);

        return(result);
    }
Example #23
0
 public SfxItem(SfxType sfxType, AudioClip audioClip)
 {
     _sfxType   = sfxType;
     _audioClip = audioClip;
 }
Example #24
0
 public void PlaySE(SfxType audio, float delay = 0.0f)
 {
     PlaySE(audio.ToString(), delay);
 }
Example #25
0
        public void StartSound(Mobj mobj, Sfx sfx, SfxType type, int volume)
        {
            if (buffers[(int)sfx] == null)
            {
                return;
            }

            var x    = (mobj.X - listener.X).ToFloat();
            var y    = (mobj.Y - listener.Y).ToFloat();
            var dist = MathF.Sqrt(x * x + y * y);

            float priority;

            if (type == SfxType.Diffuse)
            {
                priority = volume;
            }
            else
            {
                priority = amplitudes[(int)sfx] * GetDistanceDecay(dist) * volume;
            }

            if (priority < 0.001F)
            {
                return;
            }

            for (var i = 0; i < infos.Length; i++)
            {
                var info = infos[i];
                if (info.Source == mobj && info.Type == type)
                {
                    info.Reserved = sfx;
                    info.Priority = priority;
                    info.Volume   = volume;
                    return;
                }
            }

            for (var i = 0; i < infos.Length; i++)
            {
                var info = infos[i];
                if (info.Reserved == Sfx.NONE && info.Playing == Sfx.NONE)
                {
                    info.Reserved = sfx;
                    info.Priority = priority;
                    info.Source   = mobj;
                    info.Type     = type;
                    info.Volume   = volume;
                    return;
                }
            }

            var minPriority = float.MaxValue;
            var minChannel  = -1;

            for (var i = 0; i < infos.Length; i++)
            {
                var info = infos[i];
                if (info.Priority < minPriority)
                {
                    minPriority = info.Priority;
                    minChannel  = i;
                }
            }
            if (priority >= minPriority)
            {
                var info = infos[minChannel];
                info.Reserved = sfx;
                info.Priority = priority;
                info.Source   = mobj;
                info.Type     = type;
                info.Volume   = volume;
            }
        }
Example #26
0
 public static void PlaySFX(SfxType type)
 {
     sfxSource.PlayOneShot(sfxClipDic[type]);
 }
Example #27
0
 public void StartSound(Mobj mobj, Sfx sfx, SfxType type, int volume)
 {
     options.Sound.StartSound(mobj, sfx, type, volume);
 }
Example #28
0
 public void StartSound(Mobj mobj, Sfx sfx, SfxType type)
 {
     this.options.Sound.StartSound(mobj, sfx, type);
 }
 public static void PlaySfx(SfxType sfxType, AudioSource audiosSource)
 {
     _audioManagerInner.PlaySfxInner(sfxType, audiosSource);
 }