/// <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); }
/// <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); } }
/// <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); }