当前位置:网站首页>Unity3d multi platform method for reading text files in streamingasset directory
Unity3d multi platform method for reading text files in streamingasset directory
2022-06-12 06:04:00 【VR technology Xiaoguang】
because StreamingAsset The catalogue is in androway IOS Next , The way of packing is different , The file reading method is different .
The following functions , Tested repeatedly , You can read text files of all platforms .
// Support multi platform text file reading
public static string GetFileStr(string path)
{
string jsonStr = "";
#if UNITY_ANDROID || UNITY_IOS
jsonStr = GetStreamingPathStr(path);
#else
jsonStr = FileRead(path);
#endif
return jsonStr;
}
public static string GetStreamingPathStr(string path)
{
string fileStr = "";
var uri = new System.Uri(path);
var request = UnityWebRequest.Get(uri);
var www = request.SendWebRequest();
if (request.isNetworkError || request.isNetworkError)
{
MyLog.log.Debug(request.error);
}
else
{
while (true)
{
if (!request.isDone) continue;
fileStr = request.downloadHandler.text;
break;
}
}
return fileStr;
}
public static string FileRead(string path)
{
StreamReader sr = File.OpenText(path);
// Read to end of file
string str = sr.ReadToEnd();
sr.Close();
sr.Dispose();
return str;
}
边栏推荐
猜你喜欢

Introduction to thread pool: ThreadPoolExecutor

Introduction to sringmvc

Project and build Publishing

Execute sh script to prompt "[[: not found" solution. The difference between Bash and sh

Review notes of naturallanguageprocessing based on deep learning

2D human pose estimation for pose estimation - pifpaf:composite fields for human pose estimation

Simple spiral ladder generation for Houdini program modeling
![[PowerShell] command line output and adding system environment variables](/img/49/b92175181aa4a3fddfa3adcacf1d72.jpg)
[PowerShell] command line output and adding system environment variables

EBook upload

IO stream introduction
随机推荐
IBL of directx11 advanced tutorial PBR (3)
[PowerShell] command line output and adding system environment variables
[C language basics] macro definition usage
C WMI query remote Win32_ Operatingsystem class
Guns框架多数据源配置,不修改配置文件
Chapter 8 - structure
肝了一个月的 DDD,一文带你掌握
JS预解析
IDEA常用配置
Why don't databases use hash tables?
Leetcode buckle -10 Regular expression matching analysis [recursion and dynamic programming]
nus_data_handler源码解读结构体等数据类型
Understanding of distributed transactions
Leetcode sword finger offer II 119 Longest continuous sequence
MySQL notes
Leetcode-1260. 2D mesh migration
Es6-es11 learning
Leetcode-646. Longest number pair chain
Leetcode-1043. Separate arrays for maximum sum
Getting started with houdininengine HDA and UE4