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.
- Listed in Networking and servers
- Inherits or implements
NetworkEntityBehaviour,ISavable<ModifiableStaticManagerSaveData>,ISavableSave<ModifiableStaticManagerSaveData>,ISavableSaveBase - Derived types
ModifiableStaticManagerSaveData
Constructors
| Member | What it is |
|---|---|
ModifiableStaticManager() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
| Member | What it is |
|---|---|
static Dictionary<uint, GameObject> gameObjects | Scene objects by hash, filled by ModifiableStaticObject. |
static ModifiableStaticManager instance | The one manager in the scene. Extra copies destroy themselves. |
static Dictionary<uint, bool> objectMap | Modified state by object hash. Saved with the manager and cleared on game reload. |
protected static Logger logger | NLog logger for this class. |
2 private and internal fields
| Member | What it is |
|---|---|
private MethodSync sync | Method sync for the full map, sent to each player on connect. |
private MethodSyncStruct<ModificationArguments> syncModification | Method sync for single changes, sent by the server to chunks. |
Events
| Member | What it is |
|---|---|
static event StaticChangeEvent ObjectChanged | Raised with the hash and new state whenever an object's modified state changes, on either side. |
Methods
| Member | What 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
| Member | What 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. |