Skip to main content

PerPlayerManager<TThis, TContent, TSaveFormat>

A class in Root.Township, the global namespace.

Base for server singletons that load, cache and save one content object per player from that player's data file. Get one with the static Instance.

Constructors​

MemberWhat it is
PerPlayerManager()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

3 private and internal fields
MemberWhat it is
private Dictionary<int, TContent> contentsLoaded content by player user ID.
private Dictionary<int, Task> getContentTasksIn-progress loads by player user ID, so repeated requests wait for the same load.
private static Logger loggerNLog logger for this class.

Properties​

MemberWhat it is
static TThis Instance { get; private set; }The single instance. A second copy destroys itself in Awake.

Methods​

MemberWhat it is
virtual async Task<TContent> GetContentAsync(IPlayer player)Returns the player's content, loading it from their player data file first if needed. Waits on any load already in progress.
async Task<TContent> GetContentAsync(int playerIdentifier, Player player = null, bool isCreatingNew = true)Returns the player's content, loading it from their player data file first if needed. Waits on any load already in progress.
TContent GetContentIfLoaded(Player player)Returns the player's content only if it is already in memory, otherwise null. Does not load anything.
TContent GetContentIfLoaded(int playerID)Returns the player's content only if it is already in memory, otherwise null. Does not load anything.
override void InitializeAsServer(SpawnData spawnData)Server: registers the manager for autosave, which saves every loaded player's content.
override async void OnConnected(Player player)Server: starts loading the joining player's content.
override void OnDisconnected(Player player)Server: saves the leaving player's content and drops it from the cache.
2 private and internal methods
MemberWhat it is
private void IAutoSave.AutoSave()Saves every loaded player's content without unloading it. Called by the streamer's auto save.
private void Awake()Sets Instance, destroying itself if another instance exists.