Example #1
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);
        }
Example #2
0
 /// <summary> Adds the SoundDatabase reference to this database. Returns TRUE if the operation was successful </summary>
 /// <param name="database"> SoundDatabase that will get added to the database </param>
 /// <param name="saveAssets"> Write all unsaved asset changes to disk? </param>
 public bool AddSoundDatabase(SoundDatabase database, bool saveAssets)
 {
     if (database == null)
     {
         return(false);
     }
     if (SoundDatabases == null)
     {
         SoundDatabases = new List <SoundDatabase>();
     }
     SoundDatabases.Add(database);
     UpdateDatabaseNames(false);
     SetDirty(saveAssets);
     return(true);
 }
Example #3
0
        /// <summary> Removes any null references and initializes all the referenced SoundDatabase found in the database </summary>
        public void InitializeSoundDatabases()
        {
            if (SoundDatabases == null)
            {
                return;
            }

            //remove any null sound database reference
            bool foundNullReference = false;

            for (int i = SoundDatabases.Count - 1; i >= 0; i--)
            {
                SoundDatabase soundDatabase = SoundDatabases[i];
                if (soundDatabase == null)
                {
                    SoundDatabases.RemoveAt(i);
                    foundNullReference = true;
                    continue;
                }

                soundDatabase.Initialize(false);
            }

            //after removing any null references the database is still empty -> initialize it and add the 'General' sound database
            if (SoundDatabases.Count == 0)
            {
                Initialize();
                return;
            }


            //database is not empty, but at least one null sound database reference was removed -> mark the database as dirty
            if (foundNullReference)
            {
                SetDirty(false);
            }
        }
Example #4
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);
        }
Example #5
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));
        }
Example #6
0
        /// <summary> Renames a SoundDatabase database name (including the asset filename). Returns TRUE if the operation was successful </summary>
        /// <param name="soundDatabase"> Target SoundDatabase </param>
        /// <param name="newDatabaseName"> The new database name for the target SoundDatabase </param>
        public bool RenameSoundDatabase(SoundDatabase soundDatabase, string newDatabaseName)
        {
            if (soundDatabase == null)
            {
                return(false);
            }

            newDatabaseName = newDatabaseName.Trim();

#if UNITY_EDITOR
            if (string.IsNullOrEmpty(newDatabaseName))
            {
                EditorUtility.DisplayDialog(UILabels.RenameSoundDatabase + " '" + soundDatabase.DatabaseName + "'",
                                            UILabels.EnterDatabaseName,
                                            UILabels.Ok);

                return(false);
            }

            if (Contains(newDatabaseName))
            {
                EditorUtility.DisplayDialog(UILabels.RenameSoundDatabase + " '" + soundDatabase.DatabaseName + "'",
                                            UILabels.NewSoundDatabase + ": '" + newDatabaseName + "" +
                                            "\n\n" +
                                            UILabels.AnotherEntryExists,
                                            UILabels.Ok);

                return(false);
            }

            soundDatabase.DatabaseName = newDatabaseName;
            AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(soundDatabase), "SoundDatabase_" + newDatabaseName.Replace(" ", string.Empty));
            UpdateDatabaseNames(true);
#endif
            return(true);
        }
Example #7
0
        /// <summary> Removes the given SoundDatabase reference from the database and also deletes its corresponding asset file. Returns TRUE if the operation was successful </summary>
        /// <param name="database"> SoundDatabase to delete </param>
        public bool DeleteDatabase(SoundDatabase database)
        {
            if (database == null)
            {
                return(false);
            }

#if UNITY_EDITOR
            if (!EditorUtility.DisplayDialog(UILabels.DeleteDatabase + " '" + database.DatabaseName + "'",
                                             UILabels.AreYouSureYouWantToDeleteDatabase +
                                             "\n\n" +
                                             UILabels.OperationCannotBeUndone,
                                             UILabels.Yes,
                                             UILabels.No))
            {
                return(false);
            }

            SoundDatabases.Remove(database);
            AssetDatabase.MoveAssetToTrash(AssetDatabase.GetAssetPath(database));
            UpdateDatabaseNames(true);
#endif
            return(true);
        }