Unity发布到IOS平台的游戏PFS如何突破30帧的锁定

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

 

 

 

 

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值