我需要通过TCP(通过网络通信)从服务器到客户端传输不同的元素(例如球体,立方体,夹具,dimplejacket ...)。
您认为,发送包含那些类的数据(即平均半径,长度,高度...)的消息而不必实现与元素类一样多的消息类的最佳方法是什么?
因为当前在我发送消息时,我发送的消息类型为“ Communicate”(这是我作为消息发送的班级) 我不想拥有CommunicateSphere,CommunicateCube等类,而是希望能够正确传达所有这些数据的CommunicateElement类
我想象过要传输“对象”类型,但显然“对象不包含GetPrimitiveType()的定义
/// <summary>
/// Performs whatever functions we might so desire when we receive an incoming ChatMessage
/// </summary>
/// <param name="header">The PacketHeader corresponding with the received object</param>
/// <param name="connection">The Connection from which this object was received</param>
/// <param name="incomingMessage">The incoming CommunicateElement we are after</param>
private void HandleIncomingObject(PacketHeader header, Connection connection, CommunicateElement incomingMessage)
{
PrimitiveType type = incomingMessage.Message.GetPrimitiveType();
GameObject go = GameObject.CreatePrimitive(type);
}
最后,我应该有一些按钮(或任何图形元素),它们可以将消息发送到统一位置(包含元素的数据)以创建指定的元素