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(); }