Unity3d 如何通过点对点连接传递有关游戏对象在unity中的父对象的数据?
这是从其他人接收原始数据并进行转换的代码。现在,它应该将从另一个玩家添加的对象添加到另一个玩家在第二个玩家屏幕上添加它的位置Unity3d 如何通过点对点连接传递有关游戏对象在unity中的父对象的数据?,unity3d,unity5,p2p,gameobject,parents,Unity3d,Unity5,P2p,Gameobject,Parents,这是从其他人接收原始数据并进行转换的代码。现在,它应该将从另一个玩家添加的对象添加到另一个玩家在第二个玩家屏幕上添加它的位置 public void OnRealTimeMessageReceived(bool isReliable, string senderId, byte[] data) { byte messageVersion = (byte)data[0]; // Let's figure out what type of message this is. c
public void OnRealTimeMessageReceived(bool isReliable, string senderId, byte[] data)
{
byte messageVersion = (byte)data[0];
// Let's figure out what type of message this is.
char messageType = (char)data[1];
if (messageType == 'U' && data.Length == _updateMessageLength)
{
float posX = System.BitConverter.ToSingle(data, 2);
float posY = System.BitConverter.ToSingle(data, 6);
// We'd better tell our GameController about this.
if (updateListener != null)
{
updateListener.UpdateReceived(senderId, posX, posY);
}
}
}
此代码通过google play服务向其他玩家发送消息
public void SendMyUpdate(GameObject childObj)
{
_updateMessage.Clear();
_updateMessage.Add(_protocolVersion);
_updateMessage.Add((byte)'U');
_updateMessage.AddRange(System.BitConverter.GetBytes(childObj));
byte[] messageToSend = _updateMessage.ToArray();
PlayGamesPlatform.Instance.RealTime.SendMessageToAll(false, messageToSend);
}
这个游戏就像tic-tac-toe一样对于像tic-tac-toe这样的简单游戏,我建议你在更基本的层面上交流游戏状态 假设游戏状态为3x3字符数组。数组的每个元素都是
' '
'X'
'O'
现在,每当玩家移动时,您都会更新客户端的阵列本地副本。然后,您可以通过网络轻松发送此3x3阵列。接收客户端可以相应地更新它们的数组,依此类推。我决定将浮动发送给另一个播放器,但数据似乎仍然无法使其生效,调试似乎都没有触发。我用的是adb logcat