zoukankan      html  css  js  c++  java
  • unity限帧的正确姿势

    首先 unity上面要做一下手脚

    打开后如下

    接着。。。。

    在Inspector面板

    把V Sync Count 设置为不限制(Don`t Sync)(我们用脚本限制,不然unity自己控制不了它自己,亲测真的)

    Lod Bias设置为2(默认是1,不能用默认)

     

    然后上脚本!如果想整个游戏测试的话!就放在第一个场景吧!

    自己做个TXT把帧率读出来吧!这个这里不说了!太简单!

    上代码:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    
    public class UpdateFrame : MonoBehaviour {
    
        const float fpsMeasurePeriod = 0.5f;    //FPS测量间隔
        private int m_FpsAccumulator = 0;   //帧数累计的数量
        private float m_FpsNextPeriod = 0;  //FPS下一段的间隔
        private int m_CurrentFps;   //当前的帧率
        const string display = "{0} FPS";   //显示的文字
        public Text m_Text;    //UGUI中Text组件
        public int FPS;//限帧
    
        void Awake () {
            Application.targetFrameRate=FPS;
            m_FpsNextPeriod = Time.realtimeSinceStartup + fpsMeasurePeriod; //Time.realtimeSinceStartup获取游戏开始到当前的时间,增加一个测量间隔,计算出下一次帧率计算是要在什么时候
            DontDestroyOnLoad(this.gameObject);//一直显示不销毁!最好放在第一个场景
        }
        private void Update()
        {
            // 测量每一秒的平均帧率
            m_FpsAccumulator++;
            if (Time.realtimeSinceStartup > m_FpsNextPeriod)    //当前时间超过了下一次的计算时间
            {
                m_CurrentFps = (int)(m_FpsAccumulator / fpsMeasurePeriod);   //计算
                m_FpsAccumulator = 0;   //计数器归零
                m_FpsNextPeriod += fpsMeasurePeriod;    //在增加下一次的间隔
                m_Text.text = string.Format(display, m_CurrentFps); //处理一下文字显示
            }
        }
    
    }
    

      

  • 相关阅读:
    使用JQuery+HTML写一个简单的后台登录页面,加上对登录名和密码的前端校验。
    Shiro入门3
    Shiro入门2
    Shiro入门1
    Spring+SpringMVC+Mybatis整合 pom示例
    IO(1)----File类
    集合(3)—— Map
    集合(3)—— Set
    集合(2)——List集合
    集合(1)
  • 原文地址:https://www.cnblogs.com/xxxtony/p/7954624.html
Copyright © 2011-2022 走看看