学习(四):显示FPS,和自定义显示调试
显示FPS
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class ShowFPS : MonoBehaviour {// 固定的一个时间间隔private float time_delta = 0.5f;// Time.realtimeSinceStartup: 指的是我们当前从启动开始到现在运行的时间,单位(s)private float prev_time = 0.0f; // 上一次统计FPS的时间;private float fps = 0.0f; // 计算出来的FPS的值;private int i_frames = 0; // 累计我们刷新的帧数;// GUI显示;private GUIStyle style;void Awake() {// 假设CPU 100% 工作的状态下FPS 300,// 当你设置了这个以后,他就维持在60FPS左右,不会继续冲高;// -1, 游戏引擎就会不段的刷新我们的画面,有多高,刷多高; 60FPS左右;Application.targetFrameRate = 60;}// Use this for initializationvoid Start () {this.prev_time = Time.realtimeSinceStartup;this.style = new GUIStyle();this.style.fontSize = 15;this.style.normal.textColor = new Color(255, 255, 255);}void OnGUI() {GUI.Label(new Rect(0, Screen.height - 20, 200, 200), "FPS:" + this.fps.ToString("f2"), this.style);}// Update is called once per frame// 每次游戏刷新的时候就会调用;void Update () {this.i_frames ++;if (Time.realtimeSinceStartup >= this.prev_time + this.time_delta) {this.fps = ((float)this.i_frames) / (Time.realtimeSinceStartup - this.prev_time);this.prev_time = Time.realtimeSinceStartup;this.i_frames = 0; // 重新累积我们的FPS}}
}
显示log,自定义logo,方便手机打印
#define USE_DEBUG using UnityEngine;
using System;
using System.Collections.Generic;#if RELEASE_BUILD
//发布的时候重载默认Debug
public static class Debug
{public static void Log(object message) { }public static void Log(object message, object context) { }public static void LogError(object message) { }public static void LogError(object message, object context) { }public static void LogException(Exception exception) { }public static void LogException(Exception exception, object context) { }public static void LogWarning(object message) { }public static void LogWarning(object message, object context) { }public static void DrawLine(Vector3 start, Vector3 end) { }public static void DrawLine(Vector3 start, Vector3 end, Color color) { }
}
#endif//重载默认Debug
public static class Debugger
{public static void Log(object message){#if RELEASE_BUILD#elseif (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer)DebugManager.Log(0,message.ToString());elseUnityEngine.Debug.Log(message.ToString());#endif}public static void LogError(object message){#if RELEASE_BUILD#elseif (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer)DebugManager.Log(2,message.ToString());elseUnityEngine.Debug.LogError(message.ToString());#endif}public static void LogWarning(object message){#if RELEASE_BUILD#elseif (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer)DebugManager.Log(1,message.ToString());elseUnityEngine.Debug.LogWarning(message.ToString());#endif}
}//[yaz]调试管理器
public class DebugManager : MonoBehaviour
{public class DebugMessage{public int type;public string message;}// public bool DebugEffect = false;static public bool DebugInfo = false;static public Int32 DebugCount = 0;//保存错误信息列表static public List<DebugMessage> errorInfoList = new List<DebugMessage>();// Use this for initializationvoid Start (){Log(0, "Log");Log(1, "LogWarning");Log(2, "LogError");}// Update is called once per framevoid Update () {}public static void Switch(){DebugInfo = !DebugInfo;if (DebugInfo){++DebugCount;errorInfoList.Clear();//errorInfoList.Add(DebugCount.ToString());}}public static void Log(int type,string str){DebugMessage debug = new DebugMessage();debug.type = type;debug.message = str;errorInfoList.Add(debug);}//错误信息窗口public Rect errorInfoWindowRect = new Rect(80, 20, 800, 2000);void OnGUI(){GUILayout.Space(40);if (GUILayout.Button("ShowError")){DebugInfo = !DebugInfo;}else if (GUILayout.Button("Clear")){errorInfoList.Clear();}//调试错误信息if (DebugInfo){errorInfoWindowRect = GUILayout.Window(1, errorInfoWindowRect, DebugErrorWindow, "Debug Error Window"); }}//错误信息显示窗口private Vector2 errorInfoPos = new Vector2(0, 0);void DebugErrorWindow(int windowID){ errorInfoPos = GUILayout.BeginScrollView(errorInfoPos, false, true, GUILayout.Width(800), GUILayout.Height(2000));GUILayout.Space(30);GUILayout.BeginVertical();foreach (DebugMessage debug in errorInfoList){if (debug.type==2){GUI.color = Color.red;}else if (debug.type == 1){GUI.color = Color.yellow;}else{GUI.color = Color.white;}GUILayout.Label(debug.message, GUILayout.Width(800));}//GUI.color = Color.white;GUILayout.EndVertical();GUILayout.EndScrollView();}}
学习(四):显示FPS,和自定义显示调试相关推荐
- LCD12864 液晶显示-汉字及自定义显示(串口)
在网上找了许久,发现FPGA用串口驱动LCD12864程序很少,基本上没有.刚开始窃喜,中间郁闷,最后还是高兴,为什么这样说呢!头一回在没有参考程序的情况下,完全是照时序图写(自信),中间调试过程遇到 ...
- HTML5游戏开发(四):飞机大战之显示场景和元素
<HTML5游戏开发>系列文章的目的有:一.以最小的成本去入门egret小项目开发,官方的教程一直都是面向中重型:二.egret可以非常轻量:三.egret相比PIXI.js和sprite ...
- Android 自定义带图标Toast,工具方法,Toast自定义显示时间
带图标Toast工具方法1 样式 <?xml version="1.0" encoding="utf-8"?> <shape xmlns:an ...
- 迪文屏幕T5UID3平台学习笔记二:变量图标显示和按键返回值按钮学习
需要实现一个功能:当点击某个按钮时候,要求能够改变按钮的字体和颜色,比如: 点击strat按钮后,显示stop,这样再点击就实现Stop逻辑,同时显示变成Start,也 就是说把Start和Stop按 ...
- Tableau(5):符号地图、仪表盘、自定义显示
文章目录 一.符号地图 二.仪表板 三.自定义显示 参考资料 一.符号地图 步骤1:导入全球超市订单数据 步骤2: 步骤3:一共有四种方式,图片中显示两种,剩下两种基本上不会用到,没 ...
- 关于csgo的观看录像fps低_CSGO怎么查看fps CSGO显示fps参数命令与设置方法_3DM单机...
CSGO怎么查看fps CSGO显示fps参数命令与设置方法 在CSGO中,fps.ping.丢包率都有着各自的作用,很多玩家为了提高自己会想要显示这些数据. CSGOfps.ping.丢包率作用 帧 ...
- android toast 自定义时间,Android Toast自定义显示时间
Toast是Android中使用频率较高的弹窗提示手段,使用起来简单.方便.常规使用方法这里不做说明,继前一篇博客<Android中Toast全屏显示> ,其中抛砖引玉的给出一个简单的实现 ...
- TF之CNN:利用sklearn(自带手写数字图片识别数据集)使用dropout解决学习中overfitting的问题+Tensorboard显示变化曲线
TF之CNN:利用sklearn(自带手写数字图片识别数据集)使用dropout解决学习中overfitting的问题+Tensorboard显示变化曲线 目录 输出结果 设计代码 输出结果 设计代码 ...
- pdfstamper生成pdf无法显示汉字_正点原子STM32F4/F7水星开发板资料连载第四十六章 汉字显示实验...
1)实验平台:正点原子水星 STM32F4/F7 开发板 2)摘自<STM32F7 开发指南(HAL 库版)>关注官方微信号公众号,获取更多资料:正点原子 3)全套实验源码+手册+视频下载 ...
- SharePoint 2013 关于自定义显示列表表单的bug
1.在SharePoint 2013中,我们隐藏列表Dispform页面的ListFormWebPart部件,转而使用自定义显示列表表单进行展示,因为这样更容易定制我们需要的显示: 2.之后发现文件夹 ...
最新文章
- 你需要知道的高性能并发框架Disruptor原理
- Zookeeper迁移(扩容/缩容)
- java 一元一次方程求解_七年级一元一次方程概念和解法,掌握这些就够了!
- AdventureWorksDW 2019还原图解
- python 列表写入excel_Python将MySQL表数据写入excel
- mysql+after+commit_Spring事务aftercommit原理及实践
- 外星人入侵游戏--python实战 (附完整代码)
- 拼写检查工具是android,拼写检查工具框架 | Android 开发者 | Android Developers...
- VMware中安装Centos 7
- svn上传时显示database is locked
- .net java xml_java.net.MalformedURLException – 在通过StAX解析XML文件时
- Centos之故障排除
- html微信窗口阻止滚动条,微信浏览器禁止页面下拉查看网址(不影响页面内部scroll)...
- 回调函数与回调地狱及其解决方法 | JavaScript
- 手把手教你搭建Nightingale夜莺监控系统
- 虚拟机Hadoop localhost:8080无法打开解决办法
- 006.UG_NX实体造型功能
- 【C语言|菜鸟教程】100道进阶经典例题详细解答(实例二)
- 开个代理记账公司是否有前途
- 翻译英语的软件-免费翻译软件-各种语言互相翻译
热门文章
- 【PS】443种逼真度超高水彩笔刷打包下载
- wacom数位板怎么调压感_怎么设置PS的画笔利用到数位板压感?
- 利息浅谈(五)——我的投资收益率怎么算?
- 机器翻译之人工智能方法
- 阿里开源互动游戏引擎Eva.js
- Mysql—— order 和 limit 的用法
- PhantomJS not found on PATH
- Ubuntu Vmware虚拟机网络配置(一)
- CodeForces Round#524B - Margarite and the best present (前缀和)
- ubuntu命令行启动浏览器_如何从终端启动默认Web浏览器?