当前位置: 首页 > news >正文

Unity | 发布Android的那些事儿

1.使用UnityWebRequest获取StreamingAssets中的json文件

(1)直接根据不同平台指定url路径

    IEnumerator AITalPredZhanHui(){string url;string fileName = "girl.json";
#if UNITY_EDITOR || UNITY_STANDALONEurl = "file://" + Application.dataPath + "/StreamingAssets/" + fileName;
#elif UNITY_IPHONEurl = "file://" + Application.dataPath + "/Raw/"+ fileName;
#elif UNITY_ANDROIDurl = "jar:file://" + Application.dataPath + "!/assets/"+ fileName;
#endifDebug.Log(url);using (UnityWebRequest w = UnityWebRequest.Get(url)){yield return w.SendWebRequest();if (w.isNetworkError || w.isHttpError){Debug.Log("加载失败");}else{sdkMsg = JsonConvert.DeserializeObject<SDKData>(w.downloadHandler.text);//...}}}

(2)运用System.Uri类

System.Uri这个类,这个类可以帮助我们更具不同平台更好的构造uri,特别是在使用本地路径得时候,结合Path.Combine能更好的得出Uri路径。因为平台的区别,Uri路径也不同。

var uri = new System.Uri(Path.Combine(Application.streamingAssetsPath, "girl.json"));
Debug.Log(uri);

以上两种方式在Android端得到的路径相同:jar:file:///data/app/com.DefaultCompany.AndroidTest-ZQ5hoVVjvdSWV_n-_xw2lQ==/base.apk!/assets/girl.json

2.帧率设置

官方文档中有下述描述:

-All mobile platforms have a fix cap for their maximum achievable frame rate, that is equal to the refresh rate of the screen (60 Hz = 60 fps, 40 Hz = 40 fps, ...). Screen.currentResolution contains the screen's refresh rate.

- Additionally, all mobile platforms can only display frames on a VBlank. Therefore, you should set the targetFrameRate to either -1, or a value equal to the screen's refresh rate, or the refresh rate divided by an integer. Otherwise, the resulting frame rate is always lower than targetFrameRate. Note: If you set the targetFrameRate to the refresh rate divided by an integer, the integer division leads to the same effective fps as setting QualitySettings.vSyncCount to the same value as that integer.

翻译下来就是:

所有移动平台都有其最大可实现帧速率的固定上限,即等于屏幕的刷新率(Screen.currentResolution)(60 Hz = 60 fps,40 Hz = 40 fps,...)。Screen.currentResolution包含屏幕的刷新率。

此外,所有移动平台只能在VBlank上显示帧。因此,应该将targetFrameRate设置为 -1、或者等于屏幕刷新率的值、或者刷新率除以一个整数得到的值。否则,生成的帧速率始终低targetFrameRate。注意:如果将targetFrameRate设置为刷新率除以整数,则整数除法导致的有效 fps 与将QualitySettings.vSyncCount设置为与该整数相同的值的效果相同。

举个例子:

我们通过下方代码获取到Android设备的屏幕刷新率为60HZ,那么我们通过Application.targetFrameRate只能是60、30、20、15、12、10FPS,如果我们设置为25,则真实的fps为20。

RefreshRate rate = Screen.currentResolution.refreshRateRatio;
http://www.lryc.cn/news/42920.html

相关文章:

  • git为什么要先commit,然后pull,最后再push?而不是commit完直接push?
  • 若依框架----源码分析(@RateLimiter)
  • 页面的重排和重绘?
  • 人脸检测-python和c++实现
  • PowerJob源码环境搭建
  • 天梯赛刷题小记 —— L2
  • Prometheus监控实战系列十九:监控Kubernetes集群(上)
  • 番茄学习法——亲测超级好用
  • vue 项目中使用高德地图
  • 【每日一题】病人排队
  • 【数据结构】链表OJ题
  • 冒泡 VS 插入 VS 选择——谁更胜一筹?(附排序源码)
  • [python tools] 今天看到另一个配置工具 YACS,所以做下笔记
  • Prometheus cadvisor容器监控和node-exporter节点监控
  • 机器学习|正则化|评估方法|分类模型性能评价指标|吴恩达学习笔记
  • python迭代器详解
  • 关于Docker逃逸
  • @Autowired和@Resource区别
  • 动态内存管理详细讲解
  • Python和Excel的完美结合:常用操作汇总(案例详析)
  • 卡特兰数、斯特林数基础
  • STL——mapmultimap和setmultiset
  • 2023热门抖音权重查询小程序源码
  • 153.网络安全渗透测试—[Cobalt Strike系列]—[生成hta/exe/宏后门]
  • 如何成为优秀的程序员
  • 多线程(四):线程安全
  • [ROC-RK3568-PC] [Firefly-Android] 10min带你了解Camera的使用
  • C++之模拟实现string
  • SpringBoot实战(十三)集成 Admin
  • mke2fs命令:建立ext2文件系统