Exemple #1
0
    public void RefreshUI(int _innings, rep_message_start_game _playInfo)
    {
        this.innings  = _innings;
        this.playInfo = _playInfo;
        //初始界面状态
        SetUIState(0);
        //我的头像
        if (!string.IsNullOrEmpty(PlayerData.userIcon))
        {
            var headIcon = transform.Find("PlayerInfo/LeftHeadImage/Mask/Image").GetComponent <Image>();
            StartCoroutine(Function.DownloadImage(headIcon, PlayerData.userIcon));
        }
        //对手头像
        struct_player_info opponentInfo = this.playInfo.PlayerInfo;

        if (!string.IsNullOrEmpty(opponentInfo.UserIcon))
        {
            var headIcon = transform.Find("PlayerInfo/RightHeadImage/Mask/Image").GetComponent <Image>();
            StartCoroutine(Function.DownloadImage(headIcon, opponentInfo.UserIcon));
        }
        //加载玩法prefab
        play_data playData = PlayDataConfig.Instance.GetDataByID(this.playInfo.PlayId);

        UIManager.OpenUI(playData.PrefabPath, playUI, (uiObj) =>
        {
            playBase = uiObj.transform.GetComponent <PlayBase>();
            playBase.answerFinish = AnswerFinish;
        });
    }
    //请求开始游戏
    public static void ReqSatrtGame(int innings, System.Action <rep_message_start_game> callback = null)
    {
        Debug.Log("CommonRequest.ReqSatrtGame");
        req_message_start_game reqMsg = new req_message_start_game();

        reqMsg.Innings = innings;
        Client.Instance.Request(reqMsg, (byte[] data) =>
        {
            rep_message_start_game repMsg = Client.Deserialize(rep_message_start_game.Parser, data) as rep_message_start_game;
            Debug.Log("CommonRequest.ReqSatrtGame isOK = " + repMsg.IsOK);
            if (0 == repMsg.IsOK)
            {
                //开始游戏
                Debug.Log("end_time = " + repMsg.EndTime);
                if (null != callback)
                {
                    callback(repMsg);
                }
                //打开PlayUI
                UIManager.OpenUI("Prefabs/PlayUI", UIManager.Instance.GameUIRoot, (uiObj) =>
                {
                    UIPlay uiPlay = uiObj.transform.GetComponent <UIPlay>();
                    if (null != uiPlay)
                    {
                        uiPlay.RefreshUI(innings, repMsg);
                    }
                    //关闭准备UI
                    UIManager.CloseUI("Prefabs/ReadyUI");
                });
            }
            else
            {
                Debug.LogError("CommonRequest.ReqSatrtGame Request Start Error!");
            }
        }, false);
    }