• Unity OnGUI调试工具


    背景

            在产品开发过程中调试数据是必不可少的过程之一,那么涉及到频繁的设置数据、运行unity等一系列繁琐的操作,有没有更好的办法呢?答案是肯定有更好的办法。这里我所用到的是unity自带的OnGUI相关的工具可以实时的更改数据调试。

    代码

    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using RapidGUI;
    5. using UnityEngine;
    6. public class DebugTool : MonoBehaviour
    7. {
    8. private WindowLaunchers _debugWindows;
    9. private Rect _mainRect = new Rect(10, 10, 600, 800);
    10. private Vector2 _scrollRect;
    11. private bool isShow = false;
    12. private Vector2 _scrollViews = Vector2.zero;
    13. private void Start()
    14. {
    15. _debugWindows = new WindowLaunchers() { isWindow = false};
    16. InitWondow();
    17. }
    18. private float _value = 0;
    19. private void InitWondow()
    20. {
    21. _debugWindows.Add("调试slider", () =>
    22. {
    23. _value = RGUI.Slider(_value, 0, 1, "slider的数值");
    24. });
    25. _debugWindows.Add("调试button", () =>
    26. {
    27. if (GUILayout.Button("button1")) {
    28. Debug.LogError("this is button1");
    29. }
    30. if (GUILayout.Button("button2")) {
    31. Debug.LogError("this is button2");
    32. }
    33. });
    34. _debugWindows.Add("调试text", () =>
    35. {
    36. RGUI.Field(0, "文本显示");
    37. });
    38. _debugWindows.Add("调试ScrollView", () =>
    39. {
    40. _scrollViews =
    41. GUILayout.BeginScrollView(_scrollViews, GUILayout.Width(1200), GUILayout.Height(600));
    42. foreach (var item in tasks) {
    43. float progress = 0f;
    44. if (item.Status != DownLoadTaskStatus.Downloading &&
    45. item.Status != DownLoadTaskStatus.RemoteDownloading) {
    46. progress = 0f;
    47. }
    48. else if (item.Status == DownLoadTaskStatus.Downloading) {
    49. progress = (float)item.DownloadSize / (float)item.TotalSize;
    50. }
    51. else {
    52. progress = (float)item.RemoteDownloadSize / (float)item.TotalSize;
    53. }
    54. RGUI.Slider(progress, 0f, 1.0f,
    55. $"{item.Desc} [状态:{item.Status}] 速度:{StringUtils.FormatSize(item.Speed)}/秒");
    56. }
    57. GUILayout.EndScrollView();
    58. });
    59. }
    60. private void Update()
    61. {
    62. if (Input.GetKeyDown(KeyCode.F1))
    63. {
    64. isShow = !isShow;
    65. }
    66. }
    67. private void OnGUI()
    68. {
    69. if (!isShow) return;
    70. _mainRect = GUI.Window(0, _mainRect, (id) =>
    71. {
    72. _scrollRect = GUILayout.BeginScrollView(_scrollRect, false, true, GUILayout.Width(600),
    73. GUILayout.Height(800));
    74. GUILayout.BeginVertical(GUILayout.Width(600), GUILayout.Height(800));
    75. _debugWindows.DoGUI();
    76. GUILayout.Space(20);
    77. GUILayout.EndVertical();
    78. GUILayout.EndScrollView();
    79. },"调试窗口");
    80. }
    81. }

    效果

    代码链接

                    https://download.csdn.net/download/ThreePointsHeat/88463003

  • 相关阅读:
    【IC设计】NoC(Network on Chip)调研
    Vue中的路由守卫
    官网删除「儿童性虐待内容检测方案」,但苹果仍未放弃该计划
    IT部门全被裁?不懂业务,花了几百万开发的报表系统,根本没人看
    3D感知(一):初步认识
    Win11磁盘分区后在恢复之前分区的方法介绍
    iptables使用详解
    【学习记录】tensorflow图像数据增强
    vue+leaflet集成echarts实现动态轨迹图
    在 Elasticsearch 中丰富你的 Elasticsearch 文档
  • 原文地址:https://blog.csdn.net/ThreePointsHeat/article/details/133995003