XML 文件未包含在 WebGL 构建中
XML file not included in WebGL Build
我正在尝试为 WebGL 平台构建我的游戏。我的游戏从位于项目根文件夹中的 XML 文件获取数据。它在编辑器中工作正常,如果为 Windows 构建也是如此。但是当我为 WebGL 构建游戏时,游戏无法正常运行,控制台显示:IsolatedStorageException: Could not find file "/Words.xml".
这是我用来读取文件的代码:
public List<string> Words = new List<string>();
public void SetWords ()
{
using (XmlReader reader = XmlReader.Create("Words.xml"))
{
while (reader.Read())
{
if (reader.Name == "word") Words.Add(reader.ReadString());
}
}
}
您应该将文件放在 Assets 文件夹中。
在脚本中定义一个 TextAsset 字段,然后将 xml 文件拖到它上面。
public TextAsset xmlfile;
void SomeMethod()
{
var reader = XmlReader.Create(new MemoryStream(xmlfile.bytes));
}
我正在尝试为 WebGL 平台构建我的游戏。我的游戏从位于项目根文件夹中的 XML 文件获取数据。它在编辑器中工作正常,如果为 Windows 构建也是如此。但是当我为 WebGL 构建游戏时,游戏无法正常运行,控制台显示:IsolatedStorageException: Could not find file "/Words.xml".
这是我用来读取文件的代码:
public List<string> Words = new List<string>();
public void SetWords ()
{
using (XmlReader reader = XmlReader.Create("Words.xml"))
{
while (reader.Read())
{
if (reader.Name == "word") Words.Add(reader.ReadString());
}
}
}
您应该将文件放在 Assets 文件夹中。
在脚本中定义一个 TextAsset 字段,然后将 xml 文件拖到它上面。
public TextAsset xmlfile;
void SomeMethod()
{
var reader = XmlReader.Create(new MemoryStream(xmlfile.bytes));
}