SendWriter functions removed to avoid redundancy with SendBytes. Simply call SendBytes(writer.ToArray()) instead.

This commit is contained in:
vis2k 2018-07-20 12:42:39 +02:00
parent 2e9dc82e0e
commit fc4080535b
9 changed files with 9 additions and 54 deletions

View File

@ -32,12 +32,6 @@ public override bool SendBytes(byte[] bytes, int channelId)
m_LocalClient.InvokeBytesOnClient(bytes, channelId); m_LocalClient.InvokeBytesOnClient(bytes, channelId);
return true; return true;
} }
public override bool SendWriter(NetworkWriter writer, int channelId)
{
m_LocalClient.InvokeBytesOnClient(writer.ToArray(), channelId);
return true;
}
} }
// a localClient's connection TO a server. // a localClient's connection TO a server.
@ -67,12 +61,6 @@ public override bool SendBytes(byte[] bytes, int channelId)
} }
return NetworkServer.InvokeBytes(this, bytes, channelId); return NetworkServer.InvokeBytes(this, bytes, channelId);
} }
public override bool SendWriter(NetworkWriter writer, int channelId)
{
// write relevant data, which is until .Position
return NetworkServer.InvokeBytes(this, writer.ToArray(), channelId);
}
} }
} }
#endif //ENABLE_UNET #endif //ENABLE_UNET

View File

@ -68,7 +68,7 @@ protected void SendCommandInternal(NetworkWriter writer, int channelId, string c
} }
writer.FinishMessage(); writer.FinishMessage();
ClientScene.readyConnection.SendWriter(writer, channelId); ClientScene.readyConnection.SendBytes(writer.ToArray(), channelId);
#if UNITY_EDITOR #if UNITY_EDITOR
UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.IncrementStat(
@ -96,7 +96,7 @@ protected void SendRPCInternal(NetworkWriter writer, int channelId, string rpcNa
} }
writer.FinishMessage(); writer.FinishMessage();
NetworkServer.SendWriterToReady(gameObject, writer, channelId); NetworkServer.SendBytesToReady(gameObject, writer.ToArray(), channelId);
#if UNITY_EDITOR #if UNITY_EDITOR
UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.IncrementStat(
@ -117,7 +117,7 @@ protected void SendTargetRPCInternal(NetworkConnection conn, NetworkWriter write
writer.FinishMessage(); writer.FinishMessage();
conn.SendWriter(writer, channelId); conn.SendBytes(writer.ToArray(), channelId);
#if UNITY_EDITOR #if UNITY_EDITOR
UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.IncrementStat(
@ -144,7 +144,7 @@ protected void SendEventInternal(NetworkWriter writer, int channelId, string eve
} }
writer.FinishMessage(); writer.FinishMessage();
NetworkServer.SendWriterToReady(gameObject, writer, channelId); NetworkServer.SendBytesToReady(gameObject, writer.ToArray(), channelId);
#if UNITY_EDITOR #if UNITY_EDITOR
UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.IncrementStat(

View File

@ -302,21 +302,6 @@ public virtual void Disconnect()
} }
} }
public bool SendWriter(NetworkWriter writer, int channelId)
{
if (m_Connection != null)
{
if (m_AsyncConnect != ConnectState.Connected)
{
if (LogFilter.logError) { Debug.LogError("NetworkClient SendWriter when not connected to a server"); }
return false;
}
return m_Connection.SendWriter(writer, channelId);
}
if (LogFilter.logError) { Debug.LogError("NetworkClient SendWriter with no connection"); }
return false;
}
public bool SendBytes(byte[] data, int channelId) public bool SendBytes(byte[] data, int channelId)
{ {
if (m_Connection != null) if (m_Connection != null)

View File

@ -183,7 +183,7 @@ public virtual bool SendByChannel(short msgType, MessageBase msg, int channelId)
writer.StartMessage(msgType); writer.StartMessage(msgType);
msg.Serialize(writer); msg.Serialize(writer);
writer.FinishMessage(); writer.FinishMessage();
return SendWriter(writer, channelId); return SendBytes(writer.ToArray(), channelId);
} }
public virtual bool Send(short msgType, MessageBase msg) { return SendByChannel(msgType, msg, Channels.DefaultReliable); } public virtual bool Send(short msgType, MessageBase msg) { return SendByChannel(msgType, msg, Channels.DefaultReliable); }
public virtual bool SendUnreliable(short msgType, MessageBase msg) { return SendByChannel(msgType, msg, Channels.DefaultUnreliable); } public virtual bool SendUnreliable(short msgType, MessageBase msg) { return SendByChannel(msgType, msg, Channels.DefaultUnreliable); }
@ -217,12 +217,6 @@ public virtual bool SendBytes(byte[] bytes, int channelId)
return TransportSend(bytes, channelId, out error); return TransportSend(bytes, channelId, out error);
} }
public virtual bool SendWriter(NetworkWriter writer, int channelId)
{
// write relevant data, which is until .Position
return SendBytes(writer.ToArray(), channelId);
}
void LogSend(byte[] bytes) void LogSend(byte[] bytes)
{ {
NetworkReader reader = new NetworkReader(bytes); NetworkReader reader = new NetworkReader(bytes);

View File

@ -732,7 +732,7 @@ internal void UNetUpdate()
} }
writer.FinishMessage(); writer.FinishMessage();
NetworkServer.SendWriterToReady(gameObject, writer, channelId); NetworkServer.SendBytesToReady(gameObject, writer.ToArray(), channelId);
} }
} }
} }

View File

@ -283,18 +283,6 @@ static bool SendToObservers(GameObject contextObj, short msgType, MessageBase ms
return false; return false;
} }
// End users should not send random bytes
// because the other side might interpret them as messages
static internal void SendWriterToReady(GameObject contextObj, NetworkWriter writer, int channelId)
{
if (writer.Position > UInt16.MaxValue)
{
throw new UnityException("NetworkWriter used buffer is too big!");
}
// send relevant data, which is until .Position
SendBytesToReady(contextObj, writer.ToArray(), channelId);
}
// End users should not send random bytes // End users should not send random bytes
// because the other side might interpret them as messages // because the other side might interpret them as messages
static internal void SendBytesToReady(GameObject contextObj, byte[] buffer, int channelId) static internal void SendBytesToReady(GameObject contextObj, byte[] buffer, int channelId)

View File

@ -400,7 +400,7 @@ void SendTransform()
UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing, UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing,
(short)MsgType.LocalChildTransform, "16:LocalChildTransform", 1); (short)MsgType.LocalChildTransform, "16:LocalChildTransform", 1);
#endif #endif
ClientScene.readyConnection.SendWriter(writer, GetNetworkChannel()); ClientScene.readyConnection.SendBytes(writer.ToArray(), GetNetworkChannel());
} }
static internal void HandleChildTransform(NetworkMessage netMsg) static internal void HandleChildTransform(NetworkMessage netMsg)

View File

@ -1238,7 +1238,7 @@ void SendTransform()
UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing, UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing,
(short)MsgType.LocalPlayerTransform, "6:LocalPlayerTransform", 1); (short)MsgType.LocalPlayerTransform, "6:LocalPlayerTransform", 1);
#endif #endif
ClientScene.readyConnection.SendWriter(writer, GetNetworkChannel()); ClientScene.readyConnection.SendBytes(writer.ToArray(), GetNetworkChannel());
} }
static public void HandleTransform(NetworkMessage netMsg) static public void HandleTransform(NetworkMessage netMsg)

View File

@ -258,7 +258,7 @@ void SendMsg(Operation op, int itemIndex, T item)
SerializeItem(writer, item); SerializeItem(writer, item);
writer.FinishMessage(); writer.FinishMessage();
NetworkServer.SendWriterToReady(uv.gameObject, writer, m_Behaviour.GetNetworkChannel()); NetworkServer.SendBytesToReady(uv.gameObject, writer.ToArray(), m_Behaviour.GetNetworkChannel());
#if UNITY_EDITOR #if UNITY_EDITOR
UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.IncrementStat(