Example #1
0
    private int Prcie;      //所拥有的金币数

    void Start()
    {
        //shopPath = Resources.Load("ShopData").ToString(); //获取路径

        //动态写入文件路径

        /*if (!File.Exists(savePath))
         * {
         *  File.WriteAllText(savePath, content);
         * }*/

        shopData = new ShopData();                            //实例化商城数据对象

        m_ShopItem = Resources.Load <GameObject>("ShopItem"); //加载预制体

        leftButton  = GameObject.Find("LeftButton");
        rightButton = GameObject.Find("RightButton");

        shopData.ReadByXmlPath(shopPath);    //加载Xml
        shopData.ReadGoldAndScore(savePath); //加载保存数据xml文件

        ui_starNum  = GameObject.Find("StarNum").GetComponent <UILabel>();
        ui_scoreNum = GameObject.Find("ScoreNum").GetComponent <UILabel>();

        //更新开始面板最高分显示
        int tempHeightScore = PlayerPrefs.GetInt("HeightScore", 0);

        if (tempHeightScore > shopData.heightScore)
        {
            //更新UI
            ShowHeightScore(tempHeightScore);
            //更新XML
            shopData.ChangeXMLData(savePath, "HeightScore", tempHeightScore.ToString());
            //清空PlayerPrefs中的数据
            PlayerPrefs.SetInt("HeightScore", 0);
        }
        else
        {
            //更新UI
            ShowHeightScore(shopData.heightScore);
        }

        //更新开始UI金币数显示
        int tempgold = PlayerPrefs.GetInt("GoldNum", 0);

        if (tempgold > 0)
        {
            //金币的增加
            int allgold = tempgold + shopData.goldCount;
            //更新UI
            ShowGoldNum(allgold);
            //更新XML
            shopData.ChangeXMLData(savePath, "GoldCount", allgold.ToString());
            //清空PlayerPrefs中的数据
            PlayerPrefs.SetInt("GoldNum", 0);
        }
        else
        {
            //更新UI
            ShowGoldNum(shopData.goldCount);
        }

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

        UIEventListener.Get(leftButton).onClick  = LeftButtonClick;
        UIEventListener.Get(rightButton).onClick = RightButtonClick;

        SetModelInfo(shopData.shopList[0]);
        //SetPlayerInfo(shopData.shopList[0].Player);
        CreateAllShopUI();
    }