Info
- Send a ScriptableObject over the network or into JSON as a string, then find the same asset on the other side
- Module
Polis.Core.AssetTranslation (Packages/PolisCore/AssetTranslation)
- A definition stores only its
UniqueID, without the kind. Addressable kinds get Address = Kind/ID (e.g. Avatar/Robot). The network, JSON, MemoryPack and lookups use the address
- Sent by address: avatars, scene setups, stage plays, visual IDs. Windows are addressable by address but not preloaded. App loader items use
AUniqueDefinition for a stable ID only
Usage
AUniqueDefinition - ScriptableObject base with a UniqueID
- The ID is filled from the file name when empty, without the type's suffix (
Robot for RobotAvatar). The pen button next to the field takes it from the file name again
- Override
FormatFileNameForID to change how
Address - read only, Kind/ID for addressable kinds, the ID otherwise
- Changing the ID in the inspector moves the Addressables address along
[AddressableEntry("Kind", suffixes...)] on the type - its assets are addressable as Kind/ID
Group (default Core, a remote group counts too) and Label are optional
[AddressablePrefab("Group")] on a prefab field: the prefab is addressable in that group as <Address>/Prefab
- Entries are not in the registry, e.g.
WindowDefinition
[AddressableDefinition("Kind", suffixes...)] - an addressable entry that also preloads at boot into DefinitionRegistry
AListedDefinition - base of the kinds lists show (avatars, scene setups, stage plays, forms)
- Enabled - off leaves it out of lists and defaults, saved references still resolve
- Availability - optional
ICondition, listed only while it holds (e.g. on XR or when logged in)
IsEnabled, Availability, IsAvailable, AvailabilityChanged. The condition is observed while anyone listens, once however many lists use it
DefinitionRegistry - preloaded definitions by address
- Preloaded at boot by
DefinitionsPreloader (Services category, after ReleaseContent), then resolved synchronously
- Only definitions whose bundles are built in or downloaded load. Definitions of content downloaded later join on
IDownloadedContent.ContentChanged. Ones an update changed load on the next start
TryGet<T>(address, out def), Get<T>, GetAll<T>, Contains(address), IsOnDevice(def)
Changed - after each preload and content change, also when content left the device
- In edit mode
TryGet and GetAll read the Addressables settings directly
- A request before the preload logs an error, depend on
DefinitionsPreloader
DefinitionList<T> - the preloaded definitions of one listed type that are on the device and available, sorted by ID
Items, Contains, Random(), Refresh(), Changed
- Kept current as content downloads or leaves and as conditions change, an unavailable one joins once its condition holds. Dispose it when done
DefinitionListController<TView, TDefinition> - base for list UIs, a view per definition of a DefinitionList
- Override
PopulatePrefab, optional count text
- A hidden list catches up once shown. Used by the avatar and scene setup lists
New definition type
- Inherit
AUniqueDefinition (AListedDefinition for kinds lists show) and add [AddressableDefinition("MyKind", "Definition")], plus [ManagementPanel] for its page in App Management
- Create the assets and apply the validator fix "Fix addressables" for address, group, label and prefab entries
- For PurrNet add packer extensions (see
AvatarDefinitionPackerExtensions)
- Reference prefabs, fonts and other heavy assets by address. A preloaded definition loads everything it references directly at boot
Example
[AddressableDefinition("MyKind", "Definition")]
public class MyDefinition : AUniqueDefinition { }
public static class MyDefinitionPackerExtensions
{
public static void Write(this BitPacker packer, MyDefinition value) => packer.CustomWriteTranslatedDefinition(value);
public static void Read(this BitPacker packer, ref MyDefinition value) => value = packer.CustomReadTranslatedDefinition<MyDefinition>();
}
// Available definitions, kept current
private DefinitionList<MyDefinition> _definitions;
private void Awake()
{
_definitions = new DefinitionList<MyDefinition>();
_definitions.Changed += Refresh;
}
private void OnDestroy() => _definitions.Dispose();