本文整理汇总了C#中Lidgren.Network.NetIncomingMessage.ReadAllFields方法的典型用法代码示例。如果您正苦于以下问题:C# NetIncomingMessage.ReadAllFields方法的具体用法?C# NetIncomingMessage.ReadAllFields怎么用?C# NetIncomingMessage.ReadAllFields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lidgren.Network.NetIncomingMessage
的用法示例。
在下文中一共展示了NetIncomingMessage.ReadAllFields方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleSeverMessage
void HandleSeverMessage(NetIncomingMessage msg)
{
MessageFunction type = (MessageFunction)msg.ReadInt32();
switch (type)
{
case MessageFunction.ClassMessage:
SendTo sendTo = (SendTo)msg.ReadInt32();
string assemblyName = msg.ReadString();
string classType = msg.ReadString();
Message report = (Message)Activator.CreateInstance(assemblyName, classType).Unwrap();
msg.ReadAllFields(report);
SendNetworkMessage(report, sendTo, msg);
break;
case MessageFunction.SpawnPlayer:
// broadcast this to all connections, except sender
List<NetConnection> all2 = m_server.Connections; // get copy
all2.Remove(msg.SenderConnection);
int id2 = msg.ReadInt32();
string playerName = msg.ReadString();
if (all2.Count > 0)
{
NetOutgoingMessage om = m_server.CreateMessage();
om.Write((int)MessageFunction.SpawnPlayer);
om.Write(id2);
om.Write(playerName);
m_server.SendMessage(om, all2, NetDeliveryMethod.ReliableUnordered, 0);
}
SpawnPlayer(id2, playerName, msg.SenderConnection);
break;
default:
Debug.LogWarning("Unhandled msg type: " + type.ToString());
break;
}
}
示例2: HandleClientMessage
void HandleClientMessage(NetIncomingMessage msg)
{
MessageFunction type = (MessageFunction)msg.ReadInt32();
switch (type)
{
case MessageFunction.ClassMessage:
string assemblyName = msg.ReadString();
string classType = msg.ReadString();
Message report = (Message)Activator.CreateInstance(assemblyName, classType).Unwrap();
msg.ReadAllFields(report);
report.OnCalled(report, msg);
break;
case MessageFunction.SpawnAllPlayer:
int count = msg.ReadInt32();
for (int i = 0; i < count; i++)
{
int id = msg.ReadInt32();
string playerName = msg.ReadString();
SpawnPlayer(id, playerName);
}
int newId = SpawnLocalPlayer();
MessageSpawnPlayer spawnMessage = new MessageSpawnPlayer();
spawnMessage.playerId = newId;
spawnMessage.playerName = Steam.personaName;
SendNetworkMessage(spawnMessage, SendTo.Others);
break;
case MessageFunction.UpdateVehiclesPositions:
m_vNetworkManager.UpdateCarsPositions(msg);
break;
case MessageFunction.RemoveVehicle:
int carID2 = msg.ReadInt32();
m_vNetworkManager.RemoveCar(carID2);
break;
case MessageFunction.UpdateCitizensPositions:
m_cNetworkManager.UpdateCitizensPositions(msg);
break;
default:
Debug.LogWarning("Unhandled msg type: " + type.ToString());
break;
}
}