diff --git a/MLAPI/MonoBehaviours/Core/NetworkedBehaviour.cs b/MLAPI/MonoBehaviours/Core/NetworkedBehaviour.cs index 346f61a..deb4af8 100644 --- a/MLAPI/MonoBehaviours/Core/NetworkedBehaviour.cs +++ b/MLAPI/MonoBehaviours/Core/NetworkedBehaviour.cs @@ -685,6 +685,18 @@ namespace MLAPI.MonoBehaviours.Core NetworkingManager.singleton.Send(NetworkingManager.singleton.serverClientId, messageType, channelName, data); } + /// + /// Sends a binary serialized class to the server from client + /// + /// The class type to send + /// User defined messageType + /// User defined channelName + /// The instance to send + protected void SendToServer(string messageType, string channelName, T instance) + { + SendToServer(messageType, channelName, BinarySerializer.Serialize(instance)); + } + /// /// Sends a buffer to the server from client. Only handlers on this NetworkedBehaviour will get invoked /// @@ -706,6 +718,18 @@ namespace MLAPI.MonoBehaviours.Core NetworkingManager.singleton.Send(NetworkingManager.singleton.serverClientId, messageType, channelName, data, networkId, networkedObject.GetOrderIndex(this)); } + /// + /// Sends a binary serialized class to the server from client. Only handlers on this NetworkedBehaviour will get invoked + /// + /// The class type to send + /// User defined messageType + /// User defined channelName + /// The instance to send + protected void SendToServerTarget(string messageType, string channelName, T instance) + { + SendToServerTarget(messageType, channelName, BinarySerializer.Serialize(instance)); + } + /// /// Sends a buffer to the server from client /// @@ -727,6 +751,18 @@ namespace MLAPI.MonoBehaviours.Core NetworkingManager.singleton.Send(ownerClientId, messageType, channelName, data); } + /// + /// Sends a binary serialized class to the server from client + /// + /// The class type to send + /// User defined messageType + /// User defined channelName + /// The instance to send + protected void SendToLocalClient(string messageType, string channelName, T instance) + { + SendToLocalClient(messageType, channelName, BinarySerializer.Serialize(instance)); + } + /// /// Sends a buffer to the client that owns this object from the server. Only handlers on this NetworkedBehaviour will get invoked /// @@ -748,6 +784,18 @@ namespace MLAPI.MonoBehaviours.Core NetworkingManager.singleton.Send(ownerClientId, messageType, channelName, data, networkId, networkedObject.GetOrderIndex(this)); } + /// + /// Sends a buffer to the client that owns this object from the server. Only handlers on this NetworkedBehaviour will get invoked + /// + /// The class type to send + /// User defined messageType + /// User defined channelName + /// The instance to send + protected void SendToLocalClientTarget(string messageType, string channelName, T instance) + { + SendToLocalClientTarget(messageType, channelName, BinarySerializer.Serialize(instance)); + } + /// /// Sends a buffer to all clients except to the owner object from the server /// @@ -769,6 +817,18 @@ namespace MLAPI.MonoBehaviours.Core NetworkingManager.singleton.Send(messageType, channelName, data, ownerClientId); } + /// + /// Sends a binary serialized class to all clients except to the owner object from the server + /// + /// The class type to send + /// User defined messageType + /// User defined channelName + /// The instance to send + protected void SendToNonLocalClients(string messageType, string channelName, T instance) + { + SendToNonLocalClients(messageType, channelName, BinarySerializer.Serialize(instance)); + } + /// /// Sends a buffer to all clients except to the owner object from the server. Only handlers on this NetworkedBehaviour will get invoked /// @@ -790,6 +850,18 @@ namespace MLAPI.MonoBehaviours.Core NetworkingManager.singleton.Send(messageType, channelName, data, ownerClientId, networkId, networkedObject.GetOrderIndex(this)); } + /// + /// Sends a binary serialized class to all clients except to the owner object from the server. Only handlers on this NetworkedBehaviour will get invoked + /// + /// The class type to send + /// User defined messageType + /// User defined channelName + /// The instance to send + protected void SendToNonLocalClientsTarget(string messageType, string channelName, T instance) + { + SendToNonLocalClientsTarget(messageType, channelName, BinarySerializer.Serialize(instance)); + } + /// /// Sends a buffer to a client with a given clientId from Server /// @@ -812,6 +884,19 @@ namespace MLAPI.MonoBehaviours.Core NetworkingManager.singleton.Send(clientId, messageType, channelName, data); } + /// + /// Sends a binary serialized class to a client with a given clientId from Server + /// + /// The class type to send + /// The clientId to send the message to + /// User defined messageType + /// User defined channelName + /// The instance to send + protected void SendToClient(int clientId, string messageType, string channelName, T instance) + { + SendToClient(clientId, messageType, channelName, BinarySerializer.Serialize(instance)); + } + /// /// Sends a buffer to a client with a given clientId from Server. Only handlers on this NetworkedBehaviour gets invoked /// @@ -834,6 +919,19 @@ namespace MLAPI.MonoBehaviours.Core NetworkingManager.singleton.Send(clientId, messageType, channelName, data, networkId, networkedObject.GetOrderIndex(this)); } + /// + /// Sends a buffer to a client with a given clientId from Server. Only handlers on this NetworkedBehaviour gets invoked + /// + /// The class type to send + /// The clientId to send the message to + /// User defined messageType + /// User defined channelName + /// The instance to send + protected void SendToClientTarget(int clientId, string messageType, string channelName, T instance) + { + SendToClientTarget(clientId, messageType, channelName, BinarySerializer.Serialize(instance)); + } + /// /// Sends a buffer to multiple clients from the server /// @@ -856,6 +954,19 @@ namespace MLAPI.MonoBehaviours.Core NetworkingManager.singleton.Send(clientIds, messageType, channelName, data); } + /// + /// Sends a binary serialized class to multiple clients from the server + /// + /// The class type to send + /// The clientId's to send to + /// User defined messageType + /// User defined channelName + /// The instance to send + protected void SendToClients(int[] clientIds, string messageType, string channelName, T instance) + { + SendToClients(clientIds, messageType, channelName, BinarySerializer.Serialize(instance)); + } + /// /// Sends a buffer to multiple clients from the server. Only handlers on this NetworkedBehaviour gets invoked /// @@ -878,6 +989,19 @@ namespace MLAPI.MonoBehaviours.Core NetworkingManager.singleton.Send(clientIds, messageType, channelName, data, networkId, networkedObject.GetOrderIndex(this)); } + /// + /// Sends a buffer to multiple clients from the server. Only handlers on this NetworkedBehaviour gets invoked + /// + /// The class type to send + /// The clientId's to send to + /// User defined messageType + /// User defined channelName + /// The instance to send + protected void SendToClientsTarget(int[] clientIds, string messageType, string channelName, T instance) + { + SendToClientsTarget(clientIds, messageType, channelName, BinarySerializer.Serialize(instance)); + } + /// /// Sends a buffer to multiple clients from the server /// @@ -900,6 +1024,19 @@ namespace MLAPI.MonoBehaviours.Core NetworkingManager.singleton.Send(clientIds, messageType, channelName, data); } + /// + /// Sends a binary serialized class to multiple clients from the server + /// + /// The class type to send + /// The clientId's to send to + /// User defined messageType + /// User defined channelName + /// The instance to send + protected void SendToClients(List clientIds, string messageType, string channelName, T instance) + { + SendToClients(clientIds, messageType, channelName, BinarySerializer.Serialize(instance)); + } + /// /// Sends a buffer to multiple clients from the server. Only handlers on this NetworkedBehaviour gets invoked /// @@ -922,6 +1059,11 @@ namespace MLAPI.MonoBehaviours.Core NetworkingManager.singleton.Send(clientIds, messageType, channelName, data, networkId, networkedObject.GetOrderIndex(this)); } + protected void SendToClientsTarget(List clientIds, string messageType, string channelName, T instance) + { + SendToClientsTarget(clientIds, messageType, channelName, BinarySerializer.Serialize(instance)); + } + /// /// Sends a buffer to all clients from the server /// @@ -943,6 +1085,18 @@ namespace MLAPI.MonoBehaviours.Core NetworkingManager.singleton.Send(messageType, channelName, data); } + /// + /// Sends a buffer to all clients from the server + /// + /// The class type to send + /// User defined messageType + /// User defined channelName + /// The instance to send + protected void SendToClients(string messageType, string channelName, T instance) + { + SendToClients(messageType, channelName, BinarySerializer.Serialize(instance)); + } + /// /// Sends a buffer to all clients from the server. Only handlers on this NetworkedBehaviour will get invoked /// @@ -963,6 +1117,18 @@ namespace MLAPI.MonoBehaviours.Core } NetworkingManager.singleton.Send(messageType, channelName, data, networkId, networkedObject.GetOrderIndex(this)); } + + /// + /// Sends a buffer to all clients from the server. Only handlers on this NetworkedBehaviour will get invoked + /// + /// The class type to send + /// User defined messageType + /// User defined channelName + /// The instance to send + protected void SendToClientsTarget(string messageType, string channelName, T instance) + { + SendToClientsTarget(messageType, channelName, BinarySerializer.Serialize(instance)); + } #endregion /// diff --git a/MLAPI/NetworkingManagerComponents/BinarySerializer.cs b/MLAPI/NetworkingManagerComponents/BinarySerializer.cs index bac09a9..afd0135 100644 --- a/MLAPI/NetworkingManagerComponents/BinarySerializer.cs +++ b/MLAPI/NetworkingManagerComponents/BinarySerializer.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Reflection; using System.Text; +using UnityEngine; namespace MLAPI.NetworkingManagerComponents {