|
1 | 1 | using UnityEditor; |
| 2 | +using UnityEngine; |
2 | 3 |
|
3 | 4 | namespace LDtkUnity.Editor |
4 | 5 | { |
5 | 6 | internal static class ReserializeAssets |
6 | 7 | { |
7 | | - [MenuItem("LDtkUnity/Reserialize Assets", false, 10)] |
| 8 | + [MenuItem("LDtkUnity/Reserialize/All", false, 10)] |
8 | 9 | private static void ForceReserializeAssets() |
9 | 10 | { |
10 | 11 | AssetDatabase.ForceReserializeAssets(); |
11 | 12 | } |
| 13 | + [MenuItem("LDtkUnity/Reserialize/LDtkUnity", false, 10)] |
| 14 | + private static void ForceReserializeLDtkAssets() |
| 15 | + { |
| 16 | + ForceReserializeFolder("Assets/LDtkUnity"); |
| 17 | + } |
| 18 | + [MenuItem("LDtkUnity/Reserialize/Samples", false, 10)] |
| 19 | + private static void ForceReserializeSamples() |
| 20 | + { |
| 21 | + ForceReserializeFolder("Assets/Samples"); |
| 22 | + } |
| 23 | + |
| 24 | + private static void ForceReserializeFolder(string folderPath) |
| 25 | + { |
| 26 | + if (string.IsNullOrEmpty(folderPath)) |
| 27 | + { |
| 28 | + Debug.LogError("Folder path cannot be null or empty."); |
| 29 | + return; |
| 30 | + } |
| 31 | + |
| 32 | + // 1. Get all asset GUIDs in the folder and its subfolders |
| 33 | + string[] guids = AssetDatabase.FindAssets("", new[] { folderPath }); |
| 34 | + string[] paths = new string[guids.Length]; |
| 35 | + |
| 36 | + // 2. Convert GUIDs to individual file paths |
| 37 | + for (int i = 0; i < guids.Length; i++) |
| 38 | + { |
| 39 | + paths[i] = AssetDatabase.GUIDToAssetPath(guids[i]); |
| 40 | + } |
| 41 | + |
| 42 | + // 3. Force reserialize the asset paths |
| 43 | + AssetDatabase.ForceReserializeAssets(paths); |
| 44 | + |
| 45 | + Debug.Log($"Force-reserialized {paths.Length} assets in '{folderPath}'."); |
| 46 | + } |
12 | 47 | } |
13 | 48 | } |
0 commit comments