Skip to main content

GlobalLogicManager

A class in Root.Township, Alta.Logic.

Holds the shared data records for logic components (switches, wires and so on), keyed by id, and saves them. One is the global manager; others can act as a saving context for a group of components.

Constructors​

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

Fields​

7 private and internal fields
MemberWhat it is
private static Stack<GlobalLogicManager> contextStackStatic stack of managers pushed as saving contexts. Its top is Current, or Global when empty.
private Dictionary<uint, ILogicValueData> dataMapLogic value data by identifier. Filled by GetData and replaced on load, saved in full.
private NonHashedData defaultSetDataSaved data loaded into the entity on server start when nothing has been loaded yet.
private static GlobalLogicManager instanceBacking field for Global.
private bool isGlobalWhether this manager registers itself as Global in Awake. Defaults to true.
private static Logger loggerNLog logger for this class.
private uint nextIdNext identifier GetData hands out to data that has none. Saved, and only raised on load.

Properties​

MemberWhat it is
static GlobalLogicManager Current { get; }The manager on top of the saving context stack, or the global one if the stack is empty.
static GlobalLogicManager Global { get; }The manager marked as global, set when it wakes.

Methods​

MemberWhat it is
TData GetData<TData>(ref uint identifier)Gets a record by id. The generic form assigns a new id if 0 and creates missing records; the plain form returns null.
ILogicValueData GetData(uint identifier)Gets a record by id. The generic form assigns a new id if 0 and creates missing records; the plain form returns null.
override void InitializeAsServer(SpawnData spawnData)Server: loads the default data set into its entity if it has no records yet.
void Restore<TData>(ref TData saveData)On load: keeps the existing record for an id if there is one, otherwise stores the loaded one.
3 private and internal methods
MemberWhat it is
private void Awake()Registers this manager as Global when isGlobal is set.
private void ISavingContext.PopContext()Explicit ISavingContext method: pops this manager off the context stack, logging an error if it wasn't on top.
private void ISavingContext.PushContext()Explicit ISavingContext method: pushes this manager so it becomes Current while its children load or save.

Used in​

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