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