Exemplo n.º 1
0
    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);
        }
    }