看看路径,还有生成的xml在不在那个文件夹
用WWW的方式获取xml再解析据说可以。 还有,别忘了在根目录放置crossdomain.xml。
当unity发布为web之后,想要运行之后在本机上面保存一个xml文件,并且读取,目前只找到了读取的方法。其实就是把本机当成是一个服务器端,web运行的时候从本机的URL上面读取一个xml文件,注意要把crossdomain.xml保存到c盘的wwwroot目录下
,然后将要读取的xml文件放到发布之后的web文件下面的templets文件夹里面
,unity代码:
using UnityEngine;
using System.Collections;
using System.Xml;
using System;
using System.Text;
using System.Collections.Generic;
public class Test1 : MonoBehaviour
{
public string timeURL;
public string all;
public string id;
public string start;
public string end;
public string content;
public string fdate;
public string idate;
private string erro1;
private string erro2;
private string erro3;
// Use this for initialization
void Start()
{
timeURL = "http://127.0.0.1:82/templets/area.xml"; //这里填写格式
StartCoroutine(GetXML());
}
IEnumerator GetXML()
{
Debug.Log("Start get GetXML");
WWW www = new WWW(timeURL);
while (!www.isDone)
{
Debug.Log("Getting GetXML");
yield return www;
all = www.text;
Debug.Log("Finish getting GetXML and whole xml is : " + www.text);
ParseXml(www);
}
}
public void ParseXml(WWW www)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(www.text);
XmlNodeList nodeList=xmlDoc.SelectSingleNode("list").ChildNodes;
foreach(XmlElement xe in nodeList)
{
id = xe.GetAttribute("id");
start = xe.GetAttribute("start");
end = xe.GetAttribute("end");
content = xe.GetAttribute("content");
fdate = xe.GetAttribute("fdate");
idate = xe.GetAttribute("idate");
}
}
void OnGUI()
{
GUI.Label(new Rect(100,00,200,200),all);
GUI.Label(new Rect(0,00,200,200),id);
GUI.Label(new Rect(0,30,200,200),start);
GUI.Label(new Rect(0,60,200,200),end);
GUI.Label(new Rect(0,90,200,200),content);
GUI.Label(new Rect(0,120,200,200),fdate);
GUI.Label(new Rect(0,150,200,200),idate);
}
}
1.File - Build Setting 2.将鼠标光标移动到Web Player一栏,点击Switch Platform按钮 3.点击Build,选择路径 4.连接网络,打开发布好的html文件
建议你用这个来做为手机上xml的地址application.persistentdatapath
用WWW的方式获取xml再解析据说可以。 还有,别忘了在根目录放置crossdomain.xml
Photoshop|
Dreamweaver|
SVG|
WebGL|
Visual Studio|
PowerDesigner|
Eclipse|
Git|
Apache Ant|
Atom|
Composer|
CodeSmith|
Flex|
Gradle|
Maven|
Sublime Text3|
SVN|
Tableau|
Vim|
Chrome开发者工具|
OpenGL|
Unity|
Direct3D|
用户登录
还没有账号?立即注册
用户注册
投稿取消
文章分类: |
|
还能输入300字
上传中....