Esempio n. 1
0
 /// <summary>
 /// 计算商品价格并购买
 /// </summary>
 /// <param name="item"></param>
 public void CalcItemPrice(ShopUIItem item)
 {
     if (shopData.goldCount >= item.itemPrice)   //当金币数大于商品价格时
     {
         Debug.Log("购买成功");
         item.buyState.SetActive(false);                                               //隐藏购买按钮
         shopData.goldCount -= item.itemPrice;                                         //金币数减去商品价格
         ShowUIData();                                                                 //更新UI数据
         shopData.ChangeXMLData(savePath, "GoldCount", shopData.goldCount.ToString()); //更新金币数
         shopData.ChangeXMLData(savePath, "ID" + item.itemID, "1");                    //更新商品的购买状态
     }
     else
     {
         Debug.Log("购买失败,金币不足");
     }
 }
Esempio n. 2
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();
    }