我是靠谱客的博主 忧心花瓣,这篇文章主要介绍Unity Editor自定义一个记录Bug的窗口,现在分享给大家,希望可以做个参考。

直接上代码:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System.Collections; using System.IO; using UnityEditor; using UnityEditor.SceneManagement; using UnityEngine; public class MyFirstWindow : EditorWindow { string bugReporterName = ""; string description = ""; GameObject buggyGameobject; MyFirstWindow() { this.titleContent = new GUIContent("Bug Reporter"); } [MenuItem("Tool/Bug Reporter")] static void ShowWindow() { EditorWindow.GetWindow(typeof(MyFirstWindow)); } void OnGUI() { EditorGUILayout.BeginVertical(); GUILayout.Space(10); GUI.skin.label.fontSize = 24; GUI.skin.label.alignment = TextAnchor.MiddleCenter; GUILayout.Label("Bug Reporter"); GUILayout.Space(10); bugReporterName = EditorGUILayout.TextField("Bug Name", bugReporterName); GUILayout.Space(10); GUI.skin.label.fontSize = 12; GUI.skin.label.alignment = TextAnchor.UpperLeft; GUILayout.Label("Currently Scene:" + EditorSceneManager.GetActiveScene().name); GUILayout.Space(10); GUILayout.Label("Time:" + System.DateTime.Now); GUILayout.Space(10); buggyGameobject = (GameObject)EditorGUILayout.ObjectField("Buggy Gameobject", buggyGameobject, typeof(GameObject), true); GUILayout.Space(10); GUILayout.BeginHorizontal(); GUILayout.Label("Description", GUILayout.MaxWidth(80)); description = EditorGUILayout.TextArea(description, GUILayout.MaxHeight(50)); GUILayout.EndHorizontal(); EditorGUILayout.Space(); if (GUILayout.Button("Save Bug")) { SaveBug(); } if (GUILayout.Button("Save Bug With Screenshot")) { SaveBugWithScreenshot(); } GUILayout.EndVertical(); } void SaveBug() { Directory.CreateDirectory("Assets/BugRepots/" + bugReporterName); StreamWriter sw = new StreamWriter("Assets/BugRepots/" + bugReporterName + "/" + bugReporterName + ".txt"); sw.WriteLine(bugReporterName); sw.WriteLine(System.DateTime.Now.ToString()); sw.WriteLine(EditorSceneManager.GetActiveScene().name); sw.WriteLine(description); sw.Close(); } void SaveBugWithScreenshot() { Directory.CreateDirectory("Assets/BugRepots/" + bugReporterName); StreamWriter sw = new StreamWriter("Assets/BugRepots/" + bugReporterName + "/" + bugReporterName + ".txt"); sw.WriteLine(bugReporterName); sw.WriteLine(System.DateTime.Now.ToString()); sw.WriteLine(EditorSceneManager.GetActiveScene().name); sw.WriteLine(description); sw.Close(); ScreenCapture.CaptureScreenshot("Assets/BugRepots/" + bugReporterName + "/" + bugReporterName + "ScreenShot" + ".png"); } }

最终效果:

 

那个截屏的功能,Unity帮我换成了别的函数方法,但是截不了图,如果想要截图功能的可以到官网查找相关的函数。如果想了解详细的信息可以点击下面的链接,那个文章里说得很仔细。

本文章参考:https://blog.csdn.net/qq_39020624/article/details/89387005?spm=1001.2014.3001.5506

最后

以上就是忧心花瓣最近收集整理的关于Unity Editor自定义一个记录Bug的窗口的全部内容,更多相关Unity内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(75)

评论列表共有 0 条评论

立即
投稿
返回
顶部