Skip to main content

LogicValueSender<TData>

An abstract class in Root.Township, Alta.Logic.

Base for logic components (switches, wires and similar) whose value lives in a shared logic data record held by a GlobalLogicManager, so linked parts see the same value. Server-side; saved through the record.

Constructors​

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

Fields​

2 private and internal fields
MemberWhat it is
private TData dataBacking field for Data; filled from the logic manager on first access or from the save on load.
private static Logger loggerNLog logger for this class.

Properties​

MemberWhat it is
TData Data { get; }The shared data record, fetched from the logic manager on first use.
sealed override Type DataType { get; }The save data type this sender uses.
override uint Identifier { get; }Id of the shared data record in the logic manager. 0 means none.

Methods​

MemberWhat it is
override void Clear()Drops the link to the data record.
override void EditorPreSave(GlobalLogicManager manager)Editor hook before saving. Empty here.
override void InitializeAsServer(SpawnData spawnData)Server: finds the logic manager (parent or global) and reads the current value if data exists.
protected virtual void OnValidate()Editor: links prefab instances to a data record, or clears the id on prefab assets.
protected abstract void ReadDataValue()Subclass: applies the record's value to the component. Also called when the record changes from elsewhere.
protected void UpdateDataValue()Writes the component's value into the record and notifies listeners.
protected abstract void WriteDataValue()Subclass: copies the component's value into the record.
2 private and internal methods
MemberWhat it is
private void SetupData()Hooks ReadDataValue to the data's ChangedExternally event and Unsubscribe to the entity's scene destroy. Called on load.
private void Unsubscribe(NetworkEntity entity, bool isUnload)Removes the ChangedExternally listener when the entity is destroyed by the scene.