Esempio n. 1
0
        public static void RefreshUISoundsDatabase()
        {
            EditorUtility.DisplayProgressBar("Refreshing UISounds Database", "", 0f);
            if (UISoundsDatabase == null)
            {
                UISoundsDatabase = new List <UISound>();
            }
            UISoundsDatabase.Clear();
            fileNames = null;
            fileNames = GetUISoundsFileNames;
            int fileNamesLength = fileNames != null ? fileNames.Length : 0;

            for (int fileIndex = 0; fileIndex < fileNamesLength; fileIndex++)
            {
                UISound asset = GetResource <UISound>(RESOURCES_PATH_UISOUNDS, fileNames[fileIndex]);
                if (asset == null)
                {
                    continue;
                }
                EditorUtility.DisplayProgressBar("Refreshing UISounds Database", fileNames[fileIndex], ((fileIndex + 1) / (fileNamesLength + 2)));
                UISoundsDatabase.Add(asset);
            }
            EditorUtility.DisplayProgressBar("Refreshing UISounds Database", "Creating Sound Names List...", 0.9f);
            RefreshUISoundNames();
            EditorUtility.DisplayProgressBar("Refreshing UISounds Database", "Validating...", 1f);
            ValidateUISoundsDatabase();
            EditorUtility.ClearProgressBar();
        }
Esempio n. 2
0
        public static void CreateUISound(string soundName, SoundType soundType, AudioClip audioClip = null)
        {
            if (string.IsNullOrEmpty(soundName))
            {
                return;
            }
            if (UISoundNameExists(soundName, soundType))
            {
                return;
            }
            if (UISoundNameExists(soundName, SoundType.All))
            {
                UpdateUISoundSoundType(soundName, SoundType.All);
                return;
            }
            UISound newUISound = CreateAsset <UISound>(RELATIVE_PATH_UISOUNDS, soundName);

            newUISound.soundType = soundType;
            newUISound.soundName = soundName;
            newUISound.audioClip = audioClip;
            EditorUtility.SetDirty(newUISound);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
            RefreshUISoundsDatabase();
        }
Esempio n. 3
0
        /// <summary>
        /// Retrurns true if the soundName was found or was added to the database
        /// </summary>
        /// <param name="soundName"></param>
        /// <returns></returns>
        private bool AddSoundToDatabase(string soundName)
        {
            InitSoundsDatabase();
            if (soundsDatabase.ContainsKey(soundName))
            {
                return(true);
            }
            UISound soundItem = DUI.GetUISound(soundName);

            if (soundItem == null)
            {
                Debug.Log("NULL UISound"); return(false);
            }                                                                   //the UISound was not found in the Resources folder -> thus it could not be added
            soundsDatabase.Add(soundName, soundItem);
            return(true);
        }
Esempio n. 4
0
        private static void ValidateUISoundsDatabase()
        {
            bool refreshDatabase = false;

            string[] fileNames = GetUISoundsFileNames;
            for (int fileIndex = 0; fileIndex < fileNames.Length; fileIndex++)
            {
                UISound asset = GetResource <UISound>(RESOURCES_PATH_UISOUNDS, fileNames[fileIndex]);
                if (asset == null)
                {
                    continue;
                }
                if (string.IsNullOrEmpty(asset.soundName)) //the UISound .asset file does not have a soundName -> deletion is in order
                {
                    refreshDatabase = true;
                    if (AssetDatabase.MoveAssetToTrash(RELATIVE_PATH_UISOUNDS + fileNames[fileIndex] + ".asset")) //move asset file to trash
                    {
                        AssetDatabase.SaveAssets();
                    }
                    continue;
                }
                if (!fileNames[fileIndex].Equals(asset.soundName)) //the .asset fileName does not match the soundName
                {
                    refreshDatabase = true;
                    if (GetResource <UISound>(RESOURCES_PATH_UISOUNDS, asset.soundName) != null)                      //there is an .asset fileName that is the same with the soundName
                    {
                        if (AssetDatabase.MoveAssetToTrash(RELATIVE_PATH_UISOUNDS + fileNames[fileIndex] + ".asset")) //move asset file to trash (just in case)
                        {
                            Debug.Log("[DoozyUI] UISoundsDatabase automated validation system - The " + fileNames[fileIndex] + ".asset file has been moved to trash. This happened because there is another UISound asset file that has the '" + asset.soundName + "' soundName. The system does not allow for duplicate soundNames in the database, thus it executed this fail safe operation.");
                            AssetDatabase.SaveAssets();
                        }
                        continue;
                    }
                    CreateUISound(asset.soundName, asset.soundType, asset.audioClip);
                    if (AssetDatabase.MoveAssetToTrash(RELATIVE_PATH_UISOUNDS + fileNames[fileIndex] + ".asset")) //move asset file to trash to avoid duplicates
                    {
                        AssetDatabase.SaveAssets();
                    }
                }
            }
            if (refreshDatabase)
            {
                RefreshUISoundsDatabase();
            }
        }