zoukankan      html  css  js  c++  java
  • Unity3D FPS帧数修改

    修改Unity的FPS

    FPS是游戏运行的帧数,本文讲解如何修改Unity引擎的FPS。

    步骤

    1、在 Edit/Project Settings/Quality  质量设置里把帧数设定关闭,关闭之后才能在代码中修改游戏运行的帧数。

    image

    UpdateFrame.cs

    2、在Unity中创建新脚本UpdateFrame.cs ,代码

    using UnityEngine;
    using System.Collections;
    
    /// <summary>
    /// 功能:修改游戏FPS
    /// </summary>
    public class UpdateFrame : MonoBehaviour
    {
        //游戏的FPS,可在属性窗口中修改
        public int targetFrameRate = 300;
        
        //当程序唤醒时
        void Awake ()
        {
            //修改当前的FPS
            Application.targetFrameRate = targetFrameRate;
        }
        
    }

    3、把该代码及ShowFPS.js绑定在层次视图的任一GameObject上

    尝试修改

    4、运行游戏,即可以Game视图中看到当前的FPS修改targetFrameRate变量,查看FPS的变化

    ShowFPS.js

    @script ExecuteInEditMode
    
    private var gui : GUIText;
    
    private var updateInterval = 1.0;
    private var lastInterval : double; // Last interval end time
    private var frames = 0; // Frames over current interval
    
    function Start()
    {
        lastInterval = Time.realtimeSinceStartup;
        frames = 0;
    }
    
    function OnDisable ()
    {
        if (gui)
            DestroyImmediate (gui.gameObject);
    }
    
    function Update()
    {
    #if !UNITY_FLASH
        ++frames;
        var timeNow = Time.realtimeSinceStartup;
        if (timeNow > lastInterval + updateInterval)
        {
            if (!gui)
            {
                var go : GameObject = new GameObject("FPS Display", GUIText);
                go.hideFlags = HideFlags.HideAndDontSave;
                go.transform.position = Vector3(0,0,0);
                gui = go.guiText;
                gui.pixelOffset = Vector2(5,55);
            }
            var fps : float = frames / (timeNow - lastInterval);
            var ms : float = 1000.0f / Mathf.Max (fps, 0.00001);
            gui.text = ms.ToString("f1") + "ms " + fps.ToString("f2") + "FPS";
            frames = 0;
            lastInterval = timeNow;
        }
    #endif
    }
  • 相关阅读:
    一起ORA-00028案例的处理过程
    Preferences偏好设置
    Snap Settings对齐设置
    Graphics Emulation图形模拟
    Network Emulation(网格模拟)
    Selection
    Edit编辑
    Build Settings 构建设置
    Player Settings-PC
    Build Settings发布设置
  • 原文地址:https://www.cnblogs.com/zhaoqingqing/p/3296143.html
Copyright © 2011-2022 走看看