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

unity 增加系统时间显示、FPS帧率、ms延迟

代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;using UnityEngine;public class Frame : MonoBehaviour
{// 记录帧数private int _frame;// 上一次计算帧率的时间private float _lastTime;// 平均每一帧的时间private float _frameDeltaTime;// 间隔多长时间(秒)计算一次帧率private float _Fps;private const float _timeInterval = 0.5f;void Start(){_lastTime = Time.realtimeSinceStartup;}void Update(){FrameCalculate();}private void FrameCalculate(){_frame++;if (Time.realtimeSinceStartup - _lastTime < _timeInterval){return;}float time = Time.realtimeSinceStartup - _lastTime;_Fps = _frame / time;_frameDeltaTime = time / _frame;_lastTime = Time.realtimeSinceStartup;_frame = 0;}private void OnGUI(){string msg = string.Format("<color=red><size=30>FPS:{0}   ms:{1}</size></color>",(int) _Fps , (int)(_frameDeltaTime *1000));GUI.Label(new Rect(Screen.width-230, 0, 500, 150), msg);var timeNow = System.DateTime.Now;string time = string.Format("<color=green><size=30>{0}</size></color>", timeNow);GUI.Label(new Rect(Screen.width/2-200, 2, 600, 50), time);}
}

将脚本挂载到相机上面

在这里插入图片描述

效果

在这里插入图片描述

http://www.lryc.cn/news/295081.html

相关文章:

  • 【Python基础】文件详解(文件基础、csv文件、时间处理、目录处理、excel文件、jsonpicke、ini配置文件)
  • [UI5 常用控件] 05.FlexBox, VBox,HBox,HorizontalLayout,VerticalLayout
  • Unity类银河恶魔城学习记录1-14 AttackDirection源代码 P41
  • DataX详解和架构介绍
  • 02.05
  • 【C语言】贪吃蛇 详解
  • Mysql MGR搭建
  • 新火种AI|寒武纪跌落神坛!七年连亏50亿,AI芯片第一股不行了吗?
  • three.js CSS3DObject、CSS2DObject、CSS3DSprite、Sprite的作为标签的区别
  • 第7节、双电机直线运动【51单片机+L298N步进电机系列教程】
  • 【C语言 - 哈希表 - 力扣 - 相交链表】
  • C++参悟:内存管理-unique_ptr
  • 【征稿已开启】第五大数据、人工智能与软件工程国际研讨会(ICBASE 2024)
  • Vue3父子组件传参
  • SpringBoot整理-微服务
  • 服务器和CDN推荐
  • c#读取csv文件中的某一列的数据
  • 不懂快团团大团长对接?凭什么快团团的钱轮到你赚?
  • OpenGL 入门(九)—Material(材质)和 光照贴图
  • jmeter-03界面介绍
  • 探究 MySQL 中使用 where 1=1 是否存在性能影响
  • VSCode无法启动:Waiting for server log...
  • VMware虚拟机清理瘦身
  • Coil:Android上基于Kotlin协程的超级图片加载库
  • 时间序列(Time-Series)MultiWaveletCorrelation.py代码解析
  • C++的缺省参数和函数重载
  • nginx upstream server主动健康检测模块ngx_http_upstream_check_module 使用和源码分析(上)
  • 第01课:自动驾驶概述
  • Docker进阶篇-CIG重量级监控系统
  • 鸿蒙踩坑合集