当前位置:网站首页>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;
}
边栏推荐
- China's elastic belt market trend report, technical dynamic innovation and market forecast
- nus_ data_ Handler source code interprets data types such as structure
- Brief summary of software project architecture
- (UE4 4.27) customize globalshader
- Three years of sharpening a sword: insight into the R & D efficiency of ant financial services
- C WMI query remote Win32_ Operatingsystem class
- Heap classical problem
- Review notes of naturallanguageprocessing based on deep learning
- IO stream introduction
- Error the main class com xxx. yyy. Application
猜你喜欢

Houdini script vex learning

Redis cache data consistency and problems

(UE4 4.27) customize globalshader

Un mois de DDD hépatique.

Leetcode-1260. 2D mesh migration

Introduction to sringmvc

Leetcode-1535. Find the winner of the array game

Directx11 advanced tutorial cluster based deffered shading

EBook list page

BlockingQueue interface introduction
随机推荐
sqlite交叉编译动态库
EBook list page
肝了一个月的 DDD,一文带你掌握
Guns框架多数据源配置,不修改配置文件
项目管理与统筹
Front desk display LED number (number type on calculator)
Market trend report, technical innovation and market forecast of Chinese stump crusher
Redis memory obsolescence strategy
Chapter 8 - structure
nRF52832自定義服務與特性
nrf52832--官方例程ble_app_uart添加led特性,实现电脑uart和手机app控制开发板led开和关
[untitled]
Automatic annotation of target detection based on lffd model to generate XML file
Glossary of Chinese and English terms for pressure sensors
Redis cache data consistency and problems
Un mois de DDD hépatique.
A month's worth of DDD will help you master it
MySQL notes
Data integration framework seatunnel learning notes
交叉编译libev