public void UpdatePlayerInfo() { string filePath = Application.persistentDataPath + "/Player.xml"; if (File.Exists(filePath)) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(filePath); XmlNodeList playerNodeList = xmlDoc.SelectSingleNode("Player").ChildNodes; //遍历Player结点下所有子节点 foreach (XmlElement xe in playerNodeList) { switch (xe.Name) { case "LevelLayer": xe.InnerText = LayerCount.ToString(); break; case "Hp": xe.InnerText = Hp.ToString(); break; case "ShootLevel": xe.InnerText = ShootLevel.ToString(); break; case "SpeedLevel": xe.InnerText = SpeedLevel.ToString(); break; case "BulletLevel": xe.InnerText = BulletLevel.ToString(); break; case "LightLevel": xe.InnerText = BulletLevel.ToString(); break; case "Speed": xe.InnerText = Speed.ToString(); break; case "ShootTimer": xe.InnerText = ShootTimer.ToString(); break; case "Money": xe.InnerText = Money.ToString(); break; case "SkillIcon": xe.InnerText = skillIcon.ToString(); break; } } xmlDoc.Save(filePath); } }
public void SetSpeed(SpeedLevel level) { foreach (GiantSpeed sp in availableMovements) { if (sp.type.Equals(level)) { navMeshAgent.speed = sp.speed; return; } } Debug.Log(level.ToString() + " speed level is not supported"); }
public void SavePlayerInfo() { string filePath = Application.persistentDataPath + "/Player.xml"; if (!File.Exists(filePath)) { XmlDocument xmlDoc = new XmlDocument(); //头结点 XmlElement root = xmlDoc.CreateElement("Player"); XmlElement locallayer = xmlDoc.CreateElement("LevelLayer"); locallayer.InnerText = LayerCount.ToString(); XmlElement localHp = xmlDoc.CreateElement("Hp"); localHp.InnerText = Hp.ToString(); XmlElement localShootLevel = xmlDoc.CreateElement("ShootLevel"); localShootLevel.InnerText = ShootLevel.ToString(); XmlElement localSpeedLevel = xmlDoc.CreateElement("SpeedLevel"); localSpeedLevel.InnerText = SpeedLevel.ToString(); XmlElement localBulletLevel = xmlDoc.CreateElement("BulletLevel"); localBulletLevel.InnerText = BulletLevel.ToString(); XmlElement localLightlevel = xmlDoc.CreateElement("LightLevel"); localLightlevel.InnerText = LightLevel.ToString(); XmlElement localSpeed = xmlDoc.CreateElement("Speed"); localSpeed.InnerText = Speed.ToString(); XmlElement localShootTimer = xmlDoc.CreateElement("ShootTimer"); localShootTimer.InnerText = ShootTimer.ToString(); XmlElement localMoney = xmlDoc.CreateElement("Money"); localMoney.InnerText = Money.ToString(); XmlElement localSkillIcon = xmlDoc.CreateElement("SkillICon"); localSkillIcon.InnerText = skillIcon.ToString(); root.AppendChild(locallayer); root.AppendChild(localHp); root.AppendChild(localShootLevel); root.AppendChild(localSpeedLevel); root.AppendChild(localBulletLevel); root.AppendChild(localLightlevel); root.AppendChild(localSpeed); root.AppendChild(localShootTimer); root.AppendChild(localMoney); root.AppendChild(localSkillIcon); xmlDoc.AppendChild(root); xmlDoc.Save(filePath); } }