コード例 #1
0
ファイル: ShopManger.cs プロジェクト: DingLi-23/MyCat
    void Start()
    {
        shopData = new ShopData();

        //加载XML.
        shopData.ReadXmlByPath(xmlPath);
        shopData.ReadMasonryandshopState(savePath);

        //shopData.shopList:

        Debug.Log(shopData.masonryCount);

        for (int i = 0; i < shopData.shopState.Count; i++)
        {
            Debug.Log(shopData.shopState[i]);
        }

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

        //左右按钮事件.
        leftButton  = GameObject.Find("LeftButton");
        rightButton = GameObject.Find("RightButton");
        button_Play = GameObject.Find("Play");
        UIEventListener.Get(leftButton).onClick  = LeftButtonClick;
        UIEventListener.Get(rightButton).onClick = RightButtonClick;
        UIEventListener.Get(button_Play).onClick = PlayButtonClick;

        //UI与xml数据的同步.
        masonryNums = GameObject.Find("Masonry/MasonryNum").GetComponent <UILabel>();
        //UpdateUI();

        //读取PlayerPerfs中的钻石数.
        int tempMasonry = PlayerPrefs.GetInt("MasonryCount", 0);

        if (tempMasonry > 0)
        {
            int masonry = shopData.masonryCount + tempMasonry;
            //更新UI
            UpdateUIMasonry(masonry);
            //更新XML中的数据.
            shopData.UpdateXMLData(savePath, "MasonryCount", masonry.ToString());
            //清空PlayerPrefs
            PlayerPrefs.SetInt("MasonryCount", 0);
        }
        else
        {
            //更新UI.
            UpdateUIMasonry(shopData.masonryCount);
        }

        SetPlayerInfo(shopData.shopList[0].Model);

        CreateAllShopUI();
    }