Exemplo n.º 1
0
        //--------------------------------------------------------------------------------------------

        ///<summary>
        ///(Sphere Audio) Instiante a sound, play it and then destroy it
        ///<param name="aSound">The AudioData, with all setting already set, that need to be play</param>
        ///<param name="aPosition">The position where the sound will be instantiate</param>
        ///</summary>
        public void SoundEasy_Play(AudioData aSound, Vector3 aPosition)
        {
            if (!SFX_IsInit(true))
            {
                return;
            }
            if (aSound == null)
            {
                Debug.LogWarning(Debug_Warning("There's no sound to play"));
                return;
            }
            SFX_AudioSetup audio = Instantiate(new GameObject(), aPosition, Quaternion.identity).AddComponent <SFX_AudioSetup>();

            audio.SetAudioSource();
            audio.SetupAudio(aSound.GetClip(), aSound.GetVolume(), aSound.GetPitch(), aSound.GetSpatialBlend(), aSound.GetStereoPan());
            audio.PlayAudio(aSound.GetDelay());
        }
Exemplo n.º 2
0
        //--------------------------------------------------------------------------------------------

        ///<summary>
        ///(Sphere Audio) Instiante a foot sound depend on which ground you are on, play it and then destroy it
        ///<param name="aPosition">The position where the sound will be instantiate</param>
        ///<param name="aGroundType">The type of ground you are moving on</param>
        ///<param name="aMovementType">The type of movement you are doing</param>
        ///<param name="aFootDir">The foot that will touch the ground and make sound</param>
        ///</summary>
        public void FootSound_Play(Vector3 aPosition, eAudioM_GroundType aGroundType, eAudioM_FootSoundType aMovementType, eAudioM_FootSoundDir aFootDir)
        {
            if (!FootSound_IsInit(true))
            {
                return;
            }

            AudioClip clip = null;

            switch (m_FootAudioSelector)
            {
            case eAudioM_AudioSelector.AudioClip:
            {
                clip = m_FootSoundsData.GetFootSound(aGroundType, aMovementType);
                break;
            }

            case eAudioM_AudioSelector.AudioData:
            {
                AudioData data = m_FootSoundsData.GetFootSoundData(aGroundType, aMovementType);
                if (data == null)
                {
                    Debug.LogWarning(Debug_Warning("There's no AudioData available for the ground '" + aGroundType + "' and the movement type '" + aMovementType + "'"));
                    return;
                }
                data.StereoPan = FootSound_GetStereoPan(aFootDir);
                SoundEasy_Play(data, aPosition);
                return;
            }
            }

            if (clip == null)
            {
                Debug.LogWarning(Debug_Warning("There's no sound to play"));
                return;
            }

            GameObject obj = new GameObject();

            obj.transform.position = aPosition;
            SFX_AudioSetup audio = obj.AddComponent <SFX_AudioSetup>();

            audio.SetupAudio(clip, m_FootSoundsData.GetFootSoundVolume(aGroundType, aMovementType), 1.0f, 1.0f, FootSound_GetStereoPan(aFootDir));
            audio.PlayAudio(0);
        }
Exemplo n.º 3
0
        //--------------------------------------------------------------------------------------------

        private SFX_AudioSetup GetPerfSound()
        {
            SFX_AudioSetup perfSound = null;

            if (m_PerfSFXsAvailable.Count == 0)
            {
                Debug.LogWarning(Debug_Warning("You use to many PerfSound at the same time, consider grow the limit"));
                perfSound = m_PerfSFXsInUse[0];
                m_PerfSFXsInUse.RemoveAt(0);
                m_PerfSFXsInUse.Add(perfSound);
            }
            else
            {
                perfSound = m_PerfSFXsAvailable[0];
                m_PerfSFXsInUse.Add(perfSound);
                m_PerfSFXsAvailable.RemoveAt(0);
            }

            return(perfSound);
        }
Exemplo n.º 4
0
        ///<summary>
        /// The Sound system let's you play a sound from anywhere in the game. You only need to have an AudioData and a position you want the sound to be played and
        /// the manager will do the rest for you. You have 2 options, 1. EasySound, it will play a sound no matter what, instantiate one and destroy it just after it get done;
        /// 2. PerfSound, it will pick a sound already instantiate (from the start of the game), will modify him to be as you wish, play it and then put it back into a list.
        /// This option is more performant, but you need to set the number of sound you want from the start and if you exceed the amount (play to many sound at the same time)
        /// the Manager will first warn you, but will need to stop the first sound played (actually) to be able to play the new one.
        ///</summary>
        #region SOUND Functions

        private void InitSFXSystem()
        {
            GameObject perfParent = Instantiate(new GameObject(), transform);

            perfParent.name  = "PerfSounds[" + m_MaxAmountPerfSFX + "]";
            m_ListPerfSounds = perfParent.transform;

            SFX_AudioSetup audioInCreation = null;

            for (int i = 0; i < m_MaxAmountPerfSFX; i++)
            {
                audioInCreation      = Instantiate(new GameObject(), Vector3.zero, Quaternion.identity).AddComponent <SFX_AudioSetup>();
                audioInCreation.name = "PerfSound_" + i.ToString();
                audioInCreation.SetAudioSource();
                audioInCreation.transform.SetParent(m_ListPerfSounds);
                m_PerfSFXsAvailable.Add(audioInCreation);
            }

            m_SFXIsInit = true;
            Debug.Log(Debug_InitSucces("SFX System as been init"));
        }
Exemplo n.º 5
0
        //--------------------------------------------------------------------------------------------

        ///<summary>
        ///(Sphere Audio) Pick a soundPrefab already instantiate from a list, play it and then put back in the list [PERFORMANCE++]
        ///<param name="aSound">The AudioData, with all setting already set, that need to be play</param>
        ///<param name="aPosition">The position where the sound will be instantiate</param>
        ///</summary>
        public void SoundPerf_Play(AudioData aSound, Vector3 aPosition)
        {
            if (!SFX_IsInit(true))
            {
                return;
            }
            if (aSound == null)
            {
                Debug.LogWarning(Debug_Warning("There's no sound to play"));
                return;
            }
            if (m_MaxAmountPerfSFX <= 0)
            {
                Debug.LogWarning(Debug_Warning("There's no perf sound available"));
                return;
            }
            SFX_AudioSetup audio = GetPerfSound();

            audio.transform.position = aPosition;
            audio.SetupAudio(aSound.GetClip(), aSound.GetVolume(), aSound.GetPitch(), aSound.GetSpatialBlend(), aSound.GetStereoPan());
            audio.PlayPerfAudio(aSound.GetDelay(), PutBackPerfSound);
        }
Exemplo n.º 6
0
 private void PutBackPerfSound(SFX_AudioSetup aSFX)
 {
     aSFX.transform.SetParent(m_ListPerfSounds);
     m_PerfSFXsInUse.Remove(aSFX);
     m_PerfSFXsAvailable.Add(aSFX);
 }