using System.Collections.Generic; using System.Linq; using Sirenix.OdinInspector; using Sirenix.OdinInspector.Editor; using UnityEditor; using UnityEngine; namespace VOID.Editor.EditorWindow { public class ForceReserializeAssets : OdinEditorWindow { [MenuItem("VOID RPG/Assets/Force Reserialize Assets", priority = 1)] private static void OpenWindow() => GetWindow().Show(); [InfoBox( "WHY use this:\n" + "- Update all names of properties when changed by FormerlySerializedAs\n" + "\n" + "HOW use this:\n" + "- Add all files to update serialized data and press Reserialize\n" + "- OR! Just press Serialize Everything, but it will go through all files in project" )] [ShowInInspector, AssetsOnly] private List _files = new(); [Button(ButtonSizes.Gigantic)] public void Reserialize() { var paths = _files .Select(AssetDatabase.GetAssetPath) .SelectMany(file => AssetDatabase.IsValidFolder(file) ? GetAssetsPathsFromFolder(file) : new[] { file }) .Distinct() .ToList(); AssetDatabase.ForceReserializeAssets(paths); _files.Clear(); } [Button(Name = "Reserialize Everything")] [GUIColor(1, 0, 0)] public void ReserializeEverything() { if (EditorUtility.DisplayDialog( "Reserialize Everything", "Are you sure? It'll be very long process, around ~30 minutes!", "Yes, do it", "No")) { AssetDatabase.ForceReserializeAssets(); } } private string[] GetAssetsPathsFromFolder(string folderPath) { return AssetDatabase.FindAssets("", new[] { folderPath }).Select(AssetDatabase.GUIDToAssetPath).ToArray(); } } }