Skip to content

Commit

Permalink
Merge tag '1.21.17'
Browse files Browse the repository at this point in the history
The Addressable Asset System allows the developer to ask for an asset via its address. Once an asset (e.g. a prefab) is marked "addressable", it generates an address which can be called from anywhere. Wherever the asset resides (local or remote), the system will locate it and its dependencies, then return it.

Use 'Window->Asset Management->Addressables' to begin working with the system.

Addressables use asynchronous loading to support loading from any location with any collection of dependencies. Whether you have been using direct references, traditional asset bundles, or Resource folders, addressables provide a simpler way to make your game more dynamic. Addressables simultaneously opens up the world of asset bundles while managing all the complexity.

For usage samples, see github.com/Unity-Technologies/Addressables-Sample
  • Loading branch information
juniordiscart committed Nov 12, 2023
2 parents c9efaa9 + 0f70e02 commit dec972b
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 35 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ All notable changes to this package will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.21.17] - 2023-08-16
- Fixed issue where sprite is missing normal texture when using "Use Existing Build" build mode
- Fixed a bug where a GUI style was misspelled in the Editor and was recently fixed
- Fixed an issue where asset loading would occasionally stop working if domain reload was disabled

## [1.21.15] - 2023-08-03
- Fixed an issue where using binary catalogs causes a crash on Android with ARM7.
- DownloadDepedenciesAsync no longer loads asset bundles into memory
- Fixed a bug where a GUI style was misspelled in the Editor and was recently fixed
- Fixed an exception getting thrown in the Addressables Report when drilling into a bundle chain

## [1.21.14] - 2023-06-14
Expand Down
24 changes: 15 additions & 9 deletions Editor/GUI/AddressableAssetsSettingsGroupEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,21 @@ void TopToolbar(Rect toolbarPos)
{
m_SearchStyles = new List<GUIStyle>();

#if UNITY_2023_2_OR_NEWER
m_SearchStyles.Add(GetStyle("ToolbarSearchTextFieldPopup")); //GetStyle("ToolbarSearchTextField");
m_SearchStyles.Add(GetStyle("ToolbarSearchCancelButton"));
m_SearchStyles.Add(GetStyle("ToolbarSearchCancelButtonEmpty"));
#else
m_SearchStyles.Add(GetStyle("ToolbarSeachTextFieldPopup")); //GetStyle("ToolbarSearchTextField");
m_SearchStyles.Add(GetStyle("ToolbarSeachCancelButton"));
m_SearchStyles.Add(GetStyle("ToolbarSeachCancelButtonEmpty"));
#endif
string toolbarSearchTextField = "ToolbarSeachTextFieldPopup";
string toolbarSearchCancelButton = "ToolbarSeachCancelButton";
string toolbarSearchCancelButtonEmpty = "ToolbarSeachCancelButtonEmpty";

if(!AddressablesGUIUtility.HasStyle(toolbarSearchTextField))
{
toolbarSearchTextField = "ToolbarSearchTextFieldPopup";
toolbarSearchCancelButton = "ToolbarSearchCancelButton";
toolbarSearchCancelButtonEmpty = "ToolbarSearchCancelButtonEmpty";
}

m_SearchStyles.Add(GetStyle(toolbarSearchTextField)); //GetStyle("ToolbarSearchTextField");
m_SearchStyles.Add(GetStyle(toolbarSearchCancelButton));
m_SearchStyles.Add(GetStyle(toolbarSearchCancelButtonEmpty));

}

if (m_ButtonStyle == null)
Expand Down
26 changes: 16 additions & 10 deletions Editor/GUI/AddressableAssetsSettingsLabelMaskPopup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,20 @@ private void Set(Rect activatorRect, AddressableAssetSettings settings, List<Add
m_ActivatorRect = activatorRect;
m_SearchStyles = new List<GUIStyle>();

#if UNITY_2023_2_OR_NEWER
m_SearchStyles.Add(AddressablesGUIUtility.GetStyle("ToolbarSearchTextField")); //GetStyle("ToolbarSearchTextField");
m_SearchStyles.Add(AddressablesGUIUtility.GetStyle("ToolbarSearchCancelButton"));
m_SearchStyles.Add(AddressablesGUIUtility.GetStyle("ToolbarSearchCancelButtonEmpty"));
#else
m_SearchStyles.Add(AddressablesGUIUtility.GetStyle("ToolbarSeachTextField")); //GetStyle("ToolbarSearchTextField");
m_SearchStyles.Add(AddressablesGUIUtility.GetStyle("ToolbarSeachCancelButton"));
m_SearchStyles.Add(AddressablesGUIUtility.GetStyle("ToolbarSeachCancelButtonEmpty"));
#endif
string toolbarSearchTextField = "ToolbarSearchTextField";
string toolbarSearchCancelButton = "ToolbarSearchCancelButton";
string toolbarSearchCancelButtonEmpty = "ToolbarSearchCancelButtonEmpty";

if (!AddressablesGUIUtility.HasStyle(toolbarSearchTextField))
{
toolbarSearchTextField = "ToolbarSeachTextField";
toolbarSearchCancelButton = "ToolbarSeachCancelButton";
toolbarSearchCancelButtonEmpty = "ToolbarSeachCancelButtonEmpty";
}

m_SearchStyles.Add(AddressablesGUIUtility.GetStyle(toolbarSearchTextField)); //GetStyle("ToolbarSearchTextField");
m_SearchStyles.Add(AddressablesGUIUtility.GetStyle(toolbarSearchCancelButton));
m_SearchStyles.Add(AddressablesGUIUtility.GetStyle(toolbarSearchCancelButtonEmpty));

m_HintLabelStyle = new GUIStyle(UnityEngine.GUI.skin.label);
m_HintLabelStyle.fontSize = 10;
Expand Down Expand Up @@ -267,7 +272,8 @@ public override void OnGUI(Rect fullRect)
if (toggleRect.y < yPositionDrawRange.x || toggleRect.y > yPositionDrawRange.y)
continue;
}
else continue;
else
continue;

bool newState;
if (m_LabelCount == null)
Expand Down
11 changes: 11 additions & 0 deletions Editor/GUI/AddressablesGUIUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ internal static GUIStyle GetStyle(string styleName)
return s;
}

internal static bool HasStyle(string styleName)
{
GUIStyle s = UnityEngine.GUI.skin.FindStyle(styleName);
if (s == null)
s = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector).FindStyle(styleName);
if (s == null)
return false;

return true;
}

internal static string ConvertTextToStrikethrough(string value)
{
string str = "";
Expand Down
1 change: 1 addition & 0 deletions Runtime/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
#endif
[assembly: InternalsVisibleTo("Unity.Addressables.Tests")]
[assembly: InternalsVisibleTo("Unity.Addressables.Samples.Tests")]
[assembly: InternalsVisibleTo("Unity.Addressables.Android")]
1 change: 1 addition & 0 deletions Runtime/ResourceManager/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[assembly: InternalsVisibleTo("Unity.Addressables.Editor.Tests")]
[assembly: InternalsVisibleTo("Unity.Addressables.Tests")]
[assembly: InternalsVisibleTo("Unity.Addressables")]
[assembly: InternalsVisibleTo("Unity.Addressables.Android")]
#if UNITY_EDITOR
[assembly: InternalsVisibleTo("Unity.Addressables.Editor")]
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static void AddCatalog(Hash128 buildHash)
CatalogLoadCounter.Value++;
}

public static void AddBundleOperation(ProvideHandle handle, [NotNull] AssetBundleRequestOptions requestOptions, ContentStatus status, BundleSource source)
public static void AddBundleOperation(ProvideHandle handle, AssetBundleRequestOptions requestOptions, ContentStatus status, BundleSource source)
{
IAsyncOperation op = handle.InternalOp as IAsyncOperation;
if (op == null)
Expand Down Expand Up @@ -125,7 +125,7 @@ public static void AddAssetOperation(ProvideHandle handle, ContentStatus status)
string containingBundleName = GetContainingBundleNameForLocation(handle.Location);

string assetId;
if (handle.Location.InternalId.EndsWith(']'))
if (handle.Location.InternalId.EndsWith("]"))
{
int start = handle.Location.InternalId.IndexOf('[');
assetId = handle.Location.InternalId.Remove(start);
Expand Down
14 changes: 8 additions & 6 deletions Runtime/ResourceManager/ResourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ internal int InstanceOperationCount
HashSet<InstanceOperation> m_TrackedInstanceOperations = new HashSet<InstanceOperation>();
internal DelegateList<float> m_UpdateCallbacks = DelegateList<float>.CreateWithGlobalCache();
List<IAsyncOperation> m_DeferredCompleteCallbacks = new List<IAsyncOperation>();
HashSet<IResourceProvider> m_AsestBundleProviders = new HashSet<IResourceProvider>();
HashSet<IResourceProvider> m_AssetBundleProviders = new HashSet<IResourceProvider>();

bool m_InsideExecuteDeferredCallbacksMethod = false;
List<DeferredCallbackRegisterRequest> m_DeferredCallbacksToRegister = null;
Expand Down Expand Up @@ -507,19 +507,21 @@ internal IOperationCacheKey CreateCacheKeyForLocation(IResourceProvider provider
bool isAssetBundleProvider = false;
if (provider != null)
{
if (m_AsestBundleProviders.Contains(provider))
if (m_AssetBundleProviders.Contains(provider))
isAssetBundleProvider = true;
else if (typeof(AssetBundleProvider).IsAssignableFrom(provider.GetType()))
{
isAssetBundleProvider = true;
m_AsestBundleProviders.Add(provider);
m_AssetBundleProviders.Add(provider);
}
}

//If the location uses the AssetBundleProvider, we need to transform the ID first
//so we don't try and load the same bundle twice if the user is manipulating the path at runtime.
//Actual key generation has been moved to AssetBundleProvider virtual method to allow provider derived from AssetBundleProvider
//skip calling TransformInternalId method, as it may return different values before and after asset bundle is loaded,
//for example when using Play Asset Delivery for Android.
//For major package release consider this method to be made a part of IResourceProvider to simplify this whole logic.
if (isAssetBundleProvider)
key = new IdCacheKey(TransformInternalId(location));
key = (provider as AssetBundleProvider).CreateCacheKeyForLocation(this, location, desiredType);
else
key = new LocationCacheKey(location, desiredType);

Expand Down
16 changes: 15 additions & 1 deletion Runtime/ResourceManager/ResourceProviders/AssetBundleProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,14 @@ public void Unload()
public class AssetBundleProvider : ResourceProviderBase
{
#if UNLOAD_BUNDLE_ASYNC
private static Dictionary<string, AssetBundleUnloadOperation> m_UnloadingBundles = new Dictionary<string, AssetBundleUnloadOperation>();
internal static Dictionary<string, AssetBundleUnloadOperation> m_UnloadingBundles = new Dictionary<string, AssetBundleUnloadOperation>();

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
private static void Init()
{
m_UnloadingBundles = new Dictionary<string, AssetBundleUnloadOperation>();
}

/// <summary>
/// Stores async operations that unload the requested AssetBundles.
/// </summary>
Expand Down Expand Up @@ -936,5 +943,12 @@ public override void Release(IResourceLocation location, object asset)
return;
}
}

internal virtual IOperationCacheKey CreateCacheKeyForLocation(ResourceManager rm, IResourceLocation location, Type desiredType)
{
//We need to transform the ID first
//so we don't try and load the same bundle twice if the user is manipulating the path at runtime.
return new IdCacheKey(rm.TransformInternalId(location));
}
}
}
19 changes: 18 additions & 1 deletion Tests/Editor/DomainReloadTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.ResourceProviders;
using UnityEngine.TestTools;

namespace UnityEditor.AddressableAssets.Tests
Expand All @@ -20,7 +22,7 @@ public IEnumerator RuntimeSetup()
savedOptions = EditorSettings.enterPlayModeOptions;
EditorSettings.enterPlayModeOptions = EnterPlayModeOptions.DisableDomainReload;
Addressables.reinitializeAddressables = true;

AssetBundleProvider.m_UnloadingBundles.Add("test", new AssetBundleUnloadOperation());
Assert.False(Application.isPlaying);
yield return new EnterPlayMode(false);

Expand All @@ -32,12 +34,27 @@ public IEnumerator RuntimeTearDown()
yield return new ExitPlayMode();
EditorSettings.enterPlayModeOptionsEnabled = savedState;
EditorSettings.enterPlayModeOptions = savedOptions;

if (AssetBundleProvider.m_UnloadingBundles.Count != 0)
{
AssetBundleProvider.m_UnloadingBundles = new Dictionary<string, AssetBundleUnloadOperation>();
}
#if !UNITY_EDITOR
Assert.IsTrue(Addressables.reinitializeAddressables);
#endif
Assert.False(Application.isPlaying);
}

[Test]
public void DomainReloadTests_EnteringPlaymode_ClearsUnloadingBundles()
{
#if UNITY_2022_1_OR_NEWER
Assert.AreEqual(AssetBundleProvider.m_UnloadingBundles.Count, 0, "m_UnloadingBundles not cleared correctly on enter playmode");
#else
Assert.Ignore("UNLOAD_BUNDLE_ASYNC scripting define is not set, test will be ignored.");
#endif
}

[Test]
public void DomainReloadTests_ReInitAddressablesFlagIsSetCorrectly_WhenExitingPlaymode()
{
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.unity.addressables",
"displayName": "Addressables",
"version": "1.21.15",
"version": "1.21.17",
"unity": "2019.4",
"description": "The Addressable Asset System allows the developer to ask for an asset via its address. Once an asset (e.g. a prefab) is marked \"addressable\", it generates an address which can be called from anywhere. Wherever the asset resides (local or remote), the system will locate it and its dependencies, then return it.\n\nUse 'Window->Asset Management->Addressables' to begin working with the system.\n\nAddressables use asynchronous loading to support loading from any location with any collection of dependencies. Whether you have been using direct references, traditional asset bundles, or Resource folders, addressables provide a simpler way to make your game more dynamic. Addressables simultaneously opens up the world of asset bundles while managing all the complexity.\n\nFor usage samples, see github.com/Unity-Technologies/Addressables-Sample",
"keywords": [
Expand All @@ -12,24 +12,24 @@
"assetbundles"
],
"dependencies": {
"com.unity.scriptablebuildpipeline": "1.21.8",
"com.unity.scriptablebuildpipeline": "1.21.9",
"com.unity.modules.assetbundle": "1.0.0",
"com.unity.modules.imageconversion": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0",
"com.unity.modules.unitywebrequest": "1.0.0",
"com.unity.modules.unitywebrequestassetbundle": "1.0.0"
},
"_upm": {
"changelog": "- Fixed an issue where using binary catalogs causes a crash on Android with ARM7.\n- DownloadDepedenciesAsync no longer loads asset bundles into memory\n- Fixed a bug where a GUI style was misspelled in the Editor and was recently fixed\n- Fixed an exception getting thrown in the Addressables Report when drilling into a bundle chain"
"changelog": "- Fixed issue where sprite is missing normal texture when using \"Use Existing Build\" build mode\n- Fixed a bug where a GUI style was misspelled in the Editor and was recently fixed\n- Fixed an issue where asset loading would occasionally stop working if domain reload was disabled"
},
"upmCi": {
"footprint": "a496399c62cdf3d27472d69157ce7da743931d28"
"footprint": "4dc1715b88796c91001041527ff35409734bc7b2"
},
"documentationUrl": "https://docs.unity3d.com/Packages/com.unity.addressables@1.21/manual/index.html",
"repository": {
"url": "https://github.cds.internal.unity3d.com/unity/Addressables.git",
"type": "git",
"revision": "b6e4f321768265894baab72ca85cb8b8877ffbd4"
"revision": "e66f4cab999f27fcbd7c08e8a6e7734a3a987875"
},
"samples": [
{
Expand Down

0 comments on commit dec972b

Please sign in to comment.