public override void UpdateSeats(JSONObject jsonData) { JSONArray userList = jsonData.GetObject("gameRoom").GetArray("userGames"); users = new JSONObject(); for (int i = 0; i < userList.Length; i++) { users.Add(userList[i].Obj.GetInt("seatIndex").ToString(), userList[i].Obj); } // FAKE user joined for (int i = 0; i < 4; i++) { GameObject tempUser; PlayerSlotScript playerScript = playerHolder[i]; JSONObject user = users.ContainsKey(i.ToString()) ? users.GetObject(i.ToString()) : null; if (user != null) { playerScript.Init(user.GetString("userId"), "Dan Choi" + (i + 1), (i + 1) * 200000, string.Empty); } else { playerScript.InitEmpty(); } } }
public void OnPlayerJoinRoom(string roomId, JSONObject userData) { if (this.roomId == roomId) { PlayerSlotScript playerSlot = GetAvailableSlot(userData.GetString("username")); playerSlot.Init(userData.GetString("username"), userData.GetString("displayName"), userData.GetLong("cash"), userData.GetString("avatar")); } else { Debug.LogError("Not in this room " + this.roomId + " | " + roomId); } }
public override void Init(object[] data) { base.Init(data); EventDelegate.Set(btnBack.onClick, BackToSelectRoom); EventDelegate.Set(btnThrowCard.onClick, EventPlayCards); Debug.Log(data[1]); JSONObject roomData = (JSONObject)data[1]; JSONArray userList = roomData.GetObject("gameRoom").GetArray("userGames"); for (int i = 0; i < userList.Length; i++) { users.Add(userList[i].Obj.GetInt("seatIndex").ToString(), userList[i].Obj); } // FAKE user joined for (int i = 0; i < 4; i++) { GameObject tempUser; if (i < 2) { tempUser = NGUITools.AddChild(playerLeftGrid.gameObject, Resources.Load(Global.SCREEN_PATH + "/GameScreen/TienLenMN/PlayerSlot", typeof(GameObject)) as GameObject); } else { tempUser = NGUITools.AddChild(playerRightGrid.gameObject, Resources.Load(Global.SCREEN_PATH + "/GameScreen/TienLenMN/PlayerSlot", typeof(GameObject)) as GameObject); } tempUser.name = "PlayerSlot" + (i + 1); PlayerSlotScript playerScript = tempUser.GetComponent <PlayerSlotScript>(); JSONObject user = users.ContainsKey(i.ToString()) ? users.GetObject(i.ToString()) : null; if (user != null) { playerScript.Init(user.GetString("userId"), "Dan Choi" + (i + 1), (i + 1) * 200000, string.Empty); } else { playerScript.InitEmpty(); } playerHolder.Add(playerScript); } playerLeftGrid.Reposition(); playerRightGrid.Reposition(); // for (int i = 0; i < playerHolder.Count; i++) { // UIButton tempBtn = playerHolder[i].btnThrowCard; // tempBtn.inputParams = new object[] {playerHolder[i]}; // EventDelegate.Set(tempBtn.onClick, delegate() { PlayCardFromOther((PlayerSlotScript)tempBtn.inputParams[0]); }); // // Test Player turn circle display // StartCoroutine(DisplayPlayerTurn(i)); // } StartNewGame(); }