Skip to main content

AddressableSession

A class in Root.Township, the global namespace.

Loads Unity Addressable assets and keeps them loaded until every user of the session is removed, then releases them all.

Constructors​

MemberWhat it is
AddressableSession()Creates an AddressableSession with default values.

Fields​

8 private and internal fields
MemberWhat it is
private static int countNumber of live sessions. Drops when a session's last user is removed.
private readonly Dictionary<string, AsyncOperationHandle> handleMapLoad handles by address, so loading the same address twice reuses the handle.
private readonly HashSet<AsyncOperationHandle> handlesEvery load handle this session made, released when its last user goes.
private readonly int indexThis session's number, used in log messages.
private bool isDisposedSet once the last user is removed. Loading after that throws.
private static readonly Logger loggerNLog logger. Logs loads that finish after the session ended.
private static int nextNext session number to hand out.
private readonly HashSet<object> usersObjects keeping the session alive. Starts with the session itself, which Dispose removes.

Methods​

MemberWhat it is
void AddUser(object user)Registers something that still needs the loaded assets.
void Dispose()Removes the session itself as a user.
async Task<T> LoadAsync<T>(string address)Loads an asset by address, reusing the handle if already loaded. Throws once the session has ended.
void RemoveUser(object user)Removes a user. When none are left, releases every asset and ends the session.

Used in​

Members of other types that take, return or hold a AddressableSession: