Esempio n. 1
0
    void UpdateBox(ChapterinfoTemplate chapterT)
    {
        ResetBoxToZero();

        //--------------宝箱--------------
        int curStars   = 0;
        int totalStars = 0;

        if (StageModule.GetCurTotalStarsCount(chapterT, mDifficutType, out curStars, out totalStars))
        {
            m_curTxt.text   = curStars.ToString();
            m_totalTxt.text = "/" + totalStars;

            mScrollBar.value = (float)(curStars) / (float)(totalStars);

            int[] perStars = chapterT.getStarnum();
            for (int i = 0, j = mBoxs.Count; i < j; i++)
            {
                //TODO::是否领取过---章节id,难度,第几个宝箱;
                bool isGot = StageModule.IsRewardGot(mCurChapterId);
                if (curStars >= perStars[i])
                {
                    if (isGot)
                    {
                        mBoxs[i].SetBoxImg(BoxSprite[1]);
                        mBoxs[i].SetEffActive(false);
                    }
                    else
                    {
                        mBoxs[i].SetBoxImg(BoxSprite[0]);
                        mBoxs[i].SetEffActive(true);
                    }
                }
                else
                {
                    //NoOpen;
                    mBoxs[i].SetBoxImg(BoxSprite[0]);
                    mBoxs[i].SetEffActive(false);
                }
                mBoxs[i].SetStarNum(perStars[i]);
            }

            //if (curStars >= totalStars)
            //{
            //    //是否领取过;
            //    bool isGot = StageModule.IsRewardGot(mCurChapterId);
            //    if (isGot)
            //    {
            //        m_BoxImg.sprite = BoxSprite[1];
            //    }
            //    else
            //    {
            //        //宝箱震动;
            //        InvokeRepeating("Shake", mShakeDelay, mShakeRate);

            //        m_BoxImg.sprite = BoxSprite[0];
            //    }
            //}
            //else
            //{
            //    m_BoxImg.sprite = BoxSprite[0];
            //}
        }
        else
        {
            Debug.LogError("数据错误");
        }
    }
    void UpdateBox(ChapterinfoTemplate chapterT)
    {
        //--------------宝箱--------------
        int curStars   = 0;
        int totalStars = 0;

        if (StageModule.GetCurTotalStarsCount(chapterT, mDifficutType, out curStars, out totalStars))
        {
            m_curTxt.text   = curStars.ToString();
            m_totalTxt.text = "/" + totalStars;

            m_SliderFront.SetActive(curStars > 0);
            //m_Slider.value = (float)(curStars) / (float)(totalStars);

            //判断当前星级属于第几个阶段;
            int   stageLv  = StarLvStage(curStars, chapterT.getStarnum());
            float progress = 0f;
            for (int i = 0; i < 3; i++)
            {
                if (i < stageLv)
                {
                    progress += 0.34f;
                }
                else
                {
                    float delta = 0f;
                    if (stageLv <= 0)
                    {
                        delta = (float)(curStars) / (float)(chapterT.getStarnum()[0]);
                    }
                    else
                    {
                        int star = curStars;
                        //for (int m = 0; m < stageLv ; m++)
                        //{
                        //    star -= chapterT.getStarnum()[m];
                        //}
                        star -= chapterT.getStarnum()[stageLv - 1];
                        delta = (float)(star) / (float)(chapterT.getStarnum()[stageLv] - chapterT.getStarnum()[stageLv - 1]);
                    }
                    progress += delta * 0.34f;

                    break;
                }
            }

            m_Slider.value = progress;

            int[] perStars = chapterT.getStarnum();
            for (int i = 0, j = mBoxs.Count; i < j; i++)
            {
                //TODO::是否领取过---章节id,难度,第几个宝箱;
                bool isGot = StageModule.IsRewardGot(mCurChapterId, i);
                if (curStars >= perStars[i])
                {
                    if (isGot)
                    {
                        if (i == 2)
                        {
                            mBoxs[i].SetBoxImg(BoxSprite[3]);
                        }
                        else
                        {
                            mBoxs[i].SetBoxImg(BoxSprite[1]);
                        }
                        mBoxs[i].SetEffActive(false);
                    }
                    else
                    {
                        if (i == 2)
                        {
                            mBoxs[i].SetBoxImg(BoxSprite[2]);
                        }
                        else
                        {
                            mBoxs[i].SetBoxImg(BoxSprite[0]);
                        }
                        mBoxs[i].SetEffActive(true);
                    }
                }
                else
                {
                    if (i == 2)
                    {
                        mBoxs[i].SetBoxImg(BoxSprite[2]);
                    }
                    else
                    {
                        mBoxs[i].SetBoxImg(BoxSprite[0]);
                    }
                    mBoxs[i].SetEffActive(false);
                }
                mBoxs[i].SetStarNum(perStars[i]);
            }

            //if (curStars >= totalStars)
            //{
            //    //是否领取过;
            //    bool isGot = StageModule.IsRewardGot(mCurChapterId);
            //    if (isGot)
            //    {
            //        m_BoxImg.sprite = BoxSprite[1];
            //    }
            //    else
            //    {
            //        //宝箱震动;
            //        InvokeRepeating("Shake", mShakeDelay, mShakeRate);

            //        m_BoxImg.sprite = BoxSprite[0];
            //    }
            //}
            //else
            //{
            //    m_BoxImg.sprite = BoxSprite[0];
            //}
        }
        else
        {
            Debug.LogError("数据错误");
        }
    }