initial commit
This commit is contained in:
parent
6715289efe
commit
788c3389af
37645 changed files with 2526849 additions and 80 deletions
|
@ -0,0 +1,29 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
#region doc_AddExceptionHandler
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
internal class AddExceptionHandler : MonoBehaviour
|
||||
{
|
||||
void Start()
|
||||
{
|
||||
ResourceManager.ExceptionHandler = CustomExceptionHandler;
|
||||
}
|
||||
|
||||
// Gets called for every error scenario encountered during an operation.
|
||||
// A common use case for this is having InvalidKeyExceptions fail silently when
|
||||
// a location is missing for a given key.
|
||||
void CustomExceptionHandler(AsyncOperationHandle handle, Exception exception)
|
||||
{
|
||||
if (exception.GetType() != typeof(InvalidKeyException))
|
||||
Addressables.LogException(handle, exception);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 97ad6dc3d3427a04082f57c44933e71c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,48 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
#region doc_asyncload
|
||||
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
internal class AsynchronousLoading : MonoBehaviour
|
||||
{
|
||||
private string address = "tree";
|
||||
private AsyncOperationHandle loadHandle;
|
||||
|
||||
// always minimum of 1 frame
|
||||
IEnumerator LoadAssetCoroutine()
|
||||
{
|
||||
loadHandle = Addressables.LoadAssetAsync<GameObject>(address);
|
||||
yield return loadHandle;
|
||||
}
|
||||
|
||||
// minimum of 1 frame for new asset loads
|
||||
// callback called in current frame for already loaded assets
|
||||
void LoadAssetCallback()
|
||||
{
|
||||
loadHandle = Addressables.LoadAssetAsync<GameObject>(address);
|
||||
loadHandle.Completed += h =>
|
||||
{
|
||||
// Loaded here
|
||||
};
|
||||
}
|
||||
|
||||
// minimum of 1 frame for new asset loads
|
||||
// await completes in current frame for already loaded assets
|
||||
async void LoadAssetWait()
|
||||
{
|
||||
loadHandle = Addressables.LoadAssetAsync<GameObject>(address);
|
||||
await loadHandle.Task;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
Addressables.Release(loadHandle);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4ac2fef2444fc40e1be92d0423a6587a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,65 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
#region doc_BatchBuild
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEditor.AddressableAssets;
|
||||
using UnityEditor.AddressableAssets.Build;
|
||||
using UnityEditor.AddressableAssets.Settings;
|
||||
using UnityEditor.Build.Reporting;
|
||||
using UnityEngine;
|
||||
|
||||
internal class BatchBuild
|
||||
{
|
||||
public static string build_script
|
||||
= "Assets/AddressableAssetsData/DataBuilders/BuildScriptPackedMode.asset";
|
||||
|
||||
public static string profile_name = "Default";
|
||||
|
||||
public static void ChangeSettings()
|
||||
{
|
||||
string defines = "";
|
||||
string[] args = Environment.GetCommandLineArgs();
|
||||
|
||||
foreach (var arg in args)
|
||||
if (arg.StartsWith("-defines=", System.StringComparison.CurrentCulture))
|
||||
defines = arg.Substring(("-defines=".Length));
|
||||
|
||||
var buildSettings = EditorUserBuildSettings.selectedBuildTargetGroup;
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(buildSettings, defines);
|
||||
}
|
||||
|
||||
public static void BuildContentAndPlayer()
|
||||
{
|
||||
AddressableAssetSettings settings
|
||||
= AddressableAssetSettingsDefaultObject.Settings;
|
||||
|
||||
settings.activeProfileId
|
||||
= settings.profileSettings.GetProfileId(profile_name);
|
||||
|
||||
IDataBuilder builder
|
||||
= AssetDatabase.LoadAssetAtPath<ScriptableObject>(build_script) as IDataBuilder;
|
||||
|
||||
settings.ActivePlayerDataBuilderIndex
|
||||
= settings.DataBuilders.IndexOf((ScriptableObject)builder);
|
||||
|
||||
AddressableAssetSettings.BuildPlayerContent(out AddressablesPlayerBuildResult result);
|
||||
|
||||
if (!string.IsNullOrEmpty(result.Error))
|
||||
throw new Exception(result.Error);
|
||||
|
||||
BuildReport buildReport
|
||||
= BuildPipeline.BuildPlayer(EditorBuildSettings.scenes,
|
||||
"d:/build/winApp.exe", EditorUserBuildSettings.activeBuildTarget,
|
||||
BuildOptions.None);
|
||||
|
||||
if (buildReport.summary.result != BuildResult.Succeeded)
|
||||
throw new Exception(buildReport.summary.ToString());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a51b3a53966dc984e9859a169333c8ac
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,128 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
using MenuItem = Dummy;
|
||||
|
||||
#region doc_BuildLauncher
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using UnityEditor.AddressableAssets.Build;
|
||||
using UnityEditor.AddressableAssets.Settings;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
internal class BuildLauncher
|
||||
{
|
||||
public static string build_script
|
||||
= "Assets/AddressableAssetsData/DataBuilders/BuildScriptPackedMode.asset";
|
||||
|
||||
public static string settings_asset
|
||||
= "Assets/AddressableAssetsData/AddressableAssetSettings.asset";
|
||||
|
||||
public static string profile_name = "Default";
|
||||
private static AddressableAssetSettings settings;
|
||||
|
||||
#region getSettingsObject
|
||||
|
||||
static void getSettingsObject(string settingsAsset)
|
||||
{
|
||||
// This step is optional, you can also use the default settings:
|
||||
//settings = AddressableAssetSettingsDefaultObject.Settings;
|
||||
|
||||
settings
|
||||
= AssetDatabase.LoadAssetAtPath<ScriptableObject>(settingsAsset)
|
||||
as AddressableAssetSettings;
|
||||
|
||||
if (settings == null)
|
||||
Debug.LogError($"{settingsAsset} couldn't be found or isn't " +
|
||||
$"a settings object.");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region setProfile
|
||||
|
||||
static void setProfile(string profile)
|
||||
{
|
||||
string profileId = settings.profileSettings.GetProfileId(profile);
|
||||
if (String.IsNullOrEmpty(profileId))
|
||||
Debug.LogWarning($"Couldn't find a profile named, {profile}, " +
|
||||
$"using current profile instead.");
|
||||
else
|
||||
settings.activeProfileId = profileId;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region setBuilder
|
||||
|
||||
static void setBuilder(IDataBuilder builder)
|
||||
{
|
||||
int index = settings.DataBuilders.IndexOf((ScriptableObject)builder);
|
||||
|
||||
if (index > 0)
|
||||
settings.ActivePlayerDataBuilderIndex = index;
|
||||
else
|
||||
Debug.LogWarning($"{builder} must be added to the " +
|
||||
$"DataBuilders list before it can be made " +
|
||||
$"active. Using last run builder instead.");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region buildAddressableContent
|
||||
|
||||
static bool buildAddressableContent()
|
||||
{
|
||||
AddressableAssetSettings
|
||||
.BuildPlayerContent(out AddressablesPlayerBuildResult result);
|
||||
bool success = string.IsNullOrEmpty(result.Error);
|
||||
|
||||
if (!success)
|
||||
{
|
||||
Debug.LogError("Addressables build error encountered: " + result.Error);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
[MenuItem("Window/Asset Management/Addressables/Build Addressables only")]
|
||||
public static bool BuildAddressables()
|
||||
{
|
||||
getSettingsObject(settings_asset);
|
||||
setProfile(profile_name);
|
||||
IDataBuilder builderScript
|
||||
= AssetDatabase.LoadAssetAtPath<ScriptableObject>(build_script) as IDataBuilder;
|
||||
|
||||
if (builderScript == null)
|
||||
{
|
||||
Debug.LogError(build_script + " couldn't be found or isn't a build script.");
|
||||
return false;
|
||||
}
|
||||
|
||||
setBuilder(builderScript);
|
||||
|
||||
return buildAddressableContent();
|
||||
}
|
||||
|
||||
[MenuItem("Window/Asset Management/Addressables/Build Addressables and Player")]
|
||||
public static void BuildAddressablesAndPlayer()
|
||||
{
|
||||
bool contentBuildSucceeded = BuildAddressables();
|
||||
|
||||
if (contentBuildSucceeded)
|
||||
{
|
||||
var options = new BuildPlayerOptions();
|
||||
BuildPlayerOptions playerSettings
|
||||
= BuildPlayerWindow.DefaultBuildMethods.GetBuildPlayerOptions(options);
|
||||
|
||||
BuildPipeline.BuildPlayer(playerSettings);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ad20dc0f550e9ca4997c74ae771f6042
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,31 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor.AddressableAssets.Build;
|
||||
using UnityEditor.AddressableAssets.Build.DataBuilders;
|
||||
|
||||
internal class CustomBuildScript : BuildScriptBase
|
||||
{
|
||||
#region doc_CustomBuildScript
|
||||
|
||||
public override bool CanBuildData<T>()
|
||||
{
|
||||
return typeof(T).IsAssignableFrom(typeof(AddressablesPlayerBuildResult));
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
internal class CustomPlayModeScript : BuildScriptBase
|
||||
{
|
||||
#region doc_CustomPlayModeScript
|
||||
|
||||
public override bool CanBuildData<T>()
|
||||
{
|
||||
return typeof(T).IsAssignableFrom(typeof(AddressablesPlayModeBuildResult));
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
#endif
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 94ef737d5b23784419edd995a21c46ac
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,32 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
#region doc_SetCustomBuilder
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor.AddressableAssets;
|
||||
using UnityEditor.AddressableAssets.Build;
|
||||
using UnityEditor.AddressableAssets.Settings;
|
||||
using UnityEngine;
|
||||
|
||||
internal class CustomDataBuilder
|
||||
{
|
||||
public static void SetCustomDataBuilder(IDataBuilder builder)
|
||||
{
|
||||
AddressableAssetSettings settings
|
||||
= AddressableAssetSettingsDefaultObject.Settings;
|
||||
|
||||
int index = settings.DataBuilders.IndexOf((ScriptableObject)builder);
|
||||
if (index > 0)
|
||||
settings.ActivePlayerDataBuilderIndex = index;
|
||||
else if (AddressableAssetSettingsDefaultObject.Settings.AddDataBuilder(builder))
|
||||
settings.ActivePlayerDataBuilderIndex
|
||||
= AddressableAssetSettingsDefaultObject.Settings.DataBuilders.Count - 1;
|
||||
else
|
||||
Debug.LogWarning($"{builder} could not be found " +
|
||||
$"or added to the list of DataBuilders");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c2680c6a4bae5a14ba54dc55ec1852d7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,85 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
#region doc_DeclaringReferences
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
|
||||
internal class DeclaringReferences : MonoBehaviour
|
||||
{
|
||||
// Any asset type
|
||||
public AssetReference reference;
|
||||
|
||||
// Prefab assets
|
||||
public AssetReferenceGameObject gameObjectReference;
|
||||
|
||||
// Sprite asset types
|
||||
public AssetReferenceSprite spriteReference;
|
||||
public AssetReferenceAtlasedSprite atlasSpriteReference;
|
||||
|
||||
// Texture asset types
|
||||
public AssetReferenceTexture textureReference;
|
||||
public AssetReferenceTexture2D texture2DReference;
|
||||
public AssetReferenceTexture3D texture3DReference;
|
||||
|
||||
// Any asset type with the specified labels
|
||||
[AssetReferenceUILabelRestriction("animals", "characters")]
|
||||
public AssetReference labelRestrictedReference;
|
||||
|
||||
// Generic asset type (Unity 2020.3+)
|
||||
public AssetReferenceT<AudioClip> typedReference;
|
||||
|
||||
// Custom asset reference class
|
||||
public AssetReferenceMaterial materialReference;
|
||||
|
||||
[Serializable]
|
||||
public class AssetReferenceMaterial : AssetReferenceT<Material>
|
||||
{
|
||||
public AssetReferenceMaterial(string guid) : base(guid)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// Load assets...
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
// Release assets...
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region doc_ConcreteSubClass
|
||||
|
||||
[Serializable]
|
||||
internal class AssetReferenceMaterial : AssetReferenceT<Material>
|
||||
{
|
||||
public AssetReferenceMaterial(string guid) : base(guid)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
internal class UseExamples
|
||||
{
|
||||
#region doc_UseConcreteSubclass
|
||||
|
||||
// Custom asset reference class
|
||||
public AssetReferenceMaterial materialReference;
|
||||
|
||||
#endregion
|
||||
|
||||
#region doc_RestrictionAttribute
|
||||
|
||||
[AssetReferenceUILabelRestriction("animals", "characters")]
|
||||
public AssetReference labelRestrictedReference;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d545ea8b7528c004681a86c811e92281
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,18 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
#region SAMPLE
|
||||
#if (UNITY_EDITOR && ENABLE_CCD)
|
||||
using UnityEditor;
|
||||
using UnityEditor.AddressableAssets.Build;
|
||||
|
||||
public class DisableBuildWarning
|
||||
{
|
||||
static void DisableWarning()
|
||||
{
|
||||
CcdBuildEvents.OnPreBuildEvents -= CcdBuildEvents.Instance.VerifyBuildVersion;
|
||||
CcdBuildEvents.OnPreUpdateEvents -= CcdBuildEvents.Instance.VerifyBuildVersion;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endregion
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6ab59bdae5595f345b4b7357f4cade78
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,47 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
#region doc_DownloadError
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
using UnityEngine.ResourceManagement.Exceptions;
|
||||
|
||||
internal class HandleDownloadError : MonoBehaviour
|
||||
{
|
||||
private AsyncOperationHandle m_Handle;
|
||||
|
||||
void LoadAsset()
|
||||
{
|
||||
m_Handle = Addressables.LoadAssetAsync<GameObject>("addressKey");
|
||||
m_Handle.Completed += handle =>
|
||||
{
|
||||
string dlError = GetDownloadError(m_Handle);
|
||||
if (!string.IsNullOrEmpty(dlError))
|
||||
{
|
||||
// handle what error
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
string GetDownloadError(AsyncOperationHandle fromHandle)
|
||||
{
|
||||
if (fromHandle.Status != AsyncOperationStatus.Failed)
|
||||
return null;
|
||||
|
||||
RemoteProviderException remoteException;
|
||||
System.Exception e = fromHandle.OperationException;
|
||||
while (e != null)
|
||||
{
|
||||
remoteException = e as RemoteProviderException;
|
||||
if (remoteException != null)
|
||||
return remoteException.WebRequestResult.Error;
|
||||
e = e.InnerException;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6456c5ae7c7004aef90544e60bdb58e6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,38 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
//Prevent Unity from actually registering the rule in this example
|
||||
using RuntimeInitializeOnLoadMethod = Dummy;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
||||
#region doc_Transformer
|
||||
|
||||
using UnityEngine.ResourceManagement.ResourceLocations;
|
||||
using UnityEngine.ResourceManagement.ResourceProviders;
|
||||
using UnityEngine.AddressableAssets;
|
||||
|
||||
static class IDTransformer
|
||||
{
|
||||
//Implement a method to transform the internal ids of locations
|
||||
static string MyCustomTransform(IResourceLocation location)
|
||||
{
|
||||
if (location.ResourceType == typeof(IAssetBundleResource)
|
||||
&& location.InternalId.StartsWith("http", System.StringComparison.Ordinal))
|
||||
return location.InternalId + "?customQueryTag=customQueryValue";
|
||||
|
||||
return location.InternalId;
|
||||
}
|
||||
|
||||
//Override the Addressables transform method with your custom method.
|
||||
//This can be set to null to revert to default behavior.
|
||||
[RuntimeInitializeOnLoadMethod]
|
||||
static void SetInternalIdTransform()
|
||||
{
|
||||
Addressables.InternalIdTransformFunc = MyCustomTransform;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endif
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d80d649a59df7424dbd5e5c326a096eb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,37 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
#region doc_Instantiate
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
internal class InstantiateFromKey : MonoBehaviour
|
||||
{
|
||||
public string key; // Identify the asset
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Load and instantiate
|
||||
Addressables.InstantiateAsync(key).Completed += instantiate_Completed;
|
||||
}
|
||||
|
||||
private void instantiate_Completed(AsyncOperationHandle<GameObject> obj)
|
||||
{
|
||||
// Add component to release asset in GameObject OnDestroy event
|
||||
obj.Result.AddComponent(typeof(SelfCleanup));
|
||||
}
|
||||
}
|
||||
|
||||
// Releases asset (trackHandle must be true in InstantiateAsync,
|
||||
// which is the default)
|
||||
internal class SelfCleanup : MonoBehaviour
|
||||
{
|
||||
void OnDestroy()
|
||||
{
|
||||
Addressables.ReleaseInstance(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: eb39a5e8a9f342946b37f08b70b59d02
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,27 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
#region doc_InstantiateReference
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
|
||||
internal class InstantiateReference : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private AssetReferenceGameObject reference;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (reference != null)
|
||||
reference.InstantiateAsync(this.transform);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (reference != null && reference.IsValid())
|
||||
reference.ReleaseAsset();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1052cd47d54d3c941894699bcb6eb7f6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,100 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
#region doc_Load
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
using UnityEngine.ResourceManagement.ResourceLocations;
|
||||
|
||||
internal class LoadWithLocation : MonoBehaviour
|
||||
{
|
||||
public Dictionary<string, AsyncOperationHandle<GameObject>> operationDictionary;
|
||||
public List<string> keys;
|
||||
public UnityEvent Ready;
|
||||
|
||||
IEnumerator LoadAndAssociateResultWithKey(IList<string> keys)
|
||||
{
|
||||
if (operationDictionary == null)
|
||||
operationDictionary = new Dictionary<string, AsyncOperationHandle<GameObject>>();
|
||||
|
||||
AsyncOperationHandle<IList<IResourceLocation>> locations
|
||||
= Addressables.LoadResourceLocationsAsync(keys,
|
||||
Addressables.MergeMode.Union, typeof(GameObject));
|
||||
|
||||
yield return locations;
|
||||
|
||||
var loadOps = new List<AsyncOperationHandle>(locations.Result.Count);
|
||||
|
||||
foreach (IResourceLocation location in locations.Result)
|
||||
{
|
||||
AsyncOperationHandle<GameObject> handle =
|
||||
Addressables.LoadAssetAsync<GameObject>(location);
|
||||
handle.Completed += obj => operationDictionary.Add(location.PrimaryKey, obj);
|
||||
loadOps.Add(handle);
|
||||
}
|
||||
|
||||
yield return Addressables.ResourceManager.CreateGenericGroupOperation(loadOps, true);
|
||||
|
||||
Ready.Invoke();
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
Ready.AddListener(OnAssetsReady);
|
||||
StartCoroutine(LoadAndAssociateResultWithKey(keys));
|
||||
}
|
||||
|
||||
private void OnAssetsReady()
|
||||
{
|
||||
float x = 0, z = 0;
|
||||
foreach (var item in operationDictionary)
|
||||
{
|
||||
Debug.Log($"{item.Key} = {item.Value.Result.name}");
|
||||
Instantiate(item.Value.Result,
|
||||
new Vector3(x++ * 2.0f, 0, z * 2.0f),
|
||||
Quaternion.identity, transform);
|
||||
if (x > 9)
|
||||
{
|
||||
x = 0;
|
||||
z++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
foreach (var item in operationDictionary)
|
||||
{
|
||||
Addressables.Release(item.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
internal class LoadLocations
|
||||
{
|
||||
[System.Obsolete] //only because LoadResourceLocationsAsync now takes any IEnumerator rather than *just* a List
|
||||
IEnumerator example()
|
||||
{
|
||||
#region doc_LoadLocations
|
||||
|
||||
AsyncOperationHandle<IList<IResourceLocation>> handle
|
||||
= Addressables.LoadResourceLocationsAsync(
|
||||
new string[] {"knight", "villager"},
|
||||
Addressables.MergeMode.Union);
|
||||
|
||||
yield return handle;
|
||||
|
||||
//...
|
||||
|
||||
Addressables.Release(handle);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1cdcbf100409f3d4aa907f8b5caf6b72
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,55 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
#region doc_Load
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
internal class LoadMultiple : MonoBehaviour
|
||||
{
|
||||
// Label strings to load
|
||||
public List<string> keys = new List<string>() {"characters", "animals"};
|
||||
|
||||
// Operation handle used to load and release assets
|
||||
AsyncOperationHandle<IList<GameObject>> loadHandle;
|
||||
|
||||
// Load Addressables by Label
|
||||
public IEnumerator Start()
|
||||
{
|
||||
float x = 0, z = 0;
|
||||
loadHandle = Addressables.LoadAssetsAsync<GameObject>(
|
||||
keys,
|
||||
addressable =>
|
||||
{
|
||||
//Gets called for every loaded asset
|
||||
Instantiate<GameObject>(addressable,
|
||||
new Vector3(x++ * 2.0f, 0, z * 2.0f),
|
||||
Quaternion.identity,
|
||||
transform);
|
||||
|
||||
if (x > 9)
|
||||
{
|
||||
x = 0;
|
||||
z++;
|
||||
}
|
||||
}, Addressables.MergeMode.Union, // How to combine multiple labels
|
||||
false); // Whether to fail and release if any asset fails to load
|
||||
|
||||
yield return loadHandle;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
Addressables.Release(loadHandle);
|
||||
// Release all the loaded assets associated with loadHandle
|
||||
// Note that if you do not make loaded addressables a child of this object,
|
||||
// then you will need to devise another way of releasing the handle when
|
||||
// all the individual addressables are destroyed.
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 634d22cc95ac69641b8e6f5619e01630
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,42 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
#region doc_Load
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
internal class LoadFromReference : MonoBehaviour
|
||||
{
|
||||
// Assign in Editor
|
||||
public AssetReference reference;
|
||||
|
||||
// Start the load operation on start
|
||||
void Start()
|
||||
{
|
||||
AsyncOperationHandle handle = reference.LoadAssetAsync<GameObject>();
|
||||
handle.Completed += Handle_Completed;
|
||||
}
|
||||
|
||||
// Instantiate the loaded prefab on complete
|
||||
private void Handle_Completed(AsyncOperationHandle obj)
|
||||
{
|
||||
if (obj.Status == AsyncOperationStatus.Succeeded)
|
||||
{
|
||||
Instantiate(reference.Asset, transform);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("AssetReference failed to load.");
|
||||
}
|
||||
}
|
||||
|
||||
// Release asset when parent object is destroyed
|
||||
private void OnDestroy()
|
||||
{
|
||||
reference.ReleaseAsset();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3601319bba6273845939476c3b3bf510
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,28 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
#region doc_Load
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
using UnityEngine.ResourceManagement.ResourceProviders;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
internal class LoadSceneByAddress : MonoBehaviour
|
||||
{
|
||||
public string key; // address string
|
||||
private AsyncOperationHandle<SceneInstance> loadHandle;
|
||||
|
||||
void Start()
|
||||
{
|
||||
loadHandle = Addressables.LoadSceneAsync(key, LoadSceneMode.Additive);
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
Addressables.UnloadSceneAsync(loadHandle);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: faa4c2d5ab226634bb3fe6dd91e50a67
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,34 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
#region doc_Load
|
||||
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
internal class LoadAddress : MonoBehaviour
|
||||
{
|
||||
public string key;
|
||||
AsyncOperationHandle<GameObject> opHandle;
|
||||
|
||||
public IEnumerator Start()
|
||||
{
|
||||
opHandle = Addressables.LoadAssetAsync<GameObject>(key);
|
||||
yield return opHandle;
|
||||
|
||||
if (opHandle.Status == AsyncOperationStatus.Succeeded)
|
||||
{
|
||||
GameObject obj = opHandle.Result;
|
||||
Instantiate(obj, transform);
|
||||
}
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
Addressables.Release(opHandle);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 00e1416746642a9419ba6700f4267349
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,36 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
#region doc_LoadSynchronously
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
internal class LoadSynchronously : MonoBehaviour
|
||||
{
|
||||
public string address;
|
||||
AsyncOperationHandle<GameObject> opHandle;
|
||||
|
||||
void Start()
|
||||
{
|
||||
opHandle = Addressables.LoadAssetAsync<GameObject>(address);
|
||||
opHandle.WaitForCompletion(); // Returns when operation is complete
|
||||
|
||||
if (opHandle.Status == AsyncOperationStatus.Succeeded)
|
||||
{
|
||||
Instantiate(opHandle.Result, transform);
|
||||
}
|
||||
else
|
||||
{
|
||||
Addressables.Release(opHandle);
|
||||
}
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
Addressables.Release(opHandle);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0be87be5fff9bed408703777e5c234e7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,45 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
#region doc_LoadWithAddress
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
internal class LoadWithAddress : MonoBehaviour
|
||||
{
|
||||
// Assign in Editor or in code
|
||||
public string address;
|
||||
|
||||
// Retain handle to release asset and operation
|
||||
private AsyncOperationHandle<GameObject> handle;
|
||||
|
||||
// Start the load operation on start
|
||||
void Start()
|
||||
{
|
||||
handle = Addressables.LoadAssetAsync<GameObject>(address);
|
||||
handle.Completed += Handle_Completed;
|
||||
}
|
||||
|
||||
// Instantiate the loaded prefab on complete
|
||||
private void Handle_Completed(AsyncOperationHandle<GameObject> operation)
|
||||
{
|
||||
if (operation.Status == AsyncOperationStatus.Succeeded)
|
||||
{
|
||||
Instantiate(operation.Result, transform);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"Asset for {address} failed to load.");
|
||||
}
|
||||
}
|
||||
|
||||
// Release asset when parent object is destroyed
|
||||
private void OnDestroy()
|
||||
{
|
||||
Addressables.Release(handle);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d3994cd1747d38846bb962901129f8db
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,41 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
#region doc_LoadWithEvent
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
internal class LoadWithEvent : MonoBehaviour
|
||||
{
|
||||
public string address;
|
||||
AsyncOperationHandle<GameObject> opHandle;
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Create operation
|
||||
opHandle = Addressables.LoadAssetAsync<GameObject>(address);
|
||||
// Add event handler
|
||||
opHandle.Completed += Operation_Completed;
|
||||
}
|
||||
|
||||
private void Operation_Completed(AsyncOperationHandle<GameObject> obj)
|
||||
{
|
||||
if (obj.Status == AsyncOperationStatus.Succeeded)
|
||||
{
|
||||
Instantiate(obj.Result, transform);
|
||||
}
|
||||
else
|
||||
{
|
||||
Addressables.Release(obj);
|
||||
}
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
Addressables.Release(opHandle);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 99fcf6fd27648d1498338be53a9279a8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,41 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
#region doc_LoadWithIEnumerator
|
||||
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
internal class LoadWithIEnumerator : MonoBehaviour
|
||||
{
|
||||
public string address;
|
||||
AsyncOperationHandle<GameObject> opHandle;
|
||||
|
||||
public IEnumerator Start()
|
||||
{
|
||||
opHandle = Addressables.LoadAssetAsync<GameObject>(address);
|
||||
|
||||
// yielding when already done still waits until the next frame
|
||||
// so don't yield if done.
|
||||
if (!opHandle.IsDone)
|
||||
yield return opHandle;
|
||||
|
||||
if (opHandle.Status == AsyncOperationStatus.Succeeded)
|
||||
{
|
||||
Instantiate(opHandle.Result, transform);
|
||||
}
|
||||
else
|
||||
{
|
||||
Addressables.Release(opHandle);
|
||||
}
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
Addressables.Release(opHandle);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e840cb3f9e1c79f418991c22a9bbdd28
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,58 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
#region doc_LoadWithLabels
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
internal class LoadWithLabels : MonoBehaviour
|
||||
{
|
||||
// Label strings to load
|
||||
public List<string> keys = new List<string>() {"characters", "animals"};
|
||||
|
||||
// Operation handle used to load and release assets
|
||||
AsyncOperationHandle<IList<GameObject>> loadHandle;
|
||||
|
||||
// Load Addressables by Label
|
||||
void Start()
|
||||
{
|
||||
float x = 0, z = 0;
|
||||
loadHandle = Addressables.LoadAssetsAsync<GameObject>(
|
||||
keys, // Either a single key or a List of keys
|
||||
addressable =>
|
||||
{
|
||||
//Gets called for every loaded asset
|
||||
if (addressable != null)
|
||||
{
|
||||
Instantiate<GameObject>(addressable,
|
||||
new Vector3(x++ * 2.0f, 0, z * 2.0f),
|
||||
Quaternion.identity,
|
||||
transform);
|
||||
if (x > 9)
|
||||
{
|
||||
x = 0;
|
||||
z++;
|
||||
}
|
||||
}
|
||||
}, Addressables.MergeMode.Union, // How to combine multiple labels
|
||||
false); // Whether to fail if any asset fails to load
|
||||
loadHandle.Completed += LoadHandle_Completed;
|
||||
}
|
||||
|
||||
private void LoadHandle_Completed(AsyncOperationHandle<IList<GameObject>> operation)
|
||||
{
|
||||
if (operation.Status != AsyncOperationStatus.Succeeded)
|
||||
Debug.LogWarning("Some assets did not load.");
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
// Release all the loaded assets associated with loadHandle
|
||||
Addressables.Release(loadHandle);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1e2ff1980cce8ef4e88f793c1db900f4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,42 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
#region doc_LoadWithReference
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
internal class LoadWithReference : MonoBehaviour
|
||||
{
|
||||
// Assign in Editor
|
||||
public AssetReference reference;
|
||||
|
||||
// Start the load operation on start
|
||||
void Start()
|
||||
{
|
||||
AsyncOperationHandle handle = reference.LoadAssetAsync<GameObject>();
|
||||
handle.Completed += Handle_Completed;
|
||||
}
|
||||
|
||||
// Instantiate the loaded prefab on complete
|
||||
private void Handle_Completed(AsyncOperationHandle obj)
|
||||
{
|
||||
if (obj.Status == AsyncOperationStatus.Succeeded)
|
||||
{
|
||||
Instantiate(reference.Asset, transform);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"AssetReference {reference.RuntimeKey} failed to load.");
|
||||
}
|
||||
}
|
||||
|
||||
// Release asset when parent object is destroyed
|
||||
private void OnDestroy()
|
||||
{
|
||||
reference.ReleaseAsset();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: dd340326674dc4c418bd6cf12845b4c7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,87 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
#region doc_LoadWithTask
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
internal class LoadWithTask : MonoBehaviour
|
||||
{
|
||||
// Label or address strings to load
|
||||
public List<string> keys = new List<string>() {"characters", "animals"};
|
||||
|
||||
// Operation handle used to load and release assets
|
||||
AsyncOperationHandle<IList<GameObject>> loadHandle;
|
||||
|
||||
public async void Start()
|
||||
{
|
||||
loadHandle = Addressables.LoadAssetsAsync<GameObject>(
|
||||
keys, // Either a single key or a List of keys
|
||||
addressable =>
|
||||
{
|
||||
// Called for every loaded asset
|
||||
Debug.Log(addressable.name);
|
||||
}, Addressables.MergeMode.Union, // How to combine multiple labels
|
||||
false); // Whether to fail if any asset fails to load
|
||||
|
||||
// Wait for the operation to finish in the background
|
||||
await loadHandle.Task;
|
||||
|
||||
// Instantiate the results
|
||||
float x = 0, z = 0;
|
||||
foreach (var addressable in loadHandle.Result)
|
||||
{
|
||||
if (addressable != null)
|
||||
{
|
||||
Instantiate<GameObject>(addressable,
|
||||
new Vector3(x++ * 2.0f, 0, z * 2.0f),
|
||||
Quaternion.identity,
|
||||
transform); // make child of this object
|
||||
|
||||
if (x > 9)
|
||||
{
|
||||
x = 0;
|
||||
z++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
Addressables.Release(loadHandle);
|
||||
// Release all the loaded assets associated with loadHandle
|
||||
// Note that if you do not make loaded addressables a child of this object,
|
||||
// then you will need to devise another way of releasing the handle when
|
||||
// all the individual addressables are destroyed.
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
internal class LoadSequence
|
||||
{
|
||||
List<string> keys = new List<string>() {"characters", "animals"};
|
||||
UnityEngine.SceneManagement.Scene nextScene;
|
||||
|
||||
async void load()
|
||||
{
|
||||
#region doc_UseWhenAll
|
||||
|
||||
// Load the Prefabs
|
||||
var prefabOpHandle = Addressables.LoadAssetsAsync<GameObject>(
|
||||
keys, null, Addressables.MergeMode.Union, false);
|
||||
|
||||
// Load a Scene additively
|
||||
var sceneOpHandle
|
||||
= Addressables.LoadSceneAsync(nextScene,
|
||||
UnityEngine.SceneManagement.LoadSceneMode.Additive);
|
||||
|
||||
await System.Threading.Tasks.Task.WhenAll(prefabOpHandle.Task, sceneOpHandle.Task);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fde27ed4473003b4ba91281c9228e9f8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,178 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.AddressableAssets.ResourceLocators;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
using UnityEngine.ResourceManagement.ResourceLocations;
|
||||
using UnityEngine.ResourceManagement.ResourceProviders;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
internal class MiscellaneousTopics : MonoBehaviour
|
||||
{
|
||||
#region doc_LoadAdditionalCatalog
|
||||
|
||||
public IEnumerator Start()
|
||||
{
|
||||
//Load a catalog and automatically release the operation handle.
|
||||
AsyncOperationHandle<IResourceLocator> handle
|
||||
= Addressables.LoadContentCatalogAsync("path_to_secondary_catalog", true);
|
||||
yield return handle;
|
||||
|
||||
//...
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region doc_UpdateCatalog
|
||||
|
||||
IEnumerator UpdateCatalogs()
|
||||
{
|
||||
AsyncOperationHandle<List<IResourceLocator>> updateHandle
|
||||
= Addressables.UpdateCatalogs();
|
||||
|
||||
yield return updateHandle;
|
||||
Addressables.Release(updateHandle);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region doc_CheckCatalog
|
||||
|
||||
IEnumerator CheckCatalogs()
|
||||
{
|
||||
List<string> catalogsToUpdate = new List<string>();
|
||||
AsyncOperationHandle<List<string>> checkForUpdateHandle
|
||||
= Addressables.CheckForCatalogUpdates();
|
||||
checkForUpdateHandle.Completed += op => { catalogsToUpdate.AddRange(op.Result); };
|
||||
|
||||
yield return checkForUpdateHandle;
|
||||
|
||||
if (catalogsToUpdate.Count > 0)
|
||||
{
|
||||
AsyncOperationHandle<List<IResourceLocator>> updateHandle
|
||||
= Addressables.UpdateCatalogs(catalogsToUpdate);
|
||||
yield return updateHandle;
|
||||
Addressables.Release(updateHandle);
|
||||
}
|
||||
|
||||
Addressables.Release(checkForUpdateHandle);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region doc_TransformID
|
||||
|
||||
void SetIDTransformFunction()
|
||||
{
|
||||
Addressables.ResourceManager.InternalIdTransformFunc = TransformFunc;
|
||||
}
|
||||
|
||||
string TransformFunc(IResourceLocation location)
|
||||
{
|
||||
//Implement a method that gets the base url for a given location
|
||||
string baseUrl = GetBaseURL(location);
|
||||
|
||||
//Get the url you want to use to point to your current server
|
||||
string currentUrlToUse = GetCurrentURL();
|
||||
|
||||
return location.InternalId.Replace(baseUrl, currentUrlToUse);
|
||||
}
|
||||
|
||||
string GetBaseURL(IResourceLocation location)
|
||||
{
|
||||
return "baseURL"; // The part of the id that represents the base URL
|
||||
}
|
||||
|
||||
string GetCurrentURL()
|
||||
{
|
||||
return "https://example.com"; // The replacement URL
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
IEnumerator example_GetAddress()
|
||||
{
|
||||
AssetReference MyRef1 = new AssetReference();
|
||||
|
||||
#region doc_AddressFromReference
|
||||
|
||||
var opHandle = Addressables.LoadResourceLocationsAsync(MyRef1);
|
||||
yield return opHandle;
|
||||
|
||||
if (opHandle.Status == AsyncOperationStatus.Succeeded &&
|
||||
opHandle.Result != null &&
|
||||
opHandle.Result.Count > 0)
|
||||
{
|
||||
Debug.Log("address is: " + opHandle.Result[0].PrimaryKey);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#region doc_PreloadHazards
|
||||
|
||||
Dictionary<string, GameObject> _preloadedObjects
|
||||
= new Dictionary<string, GameObject>();
|
||||
|
||||
private IEnumerator PreloadHazards()
|
||||
{
|
||||
//find all the locations with label "SpaceHazards"
|
||||
var loadResourceLocationsHandle
|
||||
= Addressables.LoadResourceLocationsAsync("SpaceHazards", typeof(GameObject));
|
||||
|
||||
if (!loadResourceLocationsHandle.IsDone)
|
||||
yield return loadResourceLocationsHandle;
|
||||
|
||||
//start each location loading
|
||||
List<AsyncOperationHandle> opList = new List<AsyncOperationHandle>();
|
||||
|
||||
foreach (IResourceLocation location in loadResourceLocationsHandle.Result)
|
||||
{
|
||||
AsyncOperationHandle<GameObject> loadAssetHandle
|
||||
= Addressables.LoadAssetAsync<GameObject>(location);
|
||||
loadAssetHandle.Completed +=
|
||||
obj => { _preloadedObjects.Add(location.PrimaryKey, obj.Result); };
|
||||
opList.Add(loadAssetHandle);
|
||||
}
|
||||
|
||||
//create a GroupOperation to wait on all the above loads at once.
|
||||
var groupOp = Addressables.ResourceManager.CreateGenericGroupOperation(opList);
|
||||
|
||||
if (!groupOp.IsDone)
|
||||
yield return groupOp;
|
||||
|
||||
Addressables.Release(loadResourceLocationsHandle);
|
||||
|
||||
//take a gander at our results.
|
||||
foreach (var item in _preloadedObjects)
|
||||
{
|
||||
Debug.Log(item.Key + " - " + item.Value.name);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private IEnumerator PreloadAssets()
|
||||
{
|
||||
#region doc_Download
|
||||
|
||||
string key = "assetKey";
|
||||
|
||||
// Check the download size
|
||||
AsyncOperationHandle<long> getDownloadSize = Addressables.GetDownloadSizeAsync(key);
|
||||
yield return getDownloadSize;
|
||||
|
||||
//If the download size is greater than 0, download all the dependencies.
|
||||
if (getDownloadSize.Result > 0)
|
||||
{
|
||||
AsyncOperationHandle downloadDependencies = Addressables.DownloadDependenciesAsync(key);
|
||||
yield return downloadDependencies;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 81e07f4bd9fd35f42828b48ea81bbd13
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,42 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
//Prevent Unity from actually registering the rule in this example
|
||||
using InitializeOnLoadAttribute = Dummy;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
||||
#region doc_CustomRule
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEditor.AddressableAssets.Build;
|
||||
using UnityEditor.AddressableAssets.Build.AnalyzeRules;
|
||||
|
||||
class MyRule : AnalyzeRule
|
||||
{
|
||||
// Rule code...
|
||||
}
|
||||
|
||||
// Register rule
|
||||
[InitializeOnLoad]
|
||||
class RegisterMyRule
|
||||
{
|
||||
static RegisterMyRule()
|
||||
{
|
||||
AnalyzeSystem.RegisterNewRule<MyRule>();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endif
|
||||
internal class Dummy : System.Attribute
|
||||
{
|
||||
public Dummy()
|
||||
{
|
||||
}
|
||||
|
||||
public Dummy(string parameter)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c13c4d40f03b84e489576570ec2daf5e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,32 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
#region doc_LoadSynchronously
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
internal class OperationHandleTypes
|
||||
{
|
||||
void Snippet()
|
||||
{
|
||||
#region doc_ConvertTypes
|
||||
|
||||
// Load asset using typed handle:
|
||||
AsyncOperationHandle<Texture2D> textureHandle = Addressables.LoadAssetAsync<Texture2D>("mytexture");
|
||||
|
||||
// Convert the AsyncOperationHandle<Texture2D> to an AsyncOperationHandle:
|
||||
AsyncOperationHandle nonGenericHandle = textureHandle;
|
||||
|
||||
// Convert the AsyncOperationHandle to an AsyncOperationHandle<Texture2D>:
|
||||
AsyncOperationHandle<Texture2D> textureHandle2 = nonGenericHandle.Convert<Texture2D>();
|
||||
|
||||
// This will throw and exception because Texture2D is required:
|
||||
AsyncOperationHandle<Texture> textureHandle3 = nonGenericHandle.Convert<Texture>();
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4a54c5871bef465498da44ad7451313d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,18 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
#region doc_Preload
|
||||
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
|
||||
internal class Preload : MonoBehaviour
|
||||
{
|
||||
public IEnumerator Start()
|
||||
{
|
||||
yield return Addressables.DownloadDependenciesAsync("preload", true);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 75340b8683e5f084ab85df09444ac24e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,56 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
#region doc_Preload
|
||||
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
internal class PreloadWithProgress : MonoBehaviour
|
||||
{
|
||||
public string preloadLabel = "preload";
|
||||
public UnityEvent<float> ProgressEvent;
|
||||
public UnityEvent<bool> CompletionEvent;
|
||||
private AsyncOperationHandle downloadHandle;
|
||||
|
||||
IEnumerator Start()
|
||||
{
|
||||
downloadHandle = Addressables.DownloadDependenciesAsync(preloadLabel, false);
|
||||
float progress = 0;
|
||||
|
||||
while (downloadHandle.Status == AsyncOperationStatus.None)
|
||||
{
|
||||
float percentageComplete = downloadHandle.GetDownloadStatus().Percent;
|
||||
if (percentageComplete > progress * 1.1) // Report at most every 10% or so
|
||||
{
|
||||
progress = percentageComplete; // More accurate %
|
||||
ProgressEvent.Invoke(progress);
|
||||
}
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
CompletionEvent.Invoke(downloadHandle.Status == AsyncOperationStatus.Succeeded);
|
||||
Addressables.Release(downloadHandle); //Release the operation handle
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
internal class PreloadExamples
|
||||
{
|
||||
string key;
|
||||
|
||||
void example()
|
||||
{
|
||||
#region doc_DownloadSize
|
||||
|
||||
AsyncOperationHandle<long> getDownloadSize =
|
||||
Addressables.GetDownloadSizeAsync(key);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 17371403cb6db7b4489e8fcd43b02b56
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,27 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
#region SAMPLE
|
||||
#if (UNITY_EDITOR && ENABLE_CCD)
|
||||
using System.Threading.Tasks;
|
||||
using UnityEditor.AddressableAssets.Build;
|
||||
|
||||
public class BuildHooks
|
||||
{
|
||||
|
||||
static void AddBuildHook()
|
||||
{
|
||||
CcdBuildEvents.PrependPreBuildEvent(PrintBucketInformation);
|
||||
CcdBuildEvents.PrependPreUpdateEvent(PrintBucketInformation);
|
||||
}
|
||||
|
||||
static async Task<bool> PrintBucketInformation(AddressablesDataBuilderInput input)
|
||||
{
|
||||
UnityEngine.Debug.Log($"Environment: {CcdManager.EnvironmentName}");
|
||||
UnityEngine.Debug.Log($"Bucket: {CcdManager.BucketId}");
|
||||
UnityEngine.Debug.Log($"Badge: {CcdManager.Badge}");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endregion
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e1e6c6d3afa9b8d44924fe8dcbee49a4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,17 @@
|
|||
The C# files in this directory contain the code examples appearing
|
||||
in the documentation. They are included in this format so that the
|
||||
code is compiled and checked before every release. The code is not
|
||||
created for the purpose of stand-alone use and is not part of the
|
||||
supported, public API of the Addressables package. In most cases,
|
||||
you must make changes before the example code can be used in a project.
|
||||
|
||||
Use of this example code is covered by the Unity Companion License
|
||||
for Unity-dependent projects. See:
|
||||
https://unity3d.com/legal/licenses/Unity_Companion_License).
|
||||
|
||||
Unless expressly provided otherwise, the Software under this license
|
||||
is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF
|
||||
ANY KIND, EXPRESS OR IMPLIED. Please review the license for details
|
||||
on these and other terms and conditions. All other information in the
|
||||
Unity Manual and Scripting Reference is licensed under the Creative Commons
|
||||
Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND)
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 643c3989e991eb74ca3064e6baa4361a
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 14eabbd60aeb052409b51db02db54c84
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,33 @@
|
|||
#region CONTENT_BUILT_CHECK
|
||||
#if UNITY_EDITOR
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEditor.AddressableAssets;
|
||||
using UnityEditor.AddressableAssets.Build;
|
||||
using UnityEditor.AddressableAssets.Settings.GroupSchemas;
|
||||
using UnityEditor.Build;
|
||||
using UnityEditor.Build.Reporting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
|
||||
public class ContentBuiltCheck : IPreprocessBuildWithReport
|
||||
{
|
||||
public int callbackOrder => 1;
|
||||
|
||||
public void OnPreprocessBuild(BuildReport report)
|
||||
{
|
||||
// we don't want to throw the exception in our continuous integration environment
|
||||
if (Application.isBatchMode)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var settingsPath = Addressables.BuildPath + "/settings.json";
|
||||
if (!File.Exists(settingsPath))
|
||||
{
|
||||
throw new System.Exception("Player content has not been built. Aborting build until content is built. This can be done from the Addressables window in the Build->Build Player Content menu command.");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endregion
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bc282c9c64eccda4392e29f59439a37e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,54 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.AddressableAssets.ResourceLocators;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
using UnityEngine.ResourceManagement.ResourceLocations;
|
||||
using UnityEngine.ResourceManagement.ResourceProviders;
|
||||
|
||||
internal class UsingAddResourceLocator
|
||||
{
|
||||
#region DECLARATION
|
||||
public static void AddResourceLocator(IResourceLocator locator, string localCatalogHash = null, IResourceLocation remoteCatalogLocation = null)
|
||||
#endregion
|
||||
{ }
|
||||
|
||||
#region SAMPLE_ADDLOCATOR
|
||||
private string m_SourceFolder = "dataFiles";
|
||||
|
||||
public void AddFileLocatorToAddressables()
|
||||
{
|
||||
if (!Directory.Exists(m_SourceFolder))
|
||||
return;
|
||||
|
||||
ResourceLocationMap locator = new ResourceLocationMap(m_SourceFolder + "_FilesLocator", 12);
|
||||
string providerId = typeof(TextDataProvider).ToString();
|
||||
|
||||
string[] files = Directory.GetFiles(m_SourceFolder);
|
||||
foreach (string filePath in files)
|
||||
{
|
||||
if (!filePath.EndsWith(".json"))
|
||||
continue;
|
||||
string keyForLoading = Path.GetFileNameWithoutExtension(filePath);
|
||||
locator.Add(keyForLoading, new ResourceLocationBase(keyForLoading, filePath, providerId, typeof(string)));
|
||||
}
|
||||
Addressables.AddResourceLocator(locator);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region SAMPLE_LOADING
|
||||
private string m_DataFileName = "settings";
|
||||
|
||||
public IEnumerator LoadDataUsingAddedLocator()
|
||||
{
|
||||
var loadingHandle = Addressables.LoadAssetAsync<string>(m_DataFileName);
|
||||
yield return loadingHandle;
|
||||
Debug.Log("Load completed " + loadingHandle.Status + (loadingHandle.Status == AsyncOperationStatus.Succeeded ? ", with result " + loadingHandle.Result : ""));
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 08d6d38651abd624b9c945a1ed5d80bb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,24 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.AddressableAssets.Initialization;
|
||||
|
||||
internal class UsingBuildPath
|
||||
{
|
||||
#region GET_SETTINGS_FROM_BUILDPATH
|
||||
public string GetBuiltContentAddressablesVersion()
|
||||
{
|
||||
string settingsPath = Addressables.BuildPath + "/settings.json";
|
||||
if (System.IO.File.Exists(settingsPath))
|
||||
{
|
||||
string json = System.IO.File.ReadAllText(settingsPath);
|
||||
ResourceManagerRuntimeData activeRuntimeSettings =
|
||||
JsonUtility.FromJson<ResourceManagerRuntimeData>(json);
|
||||
return activeRuntimeSettings.AddressablesVersion;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7ba9fc75a0048b0469b01c6cf75f65e4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,33 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
internal class UsingCheckForCatalogUpdates
|
||||
{
|
||||
#region DECLARATION
|
||||
public static AsyncOperationHandle<List<string>> CheckForCatalogUpdates(bool autoReleaseHandle = true)
|
||||
#endregion
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
public void UsingCheckForCatalogUpdatesSample()
|
||||
{
|
||||
#region SAMPLE
|
||||
Addressables.CheckForCatalogUpdates().Completed += op =>
|
||||
{
|
||||
if (op.Status == AsyncOperationStatus.Succeeded)
|
||||
{
|
||||
foreach (string catalogWithUpdate in op.Result)
|
||||
Debug.Log($"Catalog {catalogWithUpdate} has an available update.");
|
||||
}
|
||||
};
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3fae9482157db504bbc96bab93cc2e52
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,60 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
internal class UsingCleanBundleCache
|
||||
{
|
||||
#region DECLARATION
|
||||
public static AsyncOperationHandle<bool> CleanBundleCache(IEnumerable<string> catalogsIds = null)
|
||||
#endregion
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
#region SAMPLE_ALL
|
||||
public void UsingCleanBundleCacheForAllCatalogs()
|
||||
{
|
||||
// clear for all currently loaded catalogs
|
||||
// if catalogIds are provided, only those catalogs are used from the currently loaded
|
||||
AsyncOperationHandle<bool> cleanBundleCacheHandle = Addressables.CleanBundleCache();
|
||||
cleanBundleCacheHandle.Completed += op =>
|
||||
{
|
||||
// during caching a reference is added to the catalogs.
|
||||
// release is needed to reduce the reference and allow catalog to be uncached for updating
|
||||
Addressables.Release(op);
|
||||
};
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region SAMPLE_SPECIFY
|
||||
public void UsingCleanBundleCacheWithcatalogIds()
|
||||
{
|
||||
HashSet<string> catalogsIds = new HashSet<string>();
|
||||
foreach (var locator in Addressables.ResourceLocators)
|
||||
{
|
||||
if (locator.LocatorId == "AddressablesMainContentCatalog")
|
||||
{
|
||||
catalogsIds.Add(locator.LocatorId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (catalogsIds.Count == 0)
|
||||
return;
|
||||
|
||||
var cleanBundleCacheHandle = Addressables.CleanBundleCache(catalogsIds);
|
||||
cleanBundleCacheHandle.Completed += op =>
|
||||
{
|
||||
// during caching a reference is added to the catalogs.
|
||||
// release is needed to reduce the reference and allow catalog to be uncached for updating
|
||||
Addressables.Release(op);
|
||||
};
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 255df104f26ec08439fcee2d0df9ae0b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,15 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
internal class UsingClearDependencyCacheAsync
|
||||
{
|
||||
#region SAMPLE
|
||||
public void UsingClearDependencyCacheAsyncSample()
|
||||
{
|
||||
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2e94e1c7d8bd4b842a1d59b7eefc8a34
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,15 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
internal class UsingClearResourceLocators
|
||||
{
|
||||
#region SAMPLE
|
||||
public void UsingClearResourceLocatorsSample()
|
||||
{
|
||||
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1a93de9886d3e5046be743fac772d5c3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,15 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
internal class UsingCreateCatalogLocationWithHashDependencies
|
||||
{
|
||||
#region SAMPLE
|
||||
public void UsingCreateCatalogLocationWithHashDependenciesSample()
|
||||
{
|
||||
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5127a10aa9aa1f147b436d8241d02ce0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,15 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
internal class UsingDownloadDependencies
|
||||
{
|
||||
#region SAMPLE
|
||||
public void UsingDownloadDependenciesSample()
|
||||
{
|
||||
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d165a767fad23a54d963742efdf90740
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,15 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
internal class UsingDownloadDependenciesAsync
|
||||
{
|
||||
#region SAMPLE
|
||||
public void UsingDownloadDependenciesAsyncSample()
|
||||
{
|
||||
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 07dd3f1d43b528f4ea00ed7dcb84972d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,16 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
internal class UsingGetDownloadSize
|
||||
{
|
||||
#region DECLARATION
|
||||
public static AsyncOperationHandle<long> GetDownloadSize(object key)
|
||||
#endregion
|
||||
{
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8ca20cc03036f2e428964397259f253a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,15 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
internal class UsingGetDownloadSizeAsync
|
||||
{
|
||||
#region SAMPLE
|
||||
public void UsingGetDownloadSizeAsyncSample()
|
||||
{
|
||||
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 48d6c3468cb636c449f15b9361793735
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,77 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.AddressableAssets.ResourceLocators;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
internal class UsingGetLocatorInfo
|
||||
{
|
||||
#region DECLARATION_1
|
||||
public static ResourceLocatorInfo GetLocatorInfo(string locatorId)
|
||||
#endregion
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
#region DECLARATION_2
|
||||
public static ResourceLocatorInfo GetLocatorInfo(IResourceLocator locator)
|
||||
#endregion
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
#region SAMPLE_1
|
||||
IEnumerator UsingGetLocatorInfoSampleId()
|
||||
{
|
||||
yield return Addressables.InitializeAsync();
|
||||
IEnumerable<IResourceLocator> resourceLocators = Addressables.ResourceLocators;
|
||||
foreach (IResourceLocator locator in resourceLocators)
|
||||
{
|
||||
// Call GetLocatorInfo using the locator id
|
||||
ResourceLocatorInfo locatorInfo = Addressables.GetLocatorInfo(locator.LocatorId);
|
||||
if (locatorInfo != null && locatorInfo.CatalogLocation != null)
|
||||
{
|
||||
if (locatorInfo.CanUpdateContent)
|
||||
Debug.Log($"Locator {locator.LocatorId} was loaded from an UPDATABLE catalog with internal id : {locatorInfo.CatalogLocation.InternalId}");
|
||||
else
|
||||
Debug.Log($"Locator {locator.LocatorId} was loaded from an NON-UPDATABLE catalog with internal id : {locatorInfo.CatalogLocation.InternalId}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"Locator {locator.LocatorId} is not associated with a catalog");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region SAMPLE_2
|
||||
IEnumerator UsingGetLocatorInfoSampleLocator()
|
||||
{
|
||||
yield return Addressables.InitializeAsync();
|
||||
IEnumerable<IResourceLocator> resourceLocators = Addressables.ResourceLocators;
|
||||
foreach (IResourceLocator locator in resourceLocators)
|
||||
{
|
||||
// Call GetLocatorInfo using the locator object
|
||||
ResourceLocatorInfo locatorInfo = Addressables.GetLocatorInfo(locator);
|
||||
if (locatorInfo != null && locatorInfo.CatalogLocation != null)
|
||||
{
|
||||
if (locatorInfo.CanUpdateContent)
|
||||
Debug.Log($"Locator {locator.LocatorId} was loaded from an UPDATABLE catalog with internal id : {locatorInfo.CatalogLocation.InternalId}");
|
||||
else
|
||||
Debug.Log($"Locator {locator.LocatorId} was loaded from an NON-UPDATABLE catalog with internal id : {locatorInfo.CatalogLocation.InternalId}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"Locator {locator.LocatorId} is not associated with a catalog");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3e43e1a65262edd4f99dd21ce8ee50ad
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,14 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets.ResourceLocators;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
internal class UsingInitializationOperation
|
||||
{
|
||||
#region DECLARATION
|
||||
public static AsyncOperationHandle<IResourceLocator> InitializationOperation { get; }
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4061552d898b3a04696a1cefac59e068
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,17 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets.ResourceLocators;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
internal class UsingInitialize
|
||||
{
|
||||
#region DECLARATION
|
||||
public static AsyncOperationHandle<IResourceLocator> Initialize()
|
||||
#endregion
|
||||
{
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f7aebf13e806bda4db01138506100f36
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,86 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.AddressableAssets.ResourceLocators;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
using UnityEngine.ResourceManagement.ResourceLocations;
|
||||
|
||||
internal class UsingInitializeAsync
|
||||
{
|
||||
#region DECLARATION_1
|
||||
public static AsyncOperationHandle<IResourceLocator> InitializeAsync()
|
||||
#endregion
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
#region DECLARATION_2
|
||||
public static AsyncOperationHandle<IResourceLocator> InitializeAsync(bool autoReleaseHandle)
|
||||
#endregion
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
#region SAMPLE_LOADALL
|
||||
void UsingInitializeAsyncSampleCallback()
|
||||
{
|
||||
Addressables.InitializeAsync().Completed += OnInitializeComplete;
|
||||
}
|
||||
|
||||
void OnInitializeComplete(AsyncOperationHandle<IResourceLocator> handle)
|
||||
{
|
||||
if (handle.Status == AsyncOperationStatus.Succeeded)
|
||||
{
|
||||
Debug.Log("Addressables initialization succeeded");
|
||||
IResourceLocator locator = handle.Result;
|
||||
|
||||
// locator.Keys includes bundle names and other identifiers from the local catalog.
|
||||
foreach (object locatorKey in locator.Keys)
|
||||
{
|
||||
locator.Locate(locatorKey, typeof(UnityEngine.Object), out IList<IResourceLocation> locations);
|
||||
if (locations == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (IResourceLocation location in locations)
|
||||
{
|
||||
// The key representing the location of an Addressable asset.
|
||||
string locationKey = location.InternalId;
|
||||
Addressables.LoadAssetAsync<UnityEngine.Object>(locationKey).Completed += OnLoadAssetComplete;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnLoadAssetComplete(AsyncOperationHandle<UnityEngine.Object> handle)
|
||||
{
|
||||
if (handle.Status == AsyncOperationStatus.Succeeded)
|
||||
{
|
||||
Debug.Log($"Successfully loaded {handle.Result.name} ({handle.Result.GetType()})");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region SAMPLE_TASK
|
||||
async Task UsingInitializeAsyncSampleTask()
|
||||
{
|
||||
AsyncOperationHandle<IResourceLocator> handle = Addressables.InitializeAsync(false);
|
||||
await handle.Task;
|
||||
if (handle.Status == AsyncOperationStatus.Succeeded)
|
||||
{
|
||||
Debug.Log("Addressables initialization succeeded");
|
||||
IResourceLocator locator = handle.Result;
|
||||
Debug.Log($"The resource locator returned has an id of {locator.LocatorId}");
|
||||
}
|
||||
Addressables.Release(handle);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9a0e76a5271d67041be5c790b6c724fd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,66 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
using UnityEngine.ResourceManagement.ResourceLocations;
|
||||
using UnityEngine.ResourceManagement.ResourceProviders;
|
||||
|
||||
internal class UsingInstanceProvider
|
||||
{
|
||||
#region DECLARATION
|
||||
public static IInstanceProvider InstanceProvider { get; }
|
||||
#endregion
|
||||
|
||||
#region SAMPLE
|
||||
public AssetReferenceGameObject asset; // Identify the asset
|
||||
AsyncOperationHandle<GameObject> instHandle;
|
||||
AsyncOperationHandle<IList<IResourceLocation>> locHandle;
|
||||
|
||||
void UsingInstanceProviderSample()
|
||||
{
|
||||
locHandle = Addressables.LoadResourceLocationsAsync(asset, typeof(GameObject));
|
||||
locHandle.Completed += OnLoadComplete;
|
||||
}
|
||||
|
||||
void OnLoadComplete(AsyncOperationHandle<IList<IResourceLocation>> handle)
|
||||
{
|
||||
if (handle.Status == AsyncOperationStatus.Succeeded)
|
||||
{
|
||||
Debug.Log($"Successfully loaded resource locations");
|
||||
foreach (IResourceLocation location in handle.Result)
|
||||
{
|
||||
ResourceManager rm = Addressables.ResourceManager;
|
||||
IInstanceProvider provider = Addressables.InstanceProvider;
|
||||
instHandle = rm.ProvideInstance(provider, location, default(InstantiationParameters));
|
||||
instHandle.Completed += OnProvideInstanceComplete;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnProvideInstanceComplete(AsyncOperationHandle<GameObject> handle)
|
||||
{
|
||||
if (handle.Status == AsyncOperationStatus.Succeeded)
|
||||
{
|
||||
Debug.Log($"Successfully instantiated GameObject named '{handle.Result.name}'");
|
||||
}
|
||||
}
|
||||
|
||||
void ReleaseResources()
|
||||
{
|
||||
Addressables.Release(locHandle);
|
||||
Addressables.Release(instHandle);
|
||||
}
|
||||
|
||||
// When ready to release the asset, call ReleaseResources().
|
||||
// For example during OnDestroy().
|
||||
// void OnDestroy()
|
||||
// {
|
||||
// ReleaseResources();
|
||||
// }
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cef69ad46d3a2a54aa5198dad625fe82
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,15 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
internal class UsingInstantiate
|
||||
{
|
||||
#region SAMPLE
|
||||
public void UsingInstantiateSample()
|
||||
{
|
||||
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d8f1f0a84c60dd84e8aea13155080a5b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,170 @@
|
|||
namespace AddressableAssets.DocExampleCode
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
using UnityEngine.ResourceManagement.ResourceLocations;
|
||||
using UnityEngine.ResourceManagement.ResourceProviders;
|
||||
|
||||
internal class UsingInstantiateAsync
|
||||
{
|
||||
#region DECLARATION_1
|
||||
public static AsyncOperationHandle<GameObject> InstantiateAsync(IResourceLocation location, Transform parent = null, bool instantiateInWorldSpace = false, bool trackHandle = true)
|
||||
#endregion
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
#region DECLARATION_2
|
||||
public static AsyncOperationHandle<GameObject> InstantiateAsync(IResourceLocation location, Vector3 position, Quaternion rotation, Transform parent = null, bool trackHandle = true)
|
||||
#endregion
|
||||
{
|
||||
return Addressables.InstantiateAsync(location, position, rotation, parent, trackHandle);
|
||||
}
|
||||
|
||||
#region DECLARATION_3
|
||||
public static AsyncOperationHandle<GameObject> InstantiateAsync(IResourceLocation location, InstantiationParameters instantiateParameters, bool trackHandle = true)
|
||||
#endregion
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
#region DECLARATION_4
|
||||
public static AsyncOperationHandle<GameObject> InstantiateAsync(object key, Transform parent = null, bool instantiateInWorldSpace = false, bool trackHandle = true)
|
||||
#endregion
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
#region DECLARATION_5
|
||||
public static AsyncOperationHandle<GameObject> InstantiateAsync(object key, Vector3 position, Quaternion rotation, Transform parent = null, bool trackHandle = true)
|
||||
#endregion
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
#region DECLARATION_6
|
||||
public static AsyncOperationHandle<GameObject> InstantiateAsync(object key, InstantiationParameters instantiateParameters, bool trackHandle = true)
|
||||
#endregion
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
#region SAMPLE_LOCATION
|
||||
public AssetReferenceGameObject assetRefLocation; // Identify the asset
|
||||
public Transform parentTransformLocation; // Identify the transform of the parent GameObject
|
||||
AsyncOperationHandle<IList<IResourceLocation>> locHandle;
|
||||
GameObject instanceLocation;
|
||||
|
||||
void UsingInstantiateAsyncSampleLocation()
|
||||
{
|
||||
locHandle = Addressables.LoadResourceLocationsAsync(assetRefLocation, typeof(GameObject));
|
||||
locHandle.Completed += OnLoadComplete;
|
||||
}
|
||||
|
||||
void OnLoadComplete(AsyncOperationHandle<IList<IResourceLocation>> handle)
|
||||
{
|
||||
if (handle.Status == AsyncOperationStatus.Succeeded)
|
||||
{
|
||||
Debug.Log($"Successfully loaded resource locations");
|
||||
foreach (IResourceLocation location in handle.Result)
|
||||
{
|
||||
string locationKey = location.InternalId;
|
||||
var instParams = new InstantiationParameters(parentTransformLocation, false);
|
||||
Addressables.InstantiateAsync(location, instParams).Completed += OnInstantiateCompleteLocation;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnInstantiateCompleteLocation(AsyncOperationHandle<GameObject> handle)
|
||||
{
|
||||
if (handle.Status == AsyncOperationStatus.Succeeded)
|
||||
{
|
||||
instanceLocation = handle.Result;
|
||||
Debug.Log($"Successfully instantiated GameObject with name '{instanceLocation.name}'.");
|
||||
}
|
||||
}
|
||||
|
||||
void ReleaseResourcesLocation()
|
||||
{
|
||||
Addressables.Release(locHandle);
|
||||
Addressables.ReleaseInstance(instanceLocation);
|
||||
}
|
||||
|
||||
// When ready to release the asset, call ReleaseTrackedResources().
|
||||
// For example during OnDestroy().
|
||||
//void OnDestroy()
|
||||
//{
|
||||
// ReleaseResourcesLocation();
|
||||
//}
|
||||
#endregion
|
||||
|
||||
#region SAMPLE_OBJECT_TRACKED
|
||||
public AssetReferenceGameObject assetRefTracked; // Identify the asset
|
||||
public Transform parentTransformTracked; // Identify the transform of the parent GameObject
|
||||
GameObject instanceTracked;
|
||||
|
||||
void UsingInstantiateAsyncSampleKeyTracked()
|
||||
{
|
||||
var instParams = new InstantiationParameters(parentTransformTracked, false);
|
||||
Addressables.InstantiateAsync(assetRefTracked, instParams).Completed += OnInstantiateCompleteObjectTracked;
|
||||
}
|
||||
|
||||
void OnInstantiateCompleteObjectTracked(AsyncOperationHandle<GameObject> handle)
|
||||
{
|
||||
if (handle.Status == AsyncOperationStatus.Succeeded)
|
||||
{
|
||||
instanceTracked = handle.Result;
|
||||
Debug.Log($"Successfully instantiated GameObject with name '{instanceTracked.name}'.");
|
||||
}
|
||||
}
|
||||
|
||||
void ReleaseTrackedResources()
|
||||
{
|
||||
Addressables.ReleaseInstance(instanceTracked);
|
||||
}
|
||||
|
||||
// When ready to release the asset, call ReleaseTrackedResources().
|
||||
// For example during OnDestroy().
|
||||
//void OnDestroy()
|
||||
//{
|
||||
// ReleaseTrackedResources();
|
||||
//}
|
||||
#endregion
|
||||
|
||||
#region SAMPLE_OBJECT_UNTRACKED
|
||||
public AssetReferenceGameObject assetRefUntracked; // Identify the asset
|
||||
public Transform parentTransformUntracked; // Identify the transform component of the parent GameObject
|
||||
AsyncOperationHandle<GameObject> handleUntracked;
|
||||
|
||||
void UsingInstantiateAsyncSampleKeyUntracked()
|
||||
{
|
||||
var instParams = new InstantiationParameters(parentTransformUntracked, false);
|
||||
handleUntracked = Addressables.InstantiateAsync(assetRefUntracked, instParams, false);
|
||||
handleUntracked.Completed += OnInstantiateCompleteObjectUntracked;
|
||||
}
|
||||
|
||||
void OnInstantiateCompleteObjectUntracked(AsyncOperationHandle<GameObject> handle)
|
||||
{
|
||||
if (handle.Status == AsyncOperationStatus.Succeeded)
|
||||
{
|
||||
Debug.Log($"Successfully instantiated GameObject with name '{handle.Result.name}'.");
|
||||
}
|
||||
}
|
||||
|
||||
void ReleaseUntrackedResources()
|
||||
{
|
||||
Addressables.Release(handleUntracked);
|
||||
}
|
||||
|
||||
// When ready to release the asset, call ReleaseUntrackedResources().
|
||||
// For example during OnDestroy().
|
||||
//void OnDestroy()
|
||||
//{
|
||||
// ReleaseUntrackedResources();
|
||||
//}
|
||||
#endregion
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue