public override void OnMatchData(INMatchData m) { base.OnMatchData(m); var content = Encoding.UTF8.GetString(m.Data); content = content.Trim(); // content = content.Substring (1, content.Length - 2); content = content.Replace(@"\", ""); switch (m.OpCode) { case OPCODE_CHAT: Enqueue(() => { onChatMessageReceived(m.Presence.Handle, content); }); break; case OPCODE_MOVE: TBSBaseGameMove move = JsonUtility.FromJson <TBSBaseGameMove> (content); Enqueue(() => { OnPlayerMoveReceived(move, content); // onPlayerMoveMade(move); }); break; default: Debug.LogFormat("User handle '{0}' sent '{1}' '21}'", m.Presence.Handle, m.OpCode, content); break; } ; }
private void OnPlayerMoveReceived(TBSBaseGameMove move, string rawMessage) { if (move.type == "unitMove") { // TODO: have to know whom is this from. TBSUnitGameMove m = JsonUtility.FromJson <TBSUnitGameMove> (rawMessage); cellGrid.MoveUnit(m.fromCell, m.toCell); } }
public void CommitMove(TBSBaseGameMove move) { string json = JsonUtility.ToJson(move); SendMatchMessage(OPCODE_MOVE, json); }