using UnityEngine; namespace Cyber.Networking { /// /// An abstract syncer, used by and . /// public abstract class Syncer : MonoBehaviour { private int TickCounter = 0; private readonly float TickInterval; private float TimeSinceLastTick = 0; private int SyncPacketID = 0; /// /// Initializes the syncer, basically just sets the . /// /// public Syncer(float tickInterval) { TickInterval = tickInterval; TimeSinceLastTick = tickInterval; } /// /// Returns the next ID for a sync packet. /// /// public int NextSyncID() { return SyncPacketID++; } /// /// Performs a tick on the syncer, called from . /// /// The tick number, used to e.g. determine when to sync certain things. public abstract void PerformTick(int Tick); private void Update() { TimeSinceLastTick += Time.deltaTime; if (TimeSinceLastTick > TickInterval) { PerformTick(TickCounter); if (TickCounter < int.MaxValue) { TickCounter++; } else { TickCounter = 0; } TimeSinceLastTick -= TickInterval; } } } }