当前位置:网站首页>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;
}
边栏推荐
- [untitled]
- Image processing: image[:,:,:: -1], image[:,: -1,:], image[:,: -1,:]
- Introduction to thread pool: ThreadPoolExecutor
- 数据库为什么不使用hash表?
- Database Experiment 2: data update
- Research Report on water sports shoes industry - market status analysis and development prospect forecast
- json-c常用API
- 项目开发流程简单介绍
- Why is the union index the leftmost matching principle?
- Leetcode dynamic programming
猜你喜欢

Review notes of naturallanguageprocessing based on deep learning

Front desk display LED number (number type on calculator)

Redis persistence

Poisson disk sampling for procedural placement

Unable to access this account. You may need to update your password or grant the account permission to synchronize to this device. Tencent corporate email

Tabulation skills and matrix processing skills

A month's worth of DDD will help you master it

The application could not be installed: INSTALL_FAILED_TEST_ONLY

User login 【 I 】

Why doesn't the database use binary tree, red black tree, B tree and hash table? Instead, a b+ tree is used
随机推荐
First note
Leetcode-646. Longest number pair chain
Research Report on truffle fungus industry - market status analysis and development prospect forecast
Leetcode-1260. 2D mesh migration
Why is the union index the leftmost matching principle?
IO system - code example
Es6-es11 learning
MySQL notes
Data integration framework seatunnel learning notes
Flutter monitors application lifecycle status
BRDF of directx11 advanced tutorial PBR (2)
Heap classical problem
Une explication du 80e match bihebdomadaire de leetcode
How to split a row of data into multiple rows in Informix database
单通道图片的读入
[C language basics] macro definition usage
Performance optimization metrics and tools
Recursive implementation of exponential, permutation and combination enumerations
[untitled]
Multiple ways 99.9% to solve the problem of garbled code after copying text from PDF