Created
January 23, 2024 04:13
-
-
Save Long18/351c5b7e0ab880fa9596515007cc4966 to your computer and use it in GitHub Desktop.
The BuildAddressablesEditorWindow class streamlines Unity Addressable Assets building in the Editor, providing a shortcut (Alt+ B) under "Tools." It automates asset cleanup, initiates the build, and logs success/errors, enhancing the efficiency of the Addressable Assets build process.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BuildAddressablesEditorWindow: EditorWindow | |
{ | |
[MenuItem("Tools/BuildAddressable &b")] | |
public static void BuildAndRun() | |
{ | |
var window = GetWindow<BuildAddressablesEditorWindow>(); | |
window.Close(); | |
} | |
private void OnEnable() | |
{ | |
Clean(); | |
if(!Build()) return; | |
Debug.Log($"<color=green>[BuildAddressable]</color> Build Completed"); | |
} | |
private void Clean() | |
{ | |
// Clean up player content using the active player data builder. | |
// This ensures that only necessary assets are included in the built player. | |
// AddressableAssetSettings.CleanPlayerContent(AddressableAssetSettingsDefaultObject.Settings.ActivePlayerDataBuilder); | |
// Clean up player content using default settings. | |
// This removes any unnecessary data or assets from the built player. | |
AddressableAssetSettings.CleanPlayerContent(); | |
} | |
private bool Build() | |
{ | |
AddressableAssetSettings.BuildPlayerContent(out AddressablesPlayerBuildResult result); | |
bool success = string.IsNullOrEmpty(result.Error); | |
if (success) return true; | |
Debug.Log($"<color=red>[BuildAddressable]</color> Build error: {result.Error}"); | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment