public void msg_recieved(SPServerMessage msg) { foreach(SPBulletObject b in msg._bullets) { if (b._playerid == PlayerInfo._id) continue; if (!_enemy_bullets.ContainsKey(b.unique_key())) { GameObject bullet_object = (GameObject)Instantiate(Resources.Load("bullet")); bullet_object.transform.parent = gameObject.transform; bullet_object.AddComponent<Bullet>(); Bullet neu_bullet = bullet_object.GetComponent<Bullet>(); neu_bullet.start(new Vector3(b._pos._x,b._pos._y,b._pos._z),new Vector3(b._vel._x,b._vel._y,b._vel._z),bullet_object,b._id,b._playerid); _enemy_bullets[b.unique_key()] = neu_bullet; } Bullet tar = _enemy_bullets[b.unique_key()]; tar._position.x = b._pos._x; tar._position.y = b._pos._y; tar._position.z = b._pos._z; tar._vel.x = b._vel._x; tar._vel.y = b._vel._y; tar._vel.z = b._vel._z; tar.__ct = 25; } }
public void msg_recieved(SPServerMessage msg) { foreach(SPPlayerObject obj in msg._players) { if (obj._id == PlayerInfo._id) continue; if (!_id_to_onlineplayer.ContainsKey(obj._id)) { GameObject player_gameobj = (GameObject)Instantiate(Resources.Load("onlineplayer")); player_gameobj.AddComponent<OnlinePlayer>(); _id_to_onlineplayer[obj._id] = player_gameobj.GetComponent<OnlinePlayer>(); _id_to_onlineplayer[obj._id].init(); } _id_to_onlineplayer[obj._id].msg_recieved(obj); } }
public static SPServerMessage from_json(JSONObject jso) { SPServerMessage rtv = new SPServerMessage(); JSONArray players = jso.GetArray(SN.PLAYERS); foreach(JSONValue v in players) { rtv._players.Add(SPPlayerObject.from_json(v.Obj)); } JSONArray bullets = jso.GetArray(SN.BULLETS); foreach(JSONValue v in bullets) { rtv._bullets.Add(SPBulletObject.from_json(v.Obj)); } JSONArray events = jso.GetArray(SN.EVENTS); foreach(JSONValue v in events) { rtv._events.Add(SPEvent.from_json(v.Obj)); } return rtv; }
void update_msg_send() { SPServerMessage msg = new SPServerMessage(); foreach(int id in _id_to_players.Keys) { msg._players.Add(_id_to_players[id]); } foreach(string bullet_key in _key_to_bullets.Keys) { msg._bullets.Add(_key_to_bullets[bullet_key]); } foreach(SPEvent evt in _events) { msg._events.Add(evt); } lock (_msg_send_lock) { _cached_msg_send = msg.to_json().ToString(); } }