Exemple #1
0
        /// <summary>
        /// Checks that there are not null presets (animation data), that the preset category is matched to the directory structure and that the preset name is matched to the file name
        /// </summary>
        private static void ValidateLoopPresets()
        {
            bool          refresh     = false;
            List <string> directories = new List <string>();

            directories = RemoveEmptyPresetFolders(RELATIVE_PATH_LOOP_DATA, GetLoopPresetsDirectories);
            if (!directories.Contains(DEFAULT_PRESET_CATEGORY) || !LoopPresetExists(DEFAULT_PRESET_CATEGORY, DEFAULT_PRESET_NAME)) //the default preset category does not exist in the database or the default preset name does not exist in the database-> create it
            {
                refresh = true;
                CreateLoopPreset(DEFAULT_PRESET_CATEGORY, DEFAULT_PRESET_NAME, new Loop());
            }
            for (int directoryIndex = 0; directoryIndex < directories.Count; directoryIndex++)
            {
                string[] fileNames = GetLoopPresetsNamesForCategory(directories[directoryIndex]);
                if (fileNames.Length == 0)
                {
                    continue;
                }                                        //empty folder
                for (int fileIndex = 0; fileIndex < fileNames.Length; fileIndex++)
                {
                    AnimData asset = GetResource <AnimData>(RESOURCES_PATH_LOOP_DATA + directories[directoryIndex] + "/", fileNames[fileIndex]);
                    if (asset == null)
                    {
                        continue;
                    }
                    if (asset.data == null) //preset data is null (this is the animation data) -> this should not happen -> delete the preset to avoid corruption
                    {
                        refresh = true;
                        if (AssetDatabase.MoveAssetToTrash(RELATIVE_PATH_LOOP_DATA + directories[directoryIndex] + "/" + fileNames[fileIndex] + ".asset")) //move asset file to trash
                        {
                            AssetDatabase.SaveAssets();
                            AssetDatabase.Refresh();
                        }
                    }
                    if (string.IsNullOrEmpty(asset.presetName) || !asset.presetName.Equals(fileNames[fileIndex])) //preset name is empty or preset name does not match the file name -> set the preset name as the file name
                    {
                        refresh          = true;
                        asset.presetName = fileNames[fileIndex];
                        AssetDatabase.SaveAssets();
                    }
                    if (string.IsNullOrEmpty(asset.presetCategory) || !asset.presetCategory.Equals(directories[directoryIndex])) //preset category is empty or preset category does not match the directory name-> set the preset category as the directory name
                    {
                        refresh = true;
                        asset.presetCategory = directories[directoryIndex];
                        AssetDatabase.SaveAssets();
                    }
                }
            }
            if (refresh)
            {
                RefreshLoopDataPresetsDatabase();
            }
        }
Exemple #2
0
 private static AnimData CreateAnimDataAsset(string relativePath, string presetCategory, string presetName, Anim anim)
 {
     AnimData asset = ScriptableObject.CreateInstance<AnimData>();
     asset.presetName = presetName;
     asset.presetCategory = presetCategory;
     asset.data = anim;
     if (!QuickEngine.IO.File.Exists(relativePath + presetCategory + "/"))
     {
         QuickEngine.IO.File.CreateDirectory(relativePath + presetCategory + "/");
     }
     AssetDatabase.CreateAsset(asset, relativePath + presetCategory + "/" + presetName + ".asset");
     EditorUtility.SetDirty(asset);
     AssetDatabase.SaveAssets();
     AssetDatabase.Refresh();
     return asset;
 }