Unity从外部读取txt文件

unity 从StreamingAssets文件夹内读取文件并,需在Assets文件夹下创建StreamingAssets文件夹,将txt配置文件放在StreamingAssets文件夹中。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//读取配置文件
private string ReadStreamingAsset(string fileName)
{
string result = "";
string path = Application.streamingAssetsPath + "/" + fileName;

if (File.Exists(path))
{
StreamReader reader = new StreamReader(path);
result = reader.ReadToEnd();
reader.Close();
}

return result;
}

Unity从外部读取txt文件
https://blog.966677.xyz/2025/03/02/Unity从外部读取txt文件/
作者
Zhou1317fe5
发布于
2025年3月2日
许可协议