Exemple #1
0
    // check and save achievement,返回是否升级
    private void CheckNum(int id, int num, int oldNum, bool checkLevel)
    {
        int needNum = this.GetAchievementNeedNum(id);

        if (needNum == -1)
        {
            return;
        }
        if (num >= needNum)         // passed
        {
            SetAchievement(id, true);
            // 播放通过条件动画
            AniInfo aniInfo = new AniInfo(AniConditionPass);
            string  txt     = LevelConfig.GetAchievement(id).GetNumText(this.GetAchievementNeedNum(id, true));
            this.PlayAni(aniInfo.AddParam("condition", txt));

            if (checkLevel)
            {
                this.CheckLevel();                 // 检查等级
            }
        }
        else if (id != 3003)
        {
            // 播放进度动画
            string  txt     = LevelConfig.GetAchievement(id).GetNumText(this.GetAchievementNeedNum(id, true));
            AniInfo aniInfo = new AniInfo(AniConditionProgress);
            this.PlayAni(aniInfo.AddParam("condition", txt).AddParam("oldNum", oldNum.ToString()).AddParam("newNum", num.ToString()));
        }
    }
Exemple #2
0
    private void DealCondition(int level, GameObject canvas)
    {
        Level levelConfig = LevelConfig.GetLevel(level);

        if (levelConfig == null)
        {
            levelConfig            = new Level();
            levelConfig.conditions = new Condition[0];
        }
        var conditions = canvas.transform.Find("UIConditions"); // all level item ui
        int itemNum    = conditions.childCount;                 // level item num

        for (int i = 0; i < itemNum; i++)
        {
            var conditionItem = conditions.GetChild(i).gameObject;
            var text          = conditionItem.transform.Find("Text");
            var recordText    = conditionItem.transform.Find("RecordText");          // 需要显示当前进度
            var finish1       = conditionItem.transform.Find("Finish1").gameObject;  // 完成打钩
            var finish2       = conditionItem.transform.Find("Finish2").gameObject;
            if (recordText != null)
            {
                recordText.gameObject.SetActive(false);
            }
            string resource = "UI/condition_";
            if (i >= levelConfig.conditions.Length)             // empty condition
            {
                resource += "off";
                text.GetComponent <Text>().text = "";
                finish1.SetActive(false);                 // 不打钩
                finish2.SetActive(false);
            }
            else
            {
                int achievementId = levelConfig.conditions[i].id;
                if (GetComponent <AchievementController>().GetAchievement(achievementId))
                {
                    resource += "on";
                    finish1.SetActive(true);                     // 打钩
                    finish2.SetActive(true);
                }
                else
                {
                    resource += "off";
                    finish1.SetActive(false);                    // 不打钩
                    finish2.SetActive(false);
                    if (recordText != null)                      // 显示进度数字
                    {
                        int record = GetComponent <AchievementController>().GetAchievementNum(achievementId);
                        recordText.GetComponent <Text>().text = record.ToString();
                        recordText.gameObject.SetActive(true);
                    }
                }
                Achievement achievementConfig = LevelConfig.GetAchievement(achievementId);
                text.GetComponent <Text>().text = achievementConfig.GetNumText(levelConfig.conditions[i].num);
            }
            var sprite = Resources.Load(resource, typeof(Sprite)) as Sprite;             // replace sprite color
            conditionItem.GetComponent <Image>().sprite = sprite;
        }
    }