From ce64e99c010543e3414cccaffaa12a2006579ba5 Mon Sep 17 00:00:00 2001 From: Le Duc Anh Date: Wed, 20 May 2026 21:28:22 +0700 Subject: [PATCH] WIP: tool to process litmodel addressable --- .../Scripts/Utils/Editor/AddressableTools.cs | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/Assets/PerfectWorld/Scripts/Utils/Editor/AddressableTools.cs b/Assets/PerfectWorld/Scripts/Utils/Editor/AddressableTools.cs index 032b9837b0..dabcbee567 100644 --- a/Assets/PerfectWorld/Scripts/Utils/Editor/AddressableTools.cs +++ b/Assets/PerfectWorld/Scripts/Utils/Editor/AddressableTools.cs @@ -285,6 +285,117 @@ namespace BrewMonster Debug.Log(sb.ToString()); EditorUtility.DisplayDialog("Print Address and GUID", $"Printed {totalCount} addressable assets to Console.", "OK"); } + + + [MenuItem("Tools/Addressable/Set Addressable For Lit Mode In Folder")] + public static async void SetAddressableForLitModeInFolder() + { + Object selected = Selection.activeObject; + + if (selected == null) + { + Debug.LogError("Please select a folder."); + return; + } + + string folderPath = AssetDatabase.GetAssetPath(selected); + + if (!AssetDatabase.IsValidFolder(folderPath)) + { + Debug.LogError("Selected object is not a folder."); + return; + } + + // ========================= + // Config + // ========================= + + // Prefix path to remove from address + string prefixPath = "Assets/ModelRenderer/Art/Models/"; + + // Addressable group name + string groupName = "world"; + + // ========================= + // Addressable Settings + // ========================= + + AddressableAssetSettings settings = + AddressableAssetSettingsDefaultObject.Settings; + + if (settings == null) + { + Debug.LogError("Addressable Settings not found."); + return; + } + + AddressableAssetGroup group = settings.FindGroup(groupName); + + if (group == null) + { + Debug.LogError($"Addressable group not found: {groupName}"); + return; + } + + // ========================= + // Search prefabs + // ========================= + + string[] guids = AssetDatabase.FindAssets( + "t:Prefab litmodel_", + new[] { folderPath } + ); + + Debug.Log($"Found {guids.Length} prefabs"); + + int addedCount = 0; + foreach (string guid in guids) + { + string assetPath = AssetDatabase.GUIDToAssetPath(guid); + + // Remove prefix path + string address = assetPath; + + if (address.StartsWith(prefixPath)) + { + address = address.Substring(prefixPath.Length); + } + + // Remove .prefab extension + if (address.EndsWith(".prefab")) + { + address = address.Substring( + 0, + address.Length - ".prefab".Length + ); + } + + // Create or move entry into group + AddressableAssetEntry entry = settings.CreateOrMoveEntry(guid, group); + + // Set address + entry.address = address; + + addedCount++; + // show progress bar + EditorUtility.DisplayProgressBar("Set Addressable For Lit Mode In Folder", $"Processing {addedCount} prefabs", addedCount / guids.Length); + + Debug.Log( + $"Added Addressable\n" + + $"Path: {assetPath}\n" + + $"Address: {address}\n" + + $"Group: {groupName}" + ); + + await Task.Delay(1); + } + + EditorUtility.ClearProgressBar(); + + AssetDatabase.SaveAssets(); + + Debug.Log($"Finished. Added {addedCount} prefabs to Addressables."); + } } }