This is the code that receives raw data from other person and converts it. for right now it is supposed to add the object added from the other player to where the other player added it on the second players screen.
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);
}
}
}
This code sends out a message through google play services to the other player.
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);
}
and this game is like tic tac toe
For a simple game like Tic Tac Toe, I would recommend you communicate the game state in a much more basic level.
Assume you have the state of your game in a 3x3 char array. Each element of the array is either
Now whenever a player does their move, you update the client's local copy of the array. Then you can easily send this 3x3 array over the network. The receiving client can update their array accordingly, and so on.