Skip to main content

ModifiableStaticManager

A class in Root.Township, Alta.Networking.

Tracks which static (baked) scene objects have been modified, such as buildings finished by a RepairBox, by hash. A single instance on the server saves and syncs the map to every client.

Constructors​

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

Fields​

MemberWhat it is
static Dictionary<uint, GameObject> gameObjectsScene objects by hash, filled by ModifiableStaticObject.
static ModifiableStaticManager instanceThe one manager in the scene. Extra copies destroy themselves.
static Dictionary<uint, bool> objectMapModified state by object hash. Saved with the manager and cleared on game reload.
protected static Logger loggerNLog logger for this class.
2 private and internal fields
MemberWhat it is
private MethodSync syncMethod sync for the full map, sent to each player on connect.
private MethodSyncStruct<ModificationArguments> syncModificationMethod sync for single changes, sent by the server to chunks.

Events​

MemberWhat it is
static event StaticChangeEvent ObjectChangedRaised with the hash and new state whenever an object's modified state changes, on either side.

Methods​

MemberWhat it is
static void ChangeModifications(uint objectHash, bool isModified)Sets an object's modified state. If it changed, raises ObjectChanged, and the server syncs it to clients.
static void CleanObject(uint hash)Forgets the scene object registered for a hash.
static bool GetObject(uint hash, out GameObject gameObject)Finds the scene object registered for a hash.
static void GetState(uint objectHash, ref bool isModified)Reads whether an object is modified. Leaves false for unknown hashes.
override void Initialize()Sets up the full sync and the single-change sync.
override void OnConnected(Player player)Sends the full modified map to a joining player.
static void SetObject(uint hash, GameObject gameObject)Registers the scene object for a hash. Called by ModifiableStaticObject.
5 private and internal methods
MemberWhat it is
private void Awake()Makes this the single instance and clears state on game reload; destroys duplicates.
private void OnDestroy()Clears the modified objects map.
private void ReloadClean()Clears the modified objects map on game reload.
private void Sync(IPlayer player, Stream stream)Writes the whole modified objects map, or on clients reads it and raises ObjectChanged for each entry.
private void SyncModification(IPlayer player, Stream stream, ModificationArguments args)Sends or receives one object's modified flag; clients apply it through ChangeModifications.