コード例 #1
0
        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);
                }
            }
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        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);
                }
            }
        }