예제 #1
0
    public void SaveGameInfo()
    {
        string filePath = Application.persistentDataPath + "/Game.xml";

        if (!File.Exists(filePath))
        {
            XmlDocument xmlDoc = new XmlDocument();
            //头结点
            XmlElement root = xmlDoc.CreateElement("Game");

            XmlElement localMoney = xmlDoc.CreateElement("TotalMoney");
            localMoney.InnerText = TotalMoney.ToString();
            XmlElement localBgVolume = xmlDoc.CreateElement("BgVolume");
            localBgVolume.InnerText = BgVolume.ToString();
            XmlElement localEffectVolume = xmlDoc.CreateElement("EffectVolume");
            localEffectVolume.InnerText = EffectVolume.ToString();
            XmlElement localLevel2Lock = xmlDoc.CreateElement("Level2Lock");
            localLevel2Lock.InnerText = Level2Lock.ToString();
            XmlElement localLevel3Lock = xmlDoc.CreateElement("Level3Lock");
            localLevel3Lock.InnerText = Level3Lock.ToString();

            root.AppendChild(localMoney);
            root.AppendChild(localBgVolume);
            root.AppendChild(localEffectVolume);
            root.AppendChild(localLevel2Lock);
            root.AppendChild(localLevel3Lock);
            xmlDoc.AppendChild(root);
            xmlDoc.Save(filePath);
        }
    }
예제 #2
0
    public void UpdateGameInfo()
    {
        string filePath = Application.persistentDataPath + "/Game.xml";

        if (File.Exists(filePath))
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(filePath);

            XmlNodeList gameNodeList = xmlDoc.SelectSingleNode("Game").ChildNodes;
            //遍历Player结点下所有子节点
            foreach (XmlElement xe in gameNodeList)
            {
                switch (xe.Name)
                {
                case "TotalMoney":
                    xe.InnerText = TotalMoney.ToString();
                    break;

                case "BgVolume":
                    xe.InnerText = BgVolume.ToString();
                    break;

                case "EffectVolume":
                    xe.InnerText = EffectVolume.ToString();
                    break;

                case "Level2Lock":
                    xe.InnerText = Level2Lock.ToString();
                    break;

                case "Level3Lock":
                    xe.InnerText = Level3Lock.ToString();
                    break;
                }
            }
            xmlDoc.Save(filePath);
        }
    }