Unity发布到IOS平台的游戏PFS如何突破30帧的锁定
http://doc.okbase.net/qihaowutong/archive/182515.html
问题情况:
打包项目Demo到IP5,挂上帧频显现脚本发现一最高帧频只有30,因为是性能测试的Demon,所以必须在IOS上跑到60帧的时候才能明显的看出性能测试的demo的效果
Unity中关于帧频的设置:
在Editor->Project Setting ->Quality中有垂直同步的设置。Dont sync 则会根据程序中application.targetFrameRate 中的数值进行设置。Every V Blank 60帧。Every Second V Blenk 30帧。

在IOS打包的Player setting 中也有相应的帧频设置

解决方案:
虽然上述两者中均有对帧频的设置,但是在打包IOS应用的时候依旧是30FPS最高。
在旧版本的Unity中,按照如下步骤
1. Application.targetFrameRate = -1 (默认值) 下Build, 生成 XCode 项目
2. 在XCode项目中可以看到自动生成的AppContorller.mm中 kFPS 被宏定义为 30.0。 将它改成60.0。
3. Unity 中重新Build, 在覆盖先前结果时选择 "Expand" 。 (或者直接Build ^ Run,Unity会默认的进行Merge)
在unity5.2.1f1到处的Xcode项目的UnityAppController.mm中,可以看到文件说明中已经移除了对KFPS的设置。所以直接在脚本中设置Applocation.targetFrameRate就可以了。
附上写的一个显示PFS信息的小脚本。挂到GameObject上即可。
using UnityEngine;
using System.Collections;
using System.Text;
//显示FPS的组件,用OnGUI新式,不用GUIText,因为那个是过时的
//性能检测器,输出各种信息
public class FPS : MonoBehaviour
{
float nextTime;
int frameCount;
int fps=0;
//MemInfo memInfo;
void Awake(){
Application.targetFrameRate = 60;
}
void Start (){
nextTime=Time.realtimeSinceStartup+1;
frameCount=0;
}
void Update (){
//memInfo.GetMemoryInfo();
frameCount++;
if(Time.realtimeSinceStartup>nextTime){
fps=frameCount;
frameCount=0;
nextTime=Time.realtimeSinceStartup+1;
}
}
void OnGUI(){
GUI.color=Color.green;
string s="fps:"+fps
+" mus:"+(Profiler.GetMonoUsedSize()/1024/1024).ToString("000")+"M"
+" mhs:"+(Profiler.GetMonoHeapSize()/1024/1024).ToString("000")+"M"
+" uhs:"+(Profiler.usedHeapSize/1024/1024).ToString("000")+"M";
//+"---"+memInfo.VmRss+"---";
int w=300;
GUI.Label(new Rect(Screen.width-w,10,w,40),s);
}
}
原文链接:http://www.cnblogs.com/qihaowutong/p/4864519.html
|