Пример #1
0
    //请求开始准备
    public static void ReqSatrtReady()
    {
        Debug.Log("CommonRequest.ReqSatrtReady");
        req_message_start_ready reqMsg = new req_message_start_ready();

        Client.Instance.Request(reqMsg, (byte[] data) =>
        {
            rep_message_start_ready repMsg = Client.Deserialize(rep_message_start_ready.Parser, data) as rep_message_start_ready;
            Debug.Log("CommonRequest.ReqSatrtReady isOK = " + repMsg.IsOK);
            if (0 == repMsg.IsOK)
            {
                //打开准备UI
                UIManager.OpenUI("Prefabs/ReadyUI", UIManager.Instance.GameUIRoot, (uiObj) => {
                    UIReady uiReady = uiObj.transform.GetComponent <UIReady>();
                    if (null != uiReady)
                    {
                        uiReady.RefreshUI(repMsg);
                    }
                    //关闭匹配UI
                    UIManager.CloseUI("Prefabs/MatchUI");
                    //关闭上一局UI
                    UIManager.CloseUI("Prefabs/PlayUI");
                });
            }
            else
            {
                Debug.LogError("CommonRequest.ReqSatrtReady Request Match Error!");
            }
        });
    }
Пример #2
0
    public void RefreshUI(rep_message_start_ready readyInfo)
    {
        struct_player_info opponentInfo = readyInfo.PlayerInfo;

        Debug.Log("UIReady.RefreshUI readyInfo = " + readyInfo);
        //我的头像
        if (!string.IsNullOrEmpty(PlayerData.userIcon))
        {
            var headIcon = transform.Find("PlayerInfo/LeftHeadImage/Mask/Image").GetComponent <Image>();
            StartCoroutine(Function.DownloadImage(headIcon, PlayerData.userIcon));
        }
        //对手头像
        if (!string.IsNullOrEmpty(opponentInfo.UserIcon))
        {
            var headIcon = transform.Find("PlayerInfo/RightHeadImage/Mask/Image").GetComponent <Image>();
            StartCoroutine(Function.DownloadImage(headIcon, opponentInfo.UserIcon));
        }
        //倒计时
        float totalTime      = (float)(readyInfo.StartTime - Function.GetServerTime());
        Image countdownImage = transform.Find("Countdown/Bar").GetComponent <Image>();

        Scheduler.Instance.CreateScheduler("UIReady.Countdown", 0, 0, 0.01f, (param) =>
        {
            float lastTime            = (float)(readyInfo.StartTime - Function.GetServerTime());
            countdownImage.fillAmount = lastTime / totalTime;
            //Debug.Log("UIReady.Countdown lastTime = " + lastTime + " totalTime = " + totalTime);
            if (countdownImage.fillAmount <= 0)
            {
                Scheduler.Instance.Stop("UIReady.Countdown");
                //请求开始
                CommonRequest.ReqSatrtGame(readyInfo.Innings, (repMsg) => {
                    //关闭UI
                    //this.Close();
                });
            }
        });
        //第几回合
        transform.Find("Countdown/Text").GetComponent <Text>().text = Language.GetTextByKey(InningsTextKey[readyInfo.Innings]);
        //展示要随机的玩法
        playViewList.RegisterInitCallback((Transform obj, int index) =>
        {
            int playID = readyInfo.RandPlayId[index];
            //获取配置
            play_data playData = PlayDataConfig.Instance.GetDataByID(playID);
            //icon
            Function.SetImageSprite(obj.Find("Icon/Image").GetComponent <Image>(), playData.Icon);
            //名字
            obj.Find("Name").GetComponent <Text>().text = playData.Name;
        });
        //刷新列表
        playViewList.totalCount = readyInfo.RandPlayId.Count;
        playViewList.RefillCells();
        //随机选中玩法
        int       randCount = 0;
        Transform randRoot  = transform.Find("RandPlay/Viewport/Content");

        Scheduler.Instance.CreateScheduler("UIReady.RandPlay", 0, 0, 0.3f, (param) => {
            for (int idx = 0; idx < randRoot.childCount; idx++)
            {
                randRoot.GetChild(idx).Find("Icon/Choose").gameObject.SetActive(idx == randCount);
            }
            if (readyInfo.RandPlayId[randCount] == readyInfo.PlayId && readyInfo.StartTime - Function.GetServerTime() < 1.0)
            {
                //结束定时器
                Scheduler.Instance.Stop("UIReady.RandPlay");
                //播放一个放大效果
                ScaleTo scaleTo = randRoot.GetChild(randCount).Find("Icon").GetComponent <ScaleTo>();
                scaleTo.Play();
            }
            randCount = (randCount + 1) % readyInfo.RandPlayId.Count;
        });
    }