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();
    }
Beispiel #2
0
    void Start()
    {
        xmlPath = Resources.Load("ShopData").ToString();//安卓.
        if (!File.Exists(savePath))
        {
            File.WriteAllText(savePath, content);//安卓.
        }

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

        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>();
        //读取playerprefs中的新的最高分.
        int tempHeightScore = PlayerPrefs.GetInt("HeightScore", 0);

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

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

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

        SetPlayInfo(shopData.shopList[0]);

        CreateAllShopUI();
    }
Beispiel #3
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();
    }
    void Start()
    {
        shopDataContent = Resources.Load("ShopData").ToString(); //Set the content of ShopData.xml to a string variable.

        if (!File.Exists(savePath))
        {
            File.WriteAllText(savePath, saveDataContent);
        }

        shopData = gameObject.AddComponent <ShopData>();
        shopData.ReadXmlByPath(shopDataContent);
        shopData.ReadPlayerInfo(savePath);

        //Test for ReadPlayerInfo.
        //Debug.Log(shopData.goldCount);
        //Debug.Log(shopData.bestScore);
        //for(int i = 0; i < shopData.shopStatus.Count; i++)
        //{
        //    Debug.Log(shopData.shopStatus[i]);
        //}

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

        //Button event binding.
        leftButton  = GameObject.Find("LeftButton");
        rightButton = GameObject.Find("RightButton");
        UIEventListener.Get(leftButton).onClick  = LeftButtonClick;
        UIEventListener.Get(rightButton).onClick = RightButtonClick;

        //Sync the player info data from xml to UI.
        starValue  = GameObject.Find("Star/StarValue").GetComponent <UILabel>();
        scoreValue = GameObject.Find("Score/ScoreValue").GetComponent <UILabel>();

        //Load the new score from PlayerPrefs.
        int temp_Score = PlayerPrefs.GetInt("Score", 0);

        if (temp_Score > shopData.bestScore)
        {
            //Update UI best score.
            UpdateUIScore(temp_Score);
            //Update XML best score.
            shopData.UpdateXMLData(savePath, "BestScore", temp_Score.ToString());
            //Clear PlayerPrefs data.
            PlayerPrefs.SetInt("Score", 0);
        }
        else
        {
            UpdateUIScore(shopData.bestScore);
        }

        //Load the star value from PlayerPrefs.
        int temp_Star = PlayerPrefs.GetInt("Star", 0);

        if (temp_Star > 0)
        {
            int currentStarValue = shopData.goldCount + temp_Star;
            //Update UI star value.
            UpdateUIStar(currentStarValue);
            //Update XML star value.
            shopData.UpdateXMLData(savePath, "GoldCount", currentStarValue.ToString());
            //Clear PlayerPrefs data.
            PlayerPrefs.SetInt("Star", 0);
        }
        else
        {
            UpdateUIStar(shopData.goldCount);
        }

        SetWarshipInfo(shopData.shopList[index]);  //Pre-load the ship model path.

        CreateAllShopUI();
    }
Beispiel #5
0
 private void Awake()
 {
     instance = this;
 }
Beispiel #6
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();
    }