void PlayerMoveHandler(Codecs cs, byte[] data) { MoveProto proto = cs.Decode <MoveProto>(data); if (proto.id == player.GetComponent <Player>().GetID()) { return; } string line = "[" + proto.id + "] move " + proto.x.ToString() + ", " + proto.z.ToString(); print(line); if (!_players.ContainsKey(proto.id)) { GameObject e = Instantiate(preplayer, new Vector3(proto.x, 0, proto.z), Quaternion.identity); e.GetComponent <Renderer>().material.color = RandomColor(); _players.Add(proto.id, e); Transform PlayerMapIconTransform = e.transform.GetChild(0); PlayerMapIconTransform.GetComponent <Renderer>().material.color = Color.red; } else { GameObject e = _players[proto.id]; Rigidbody rg = e.GetComponent <Rigidbody>(); rg.MovePosition(new Vector3(proto.x, 0, proto.z)); e.GetComponent <Player>().SetScore(proto.score); } }
public void Update() { int process_count = 0; byte[] bytes; while (process_count < _process_message_once) { process_count++; if (!_transport.Receive(out bytes)) { continue; } MessageProto proto = _codecs.Decode <MessageProto>(bytes); _events.Invoke(proto.type, _codecs, bytes); } }
void PlayerJoinHandler(Codecs cs, byte[] data) { JoinProto proto = cs.Decode <JoinProto>(data); string line = "[" + proto.id + "] join"; print(line); if (proto.id == player.GetComponent <Player>().GetID()) { _players.Add(proto.id, player); return; } GameObject e = Instantiate(preplayer, new Vector3(0, 0, 0), Quaternion.identity); e.GetComponent <Renderer>().material.color = RandomColor(); _players.Add(proto.id, e); Transform PlayerMapIconTransform = e.transform.GetChild(0); PlayerMapIconTransform.GetComponent <Renderer>().material.color = Color.red; }
void PlayerExitHandler(Codecs cs, byte[] data) { ExitProto proto = cs.Decode <ExitProto>(data); string line = "[" + proto.id + "] exit"; print(line); if (proto.id == player.GetComponent <Player>().GetID()) { return; } if (!_players.ContainsKey(proto.id)) { return; } GameObject e = _players[proto.id]; _players.Remove(proto.id); Destroy(e); }