Ejemplo n.º 1
0
    void Start()
    {
        //实例化商城数据对象
        shopData = new ShopData();
        //加载xml
        shopData.ReadXMLByPath(xmlPath);
        shopData.ReadScoreAndGold(savePath);

        ui_ShopItem = Resources.Load <GameObject>("UI/ShopItem");

        m_StartUIManager = GameObject.Find("UI Root").GetComponent <StartUIManager>();

        //按钮事件绑定
        leftButton = GameObject.Find("LeftButton");
        UIEventListener.Get(leftButton).onClick = LeftButtonClick;
        rightButton = GameObject.Find("RightButton");
        UIEventListener.Get(rightButton).onClick = RightButtonClick;

        //同步UI与XML的数据
        starNum  = GameObject.Find("Star/StarNum").GetComponent <UILabel>();
        scoreNum = GameObject.Find("Score/ScoreNum").GetComponent <UILabel>();
        //读取PlayerPrefs中的新的最高分
        int temHighestScore = PlayerPrefs.GetInt("HighestScore", 0);

        if (temHighestScore > shopData.highScore)
        {
            //更新UI
            UpdateUIHighestScore(temHighestScore);
            //更新XML,存储新的最高分
            shopData.UpdateXMLData(savePath, "HeightScore", temHighestScore.ToString());
            //清空PlayerPrefs
            PlayerPrefs.SetInt("HeightScore", 0);
        }
        else
        {
            //更新UI
            UpdateUIHighestScore(shopData.highScore);
        }

        //读取PlayerPrefs中的金币数
        int tempGold = PlayerPrefs.GetInt("GoldNum", 0);

        if (tempGold > 0)
        {
            int gold = shopData.goldCount + tempGold;
            //更新UI
            UpdateUIGold(gold);
            //更新XML中的存储
            shopData.UpdateXMLData(savePath, "GoldCount", gold.ToString());
            //清空PlayerPrefs
            PlayerPrefs.SetInt("GoldNum", 0);
        }
        else
        {
            //更新UI
            UpdateUIGold(shopData.goldCount);
        }

        SetPlayerInfo(shopData.shopList[0]);

        CreateAllShopUI();
    }