http://blog.youkuaiyun.com/yhy2218/article/details/50789711
直接放在Resource文件下的数据是不可读的。用streamingAssets才可以
或者Application.datapath后 在Raw文件夹下读取流资源
https://docs.unity3d.com/ScriptReference/Application-streamingAssetsPath.html
https://docs.unity3d.com/ScriptReference/Application-dataPath.html
https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html
读写权限
eg:
在游戏中的数据文件,我是写在excel表格中,然后用python把它读出来 然后写成一个Json文件的。
读取这个json文件时候,可以把它放在StreamingAssets目录下去读取
public void parseJsonFromLocal() {
string jsonPath = Application.streamingAssetsPath + "/data.json";
if (!File.Exists(jsonPath)) {
Debug.Log("~~~~~~~~ json dosent exist " + jsonPath) ;
return ;
}
StreamReader str = new StreamReader(jsonPath);
if (str == null) {
Debug.Log("~~~~~~~~ stream reader error" );
return ;
}
string json = str.ReadToEnd();
// Debug.Log("~~~~~~~~ data json is " + json) ;
if (json.Length 0) {
m_localAllData = JsonUtility.FromJson<LocalDataCollection>(json);
// Debug.Log("~~~~~~~~ data json is " + json) ;
}
}