static void Sync(NetworkConnection conn, NetworkVehicleMessageBase networkState) { if (!NetworkServer.active) { if (networkState != null && networkState.VehicleSync != null && !networkState.VehicleSync.hasAuthorityOrUnownedOnServer) { networkState.VehicleSync.AddState(networkState.vehicleState); networkState.VehicleSync.CheckOwnerChange(networkState.vehicleState); } } else { if (networkState.VehicleSync == null || networkState.VehicleSync.netID.connectionToClient != conn) { return; } if (networkState.VehicleSync.latestValidatedState == null || networkState.VehicleSync.ValidateState(networkState.vehicleState, networkState.VehicleSync.latestValidatedState)) { networkState.VehicleSync.latestValidatedState = networkState.vehicleState; networkState.VehicleSync.latestValidatedState.receivedOnServerTimestamp = Time.realtimeSinceStartup; networkState.VehicleSync.SendStateToNonOwners(networkState); networkState.VehicleSync.AddState(networkState.vehicleState); networkState.VehicleSync.CheckOwnerChange(networkState.vehicleState); } } }
public void Awake() { int bufferSize = ((int)(sendRate * interpolationBackTime) + 1) * 2; stateBuffer = new VehicleState[Mathf.Max(bufferSize, 30)]; objectToSync = gameObject; netID = objectToSync.GetComponent <NetworkIdentity>(); tempState = new VehicleState(); sentState = new NetworkVehicleMessageBase(); }
void SendStateToNonOwners(NetworkVehicleMessageBase state) { foreach (var kv in netID.observers) { NetworkConnection conn = kv.Value; if (conn != null && conn != netID.connectionToClient && conn.GetType() == typeof(NetworkConnectionToClient) && conn.isReady) { conn.Send <NetworkVehicleMessageBase>(state, networkChannel); } } }