예제 #1
0
        public void SendRPC(NetAsset netAsset, string methodName, object[] args)
        {
            if (State == ServerState.Debug)
            {
                return;
            }
            if (State != ServerState.Started)
            {
                throw new InvalidOperationException($"Cannot send rpc {methodName}: Server not running");
            }

            var streamWriter = new DataStreamWriter(MaxBytesPerMessage, Allocator.Temp);

            streamWriter.WriteInt(Commands.NetAssetRPC);
            streamWriter.WriteFloat(Time);
            streamWriter.WriteInt(netAsset.NetID);
            netAsset.SerializeRPC(ref streamWriter, methodName, args);

            for (var i = 0; i < _connections.Length; i++)
            {
                DataStreamWriter writer = _serverDriver.BeginSend(_reliablePipeline, _connections[i]);
                writer.WriteBytes(streamWriter.AsNativeArray());
                _serverDriver.EndSend(writer);
            }
        }
예제 #2
0
파일: Client.cs 프로젝트: OJuergen/Netling
        public void SendRPC(NetAsset netAsset, string methodName, object[] args)
        {
            if (State == ClientState.Debug)
            {
                return;
            }
            if (State != ClientState.Connected)
            {
                throw new InvalidOperationException($"Cannot send rpc {methodName}: not connected");
            }

            DataStreamWriter streamWriter = _clientDriver.BeginSend(_reliablePipeline, _clientToServerConnection);

            streamWriter.WriteInt(Commands.NetAssetRPC);
            streamWriter.WriteFloat(Server.Time);
            streamWriter.WriteInt(netAsset.NetID);
            netAsset.SerializeRPC(ref streamWriter, methodName, args);
            _clientDriver.EndSend(streamWriter);
            DataSent?.Invoke(streamWriter.Length);
        }