Skip to main content

ChildSyncableCollection<T, TThis, TSaveData, TElementSaveData>

An abstract class in Root.Township, the global namespace.

Base for a component that holds a list of small child elements (heat points, forged points, woodcut points, ghost snap slots) and syncs and saves them as one. Sends only changed children, or one value when all are the same.

Constructors​

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

Methods​

MemberWhat it is
override void Initialize()Sets up the sync messages and gives each child its entity, index and collection.
override void InitializeAsServer(SpawnData spawnData)Server: passes the spawn data on to every child.
void SerializeToStream(Stream stream, bool isWriteFull)Writes or reads all children to a stream, optionally as a full sync.
override void SyncChild(T child)Sends one child's state to the chunk's players, if the collection uses sync messages.
4 private and internal methods
MemberWhat it is
private void SyncAllChildren(IPlayer player, Stream stream)Sync handler for all children. In a full sync, sends one copy if every child is equal; otherwise sends each child that needs it.
private void SyncDifferent(IPlayer player, Stream stream)Writes or reads each child, with a flag per child for whether it changed unless it's a full sync.
private void SyncIndividual(IPlayer player, Stream stream, uint index)Sync handler for one child by index, sent by SyncChild.
private void SyncSame(IPlayer player, Stream stream)Syncs the first child only; on read, copies it to every other child.