Beispiel #1
0
 public override void responseString(bool isSuccess, string identifier, string json)
 {
     if (isSuccess)
     {
         if (identifier.Equals(Common.IDENTIFIER_GAME_ROOM_LIST))
         {
             ResponseRoomList res = JsonUtility.FromJson <ResponseRoomList>(json);
             roomDataList = res.list;
             current      = res.current;
             maxCount     = res.max;
             isUpdateList = true;
         }
         else if (identifier.Equals(Common.IDENTIFIER_CONNECT_ROOM))
         {
             ResponseConnectionRoom res = JsonUtility.FromJson <ResponseConnectionRoom>(json);
             StateManager.Instance().changeState(GAME_STATE.WAITING_ROOM, res);
         }
     }
     else
     {
         ResponseBase res = JsonUtility.FromJson <ResponseBase>(json);
         showAlert("error", res.message, false, false, (AlertData data, bool isOn, string fieldText) => {
         });
     }
 }
    public override void initState(ResponseBase res)
    {
        base.initState(res);
        this.gameObject.SetActive(true);
        Debug.Log("initState res : " + res);

        if (res is ResponseCreateRoom)
        {
            ResponseCreateRoom resCr = (ResponseCreateRoom)res;
            title.text = resCr.title;
            // setUsersData(resCr.userList);
            roomNo    = resCr.roomNo;
            maxUser   = resCr.max;
            listUsers = resCr.userList;
            gameNo    = resCr.gameNo;
        }
        else
        {
            ResponseConnectionRoom resCr = (ResponseConnectionRoom)res;
            title.text = resCr.title;
            // setUsersData(resCr.userList);
            roomNo    = resCr.roomNo;
            maxUser   = resCr.max;
            listUsers = resCr.userList;
            gameNo    = resCr.gameNo;
        }

        foreach (GameObject obj in listUserObj)
        {
            Destroy(obj.gameObject);
        }

        listUserObj = new List <GameObject>();

        for (int i = 0; i < maxUser; i++)
        {
            GameObject item = Instantiate(userItem) as GameObject;
            //item.SetActive(false);
            listUserObj.Add(item);
            item.transform.parent = content.transform;
        }

        setUsersData();
        setButton();
    }
    public override void responseString(bool isSuccess, string identifier, string json)
    {
        if (isSuccess)
        {
            switch (identifier)
            {
            case Common.IDENTIFIER_CONNECT_ROOM:
            {
                ResponseConnectionRoom resCr = JsonUtility.FromJson <ResponseConnectionRoom>(json);
                listUsers = resCr.userList;
                isUpdate  = true;
            }
            break;

            case Common.IDENTIFIER_READY:
            {
                ResponseReady resReady = JsonUtility.FromJson <ResponseReady>(json);
                for (int i = 0; i < listUsers.Count; i++)
                {
                    if (resReady.email.Equals(listUsers[i].email))
                    {
                        listUsers[i].state = resReady.isReady == true ? (int)Common.USER_STATE.READY : (int)Common.USER_STATE.NONE;
                    }
                }
                // setUsersData(listUsers);
                isUpdate = true;
            }
            break;

            case Common.IDENTIFIER_OUT_ROOM:
            {
                // UserManager.Instance().outRoom();
                // GameManager.Instance().stateChange(GameManager.GAME_STATE.ROOM_LIST, null);
                StateManager.Instance().changeState(GAME_STATE.ROOM_LIST, null);
            }
            break;

            case Common.IDENTIFIER_ROOM_USERS:
            {
                ResponseRoomUsers resUsers = JsonUtility.FromJson <ResponseRoomUsers>(json);
                // setUsersData(resUsers.userList);
                listUsers = resUsers.userList;
                isUpdate  = true;
            }
            break;

            case Common.IDENTIFIER_START:
            {
                // ResponseStart res = JsonUtility.FromJson<ResponseStart>(json);
                //UserManager.Instance().roomNo = roomNo;
                switch (gameNo)
                {
                case (int)Common.GAME_KINDS.DAVINCICODE:
                {
                    //Common.gameInitJson = json;
                    DavinciCommon.gamePlayingData.gameNo = gameNo;
                    DavinciCommon.gamePlayingData.roomNo = roomNo;
                    DavinciCommon.gamePlayingData.json   = json;
                    gameScene = "game";
                    isUpdate  = true;
                }
                break;
                }
            }
            break;

            case Common.IDENTIFIER_ROOM_INFO:
            {
                ResponseRoomInfo res = JsonUtility.FromJson <ResponseRoomInfo>(json);
                listUsers = res.userList;
                isUpdate  = true;
            }
            break;
            }
        }
        else
        {
            ResponseBase res = JsonUtility.FromJson <ResponseBase>(json);
            showAlert("error", res.message, false, false, (AlertData data, bool isOn, string fieldText) => {
            });
        }
    }