Ejemplo n.º 1
0
        /// <summary>
        /// Play a sound according to the settings in the SoundyData reference.
        /// Returns a reference to the SoundyController that is playing the sound if data.SoundSource is set to either Soundy or AudioClip.
        /// If data is null or data.SoundSource is set to MasterAudio, it will always return null because MasterAudio is the one playing the sound and not a SoundyController </summary>
        /// <param name="data"> Sound settings </param>
        public static SoundyController Play(SoundyData data)
        {
            if (data == null)
            {
                return(null);
            }
            if (!s_initialized)
            {
                s_instance = Instance;
            }
            switch (data.SoundSource)
            {
            case SoundSource.Soundy:
                return(Play(data.DatabaseName, data.SoundName));

            case SoundSource.AudioClip:
                return(Play(data.AudioClip, data.OutputAudioMixerGroup));

            case SoundSource.MasterAudio:
                if (Instance.DebugComponent)
                {
                    DDebug.Log("Play '" + data.SoundName + "' with MasterAudio", Instance);
                }
#if dUI_MasterAudio
                DarkTonic.MasterAudio.MasterAudio.PlaySound(data.SoundName);
                //DDebug.Log("MasterAudio - Play Sound: " + data.SoundName);
#endif
                break;
            }

            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Play the specified sound and follow a given target Transform while playing.
        /// Returns a reference to the SoundyController that is playing the sound.
        /// Returns null if no sound is found.
        /// </summary>
        /// <param name="databaseName"> The sound category </param>
        /// <param name="soundName"> Sound Name of the sound </param>
        /// <param name="followTarget"> The target transform that the sound will follow while playing </param>
        public static SoundyController Play(string databaseName, string soundName, Transform followTarget)
        {
            if (!s_initialized)
            {
                s_instance = Instance;
            }
            if (Database == null)
            {
                return(null);
            }
            if (soundName.Equals(NO_SOUND))
            {
                return(null);
            }
            SoundGroupData soundGroupData = Database.GetAudioData(databaseName, soundName);

            if (soundGroupData == null)
            {
                return(null);
            }
            if (Instance.DebugComponent)
            {
                DDebug.Log("Play '" + databaseName + "' / '" + soundName + "' SoundGroupData and follow the '" + followTarget.name + "' GameObject", Instance);
            }
            return(soundGroupData.Play(followTarget, Database.GetSoundDatabase(databaseName).OutputAudioMixerGroup));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Play the specified audio clip with the given parameters (and follow a given Transform while playing).
        /// Returns a reference to the SoundyController that is playing the sound.
        /// Returns null if the AudioClip is null.
        /// </summary>
        /// <param name="audioClip"> The AudioClip to play </param>
        /// <param name="outputAudioMixerGroup"> The output audio mixer group that this sound will get routed through </param>
        /// <param name="followTarget"> The target transform that the sound will follow while playing </param>
        /// <param name="volume"> The volume of the audio source (0.0 to 1.0) </param>
        /// <param name="pitch"> The pitch of the audio source </param>
        /// <param name="loop"> Is the audio clip looping? </param>
        /// <param name="spatialBlend">
        ///     Sets how much this AudioSource is affected by 3D space calculations (attenuation,
        ///     doppler etc). 0.0 makes the sound full 2D, 1.0 makes it full 3D
        /// </param>
        public static SoundyController Play(AudioClip audioClip, AudioMixerGroup outputAudioMixerGroup,
                                            Transform followTarget = null, float volume = 1, float pitch = 1, bool loop = false,
                                            float spatialBlend     = 1)
        {
            if (!s_initialized)
            {
                s_instance = Instance;
            }
            if (audioClip == null)
            {
                return(null);
            }
            SoundyController controller = SoundyPooler.GetControllerFromPool();

            controller.SetSourceProperties(audioClip, volume, pitch, loop, spatialBlend);
            controller.SetOutputAudioMixerGroup(outputAudioMixerGroup);
            if (followTarget == null)
            {
                spatialBlend = 0;
                controller.SetFollowTarget(Pooler.transform);
            }
            else
            {
                controller.SetFollowTarget(followTarget);
            }

            controller.gameObject.name = "[AudioClip]-(" + audioClip.name + ")";
            controller.Play();
            if (Instance.DebugComponent)
            {
                DDebug.Log("Play '" + audioClip.name + "' AudioClip", Instance);
            }
            return(controller);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Play the specified sound at the given position.
        /// Returns a reference to the SoundyController that is playing the sound.
        /// Returns null if no sound is found.
        /// </summary>
        /// <param name="databaseName"> The sound category </param>
        /// <param name="soundName"> Sound Name of the sound </param>
        /// <param name="position"> The position from where this sound will play from </param>
        public static SoundyController Play(string databaseName, string soundName, Vector3 position)
        {
            if (!s_initialized)
            {
                s_instance = Instance;
            }
            if (Database == null)
            {
                return(null);
            }
            if (soundName.Equals(NO_SOUND))
            {
                return(null);
            }
            SoundGroupData soundGroupData = Database.GetAudioData(databaseName, soundName);

            if (soundGroupData == null)
            {
                return(null);
            }
            if (Instance.DebugComponent)
            {
                DDebug.Log("Play '" + databaseName + "' / '" + soundName + "' SoundGroupData at " + position + " position", Instance);
            }
            return(soundGroupData.Play(position, Database.GetSoundDatabase(databaseName).OutputAudioMixerGroup));
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Play the passed AudioClip.
 /// Returns a reference to the SoundyController that is playing the sound.
 /// Returns null if the AudioClip is null.
 /// </summary>
 /// <param name="audioClip"> The AudioClip to play </param>
 public static SoundyController Play(AudioClip audioClip)
 {
     if (!s_initialized)
     {
         s_instance = Instance;
     }
     return(Play(audioClip, null, Pooler.transform));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Play the specified sound, at the set position.
 /// Returns a reference to the SoundyController that is playing the sound.
 /// Returns null if the AudioClip is null.
 /// </summary>
 /// <param name="audioClip"> The AudioClip to play </param>
 /// <param name="followTarget"> The target transform that the sound will follow while playing </param>
 public static SoundyController Play(AudioClip audioClip, Transform followTarget)
 {
     if (!s_initialized)
     {
         s_instance = Instance;
     }
     return(Play(audioClip, null, followTarget));
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Play the specified sound, at the given position.
 /// Returns a reference to the SoundyController that is playing the sound.
 /// Returns null if the AudioClip is null.
 /// </summary>
 /// <param name="audioClip"> The AudioClip to play </param>
 /// <param name="position"> The position from where this sound will play from </param>
 public static SoundyController Play(AudioClip audioClip, Vector3 position)
 {
     if (!s_initialized)
     {
         s_instance = Instance;
     }
     return(Play(audioClip, null, position));
 }
Ejemplo n.º 8
0
 /// <summary> Initializes the SoundyManager Instance </summary>
 public static void Init()
 {
     if (s_initialized || s_instance != null)
     {
         return;
     }
     s_instance = Instance;
     for (int i = 0; i < SoundyPooler.MinimumNumberOfControllers + 1; i++)
     {
         SoundyPooler.GetControllerFromPool().Stop();
     }
 }
        /// <summary>
        /// Play the specified audio clip with the given parameters, at the set position.
        /// Returns a reference to the SoundyController that is playing the sound.
        /// Returns null if the AudioClip is null.
        /// </summary>
        /// <param name="audioClip"> The AudioClip to play </param>
        /// <param name="outputAudioMixerGroup"> The output audio mixer group that this sound will get routed through </param>
        /// <param name="position"> The position from where this sound will play from </param>
        /// <param name="volume"> The volume of the audio source (0.0 to 1.0) </param>
        /// <param name="pitch"> The pitch of the audio source </param>
        /// <param name="loop"> Is the audio clip looping? </param>
        /// <param name="spatialBlend">
        ///     Sets how much this AudioSource is affected by 3D space calculations (attenuation,
        ///     doppler etc). 0.0 makes the sound full 2D, 1.0 makes it full 3D
        /// </param>
        public static SoundyController Play(AudioClip audioClip, AudioMixerGroup outputAudioMixerGroup, Vector3 position,
                                            float volume = 1, float pitch = 1, bool loop = false, float spatialBlend = 0)
        {
            if (!s_initialized)
            {
                s_instance = Instance;
            }
            if (audioClip == null)
            {
                return(null);
            }
            SoundyController controller = SoundyPooler.GetControllerFromPool();

            controller.SetSourceProperties(audioClip, volume, pitch, loop, spatialBlend);
            controller.SetOutputAudioMixerGroup(outputAudioMixerGroup);
            controller.SetPosition(position);
            controller.Play();
            if (Instance.DebugComponent)
            {
                DDebug.Log("Play '" + audioClip.name + "' AudioClip", Instance);
            }
            return(controller);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Play the specified sound with the given category, name and type.
        /// Returns a reference to the SoundyController that is playing the sound.
        /// Returns null if no sound is found.
        /// </summary>
        /// <param name="databaseName"> The sound category </param>
        /// <param name="soundName"> Sound Name of the sound </param>
        public static SoundyController Play(string databaseName, string soundName)
        {
            if (!s_initialized)
            {
                s_instance = Instance;
            }
            if (Database == null)
            {
                return(null);
            }
            if (soundName.Equals(NO_SOUND))
            {
                return(null);
            }
            if (string.IsNullOrEmpty(databaseName) || string.IsNullOrEmpty(databaseName.Trim()))
            {
                return(null);
            }
            if (string.IsNullOrEmpty(soundName) || string.IsNullOrEmpty(soundName.Trim()))
            {
                return(null);
            }

            SoundDatabase soundDatabase = Database.GetSoundDatabase(databaseName);

            if (soundDatabase == null)
            {
                return(null);
            }
            SoundGroupData soundGroupData = soundDatabase.GetData(soundName);

            if (soundGroupData == null)
            {
                return(null);
            }
            return(soundGroupData.Play(Pooler.transform, soundDatabase.OutputAudioMixerGroup));
        }
Ejemplo n.º 11
0
        /// <summary> Adds the 'General' SoundDatabase if it does not exist and initializes it </summary>
        public void Initialize()
        {
            RemoveNullDatabases();

            if (Contains(SoundyManager.GENERAL))
            {
                return;
            }

#if UNITY_EDITOR
            SearchForUnregisteredDatabases(false);
            if (Contains(SoundyManager.GENERAL))
            {
                return;
            }

            SoundDatabase soundDatabase = AssetUtils.CreateAsset <SoundDatabase>(DoozyPath.GetDataPath(DoozyPath.ComponentName.Soundy), SoundyManager.GetSoundDatabaseFilename(SoundyManager.GENERAL));
#else
            SoundDatabase soundDatabase = ScriptableObject.CreateInstance <SoundDatabase>();
#endif
            AddSoundDatabase(soundDatabase, true);
            soundDatabase.DatabaseName = SoundyManager.GENERAL;
            soundDatabase.Initialize(true);
            UpdateDatabaseNames(true);
        }
Ejemplo n.º 12
0
        /// <summary> Creates a new SoundDatabase asset with the given database name and adds a reference to it to the database </summary>
        /// <param name="databaseName"> The name of the new SoundDatabase </param>
        /// <param name="showDialog"> Should a display dialog be shown before executing the action </param>
        /// <param name="saveAssets"> Write all unsaved asset changes to disk? </param>
        public bool CreateSoundDatabase(string databaseName, bool showDialog = false, bool saveAssets = false)
        {
            databaseName = databaseName.Trim();

            if (string.IsNullOrEmpty(databaseName))
            {
#if UNITY_EDITOR
                if (showDialog)
                {
                    EditorUtility.DisplayDialog(UILabels.NewSoundDatabase, UILabels.EnterDatabaseName, UILabels.Ok);
                }
#endif
                return(false);
            }

            if (Contains(databaseName))
            {
#if UNITY_EDITOR
                if (showDialog)
                {
                    EditorUtility.DisplayDialog(UILabels.NewSoundDatabase, UILabels.DatabaseAlreadyExists, UILabels.Ok);
                }
#endif
                return(false);
            }

#if UNITY_EDITOR
            SoundDatabase soundDatabase = AssetUtils.CreateAsset <SoundDatabase>(DoozyPath.GetDataPath(DoozyPath.ComponentName.Soundy), SoundyManager.GetSoundDatabaseFilename(databaseName.Replace(" ", string.Empty)));
#else
            SoundDatabase soundDatabase = ScriptableObject.CreateInstance <SoundDatabase>();
#endif
            soundDatabase.DatabaseName = databaseName;
            soundDatabase.Initialize(false);
            AddSoundDatabase(soundDatabase, false);
            SetDirty(saveAssets);
            return(true);
        }