WIP: tool to process litmodel addressable
This commit is contained in:
@@ -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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user