Info
- Typed helpers on top of Unity Addressables
- Module
Polis.Core.AddressableAssets (Packages/PolisCore/AddressableAssets), needs the ADDRESSABLES define
- Reference assets by address, load them async, find assets by label or address, check what is on the device, queue downloads
Addressable content
- Most things outside RootScene are addressable. RootScene holds only
AppCore, the loader and the boot screen, the setup and its managers load from bundles, see App Loader
- Shared content lives in the content kit
Packages/PolisXrContentKit (cz.lics.polis.xr-content-kit) and never references the project. SharedContentBoundaryValidator reports kit assets that depend on Assets/_Projects/
- Addressable rules by type:
[AddressableEntry] / [AddressableDefinition] set the address (Kind/ID), group (or any remote group) and label, [AddressablePrefab] the prefab entry. The validator checks them and offers "Fix addressables", see Definitions
- Lists of definitions come from the registry (
DefinitionList<T>, see Definitions). App settings load by the Settings label (see Managers & Services). Other lists load by label (AddressablePrefabListController)
- Heavy prefabs go by address (window
_PrefabReference, avatar Prefab). Avatars spawn through PurrNet AddressableNetworkPrefabs (loaded on demand), small network props stay in NetworkPrefabs
- Check for duplicates after adding content: Polis/Content/Check Duplicate Bundle Assets lists assets that several groups use without one owning them, so each of their bundles gets a copy. Give them a group of their own
Usage
AssetAddressReference<T> - serializable reference by address string, the inspector shows an address picker and validates the type
LoadAsync() - returns the handle, the same one on repeated calls
Asset - the loaded asset when done
Release() - unloads it
Cast<T>() - same address as another type
- JSON converter and MemoryPack formatter included, so it can be saved or sent as an address
SceneAssetReference - AssetReference limited to scenes, used by SceneReference, see Scene Management
AddressablePrefabListController<TPrefab, TAsset> - spawns a display prefab per asset with its Asset Label, on Awake unless Populate On Awake is off
- Loads every asset with the label, downloadable ones too
- Override
PopulatePrefab
- Optional
OrderAssets
- Optional count text, shows a dash while loading
- Lists of definitions use
DefinitionListController instead
- Attributes on
AssetReference fields
AssetReferenceTypeRestriction(type) - limit to a type
AssetReferenceDynamicTypeRestriction(getter) - type from a getter
- Editor:
AddressablesEditorUtils
IsAddressable, AddToDefaultAddressableGroup
ConvertToReference, GetAssetByAddress, GetAddressableAssets<T>
Example
[SerializeField]
private AssetAddressReference<GameObject> _Prefab;
private async UniTask Spawn()
{
await _Prefab.LoadAsync().Task;
Instantiate(_Prefab.Asset);
}
private void OnDestroy() => _Prefab.Release();
Downloadable content