Пример #1
0
    // Use this for initialization
    void Start()
    {
        xmlPath = Resources.Load("ShopData").ToString();
        if (!File.Exists(SavePath))
        {
            File.WriteAllText(SavePath, content);
        }
        shopData = new ShopData();
        shopData.ReadXmlByPath(xmlPath);
        shopData.ReadScoreAndGold(SavePath);
        Debug.Log(shopData.goldCount);
        Debug.Log(shopData.heightScore);

        ui_ShopItem    = Resources.Load <GameObject>("UI/ShopItem");
        LeftButtpn     = GameObject.Find("LeftButton");
        RightButtpn    = GameObject.Find("RightButton");
        StarNum        = GameObject.Find("Star/StarNum").GetComponent <UILabel>();
        ScoreNum       = GameObject.Find("Score/ScoreNum").GetComponent <UILabel>();
        m_StartManager = GameObject.Find("UI Root").GetComponent <StartManager>();

        int tempHeightScore = PlayerPrefs.GetInt("HeightScore", 0);

        if (tempHeightScore > shopData.heightScore)
        {
            UpdateUIHeightScore(tempHeightScore);
            shopData.UpdateXMLData(SavePath, "HeightScore", tempHeightScore.ToString());
            PlayerPrefs.SetInt("HeightScore", 0);
        }
        else
        {
            UpdateUIHeightScore(shopData.heightScore);
        }

        int tempGold = PlayerPrefs.GetInt("GoldNum", 0);

        if (tempGold > 0)
        {
            int gold = shopData.goldCount + tempGold;
            UpdateUIGold(gold);
            shopData.UpdateXMLData(SavePath, "GoldCount", gold.ToString());
            PlayerPrefs.SetInt("GoldNum", 0);
        }
        else
        {
            UpdateUIGold(shopData.goldCount);
        }

        UIEventListener.Get(LeftButtpn).onClick  = leftButtpnClick;
        UIEventListener.Get(RightButtpn).onClick = rightButtpnClick;
        SetPlayerInfo(shopData.ShopList[0]);
        CreateAllShopUI();
    }
Пример #2
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();
    }
Пример #3
0
    void Start()
    {
        savePath = Application.persistentDataPath + "/SaveData.xml";
        xmlPath  = Resources.Load("ShopData").ToString(); //静态文件只能读取
        if (!File.Exists(savePath))                       //第一次运行时写入
        {
            File.WriteAllText(savePath, content);
        }


        //实例化商城数据对象
        shopData = new ShopData();
        //加载XML
        shopData.ReadXmlByPath(xmlPath);
        shopData.ReadScoreAndGold(savePath);

        Debug.Log(shopData.goldCount);
        Debug.Log(shopData.heightScore);

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

        ui_ShopItem      = Resources.Load <GameObject>("UI/ShopItem");
        m_StartUIManager = GameObject.Find("UI Root").GetComponent <StartUIManager>();

        LeftButton  = GameObject.Find("LeftButton");
        RightButton = GameObject.Find("RightButton");
        UIEventListener.Get(LeftButton).onClick  = LeftButtonClick;
        UIEventListener.Get(RightButton).onClick = RightButtonClick;

        //同步UI与XML数据
        starNum  = GameObject.Find("Star/StarNum").GetComponent <UILabel>();
        scoreNum = GameObject.Find("Score/ScoreNum").GetComponent <UILabel>();

        //读取PlayerPrefabs中的最高分数
        int tempHeightScore = PlayerPrefs.GetInt("HeightScore", 0);

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

        //获取金币数量
        int tempGold = PlayerPrefs.GetInt("GoldNum", 0);

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

        SetPlayerInfo(shopData.shopList[0]);//默认的模型

        CreatAllShopUI();
    }