Esempio n. 1
0
    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();
    }
Esempio n. 2
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();
    }
Esempio n. 3
0
    void Start()
    {
        ui_ShopItem = Resources.Load <GameObject>("UI/ShopItem");

        //按钮事件绑定
        leftButton  = GameObject.Find("LeftButton");
        rightButton = GameObject.Find("RightButton");
        UIEventListener.Get(leftButton).onClick  = LeftButtonClick;
        UIEventListener.Get(rightButton).onClick = RightButtonClick;

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

        CreateAllShopUI();
    }
Esempio n. 4
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();
    }
Esempio n. 5
0
    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();
    }
Esempio n. 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();
    }