【发布时间】:2017-09-27 08:09:54
【问题描述】:
在我正在处理的项目中,StreamingAssets 目录中有两个 json 文件。处理它们的脚本在独立 PC 版本中完美运行,但在 WebGL 版本中根本不起作用。
我收到“找不到文件!”根据脚本消息:
else if (!File.Exists (filePath))
{
Debug.LogError ("Cannot find file!");
}
我得到了使用 WWW 类的答案,如 Unity Technologies 网站上的脚本 API 中所述,地址为:https://docs.unity3d.com/ScriptReference/Application-streamingAssetsPath.html
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
public string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, "MyFile");
public string result = "";
IEnumerator Example() {
if (filePath.Contains("://")) {
WWW www = new WWW(filePath);
yield return www;
result = www.text;
} else
result = System.IO.File.ReadAllText(filePath);
}
}
我很乐意这样做,但我对编码太陌生了,我需要一些解释。我现在的第一个问题是:行中的 "my file" 字符串是什么
public string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, "MyFile");
我应该在那里写什么?是网址吗?而如果是url,那么url是什么?
如果有人能握住我的手并引导我理解这一点,我将不胜感激!谢谢!
(这是我在这里的第一个问题;我希望我没有犯错,因为我还不知道这个地方是如何运作的。)
【问题讨论】:
标签: c# json unity3d unity-webgl