Unity之解析Xml
来源:互联网 发布:网络上翻车什么意思 编辑:程序博客网 时间:2024/05/22 04:39
//PreyerPrefs
using UnityEngine;
using System.Collections;
public class PreyerPrefsTest : MonoBehaviour {
void Awake(){
PlayerPrefs.SetInt ("age",18);
PlayerPrefs.SetFloat ("money",4000);
PlayerPrefs.SetString ("xingming","xiaoming");
PlayerPrefs.SetString ("URL","www.baidu.com");
if(PlayerPrefs.HasKey("URL")){
PlayerPrefs.DeleteKey ("URL");
}
print (PlayerPrefs.GetInt("age"));
print (PlayerPrefs.GetFloat("money"));
print (PlayerPrefs.GetString("xingming"));
PlayerPrefs.Save ();
print (Application.persistentDataPath);//:/Users/students/Library/Application Support/DefaultCompany/XmlPlayerPrefs(工程名)
print (Application.streamingAssetsPath);//:/Users/students/XmlPlayerPrefs/Assets/StreamingAssets
print (Application.dataPath);//:/Users/students/XmlPlayerPrefs/Assets
}
// Use this for initializationx
void Start () {
}
// Update is called once per frame
void Update () {
}
}
using UnityEngine;
using System.Collections;
public class Person {
public string Name{
set
{
PlayerPrefs.SetString ("Name", value);
PlayerPrefs.Save ();
}
get
{
return PlayerPrefs.GetString ("Name");
}
}
}
//Xml
using UnityEngine;
using System.Collections;
using System.IO;
using System.Xml;
public class XmlParse : MonoBehaviour {
public string xmlFileName = "/MyXmlFile.xml";
private string xmlFilePath=string.Empty;
void Awake(){
xmlFilePath = Application.streamingAssetsPath + xmlFileName;
xmlParseFun ();
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void xmlParseFun(){
XmlDocument doc = new XmlDocument ();
doc.Load (xmlFilePath);
XmlNode node = doc.SelectSingleNode ("Plist");
foreach(XmlElement e in node){
if(e.Name.Equals("dict")){
foreach(XmlElement ele in e){
if(ele.Name.Equals("array")){
XmlElement xmle = doc.CreateElement ("mystirng");
xmle.InnerText = "nihao";
ele.AppendChild (xmle);
}
}
}
}
doc.Save (xmlFilePath);
}
}
using UnityEngine;
using System.Collections;
using System.Xml;
using System.Collections.Generic;
public class XmlParse02 : MonoBehaviour {
public string xmlFileName="/MyXmlFile02.xml";
public string xmlFilePath;
List<Level> levels=new List<Level> ();
void Awake(){
xmlFilePath = Application.streamingAssetsPath + xmlFileName;
XmlParseFun ();
// CoutLevels ();
}
void XmlParseFun(){
XmlDocument doc=new XmlDocument ();
doc.Load (xmlFilePath);
XmlNode root = doc.SelectSingleNode ("levels");
XmlNode node = root.FirstChild;
while(node!=null){
// /print (node.Name);
foreach(XmlElement e in node ){
print (e.InnerText);
}
node = node.NextSibling;
}
// foreach(XmlElement e in root){
// Level temp = new Level ();
// foreach(XmlElement child in e){
//
//
// if (child.Name == "Name") {
// temp.Name = child.InnerText;
// } else if (child.Name =="Star") {
// temp.Star =int.Parse( child.InnerText);
// } else {
//
// temp.Lock =int.Parse( child.InnerText);
// }
// }
// levels.Add (temp);
// }
}
// void CoutLevels(){
// foreach(Level e in levels){
// print (e.Name + " : " + e.Star + " : " + e.Lock);
// }
// }
}
//MyXmlFile.xml
<?xml version="1.0" encoding="UTF-8"?>
<Plist>
<dict>
<key>tips</key>
<array>
<string>修改后的内容</string>
<mystring>my string value</mystring>
<mystirng>nihao</mystirng>
</array>
</dict>
<dic>
</dic>
</Plist>
//MyXmlFile02.xml
<?xml version="1.0" encoding="UTF-8" ?>
<levels>
<level>
<Name>
第一关
</Name>
<Star>
2
</Star>
<Lock>
0
</Lock>
</level>
<level>
<Name>
第二关
</Name>
<Star>
3
</Star>
<Lock>
1
</Lock>
</level>
</levels>
- Unity之解析Xml
- UNITY之Xml解析项目
- Unity解析XML
- unity 解析XML文件
- unity 与 XML 解析
- Unity序列化之XML,JSON--------合成与解析
- Unity序列化之XML,JSON--------合成与解析
- Unity 基础 XML文件解析
- Unity Json与Xml解析
- unity之XML
- unity基础开发----常用代码Unity中解析XML
- Unity之JSON数据解析
- unity UGUI之button解析
- XML解析之DOM解析
- XML解析之SAX解析
- XML解析之SAX解析
- xml解析之DOM4j解析
- xml解析之pull解析
- Ohana Cleans Up
- 【codeforces 632B Alice, Bob, Two Teams】
- typedef void (*Fun) (void)
- Linux下的C编程实战
- Ubuntu学习 变量 (4)
- Unity之解析Xml
- 编程常遇到的数据库优化项1
- 深入浅出Docker系列
- java基础学习之PreparedStatement
- 操作系统自举后做了什么???
- gcc编译小认识
- Bear and Reverse Radewoosh
- Linux中mprotect()函数的用法
- sdut oj3403 数据结构实验之排序六:希尔排序