我是靠谱客的博主 忧心花瓣,最近开发中收集的这篇文章主要介绍Unity Editor自定义一个记录Bug的窗口,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

直接上代码:

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 Editor自定义一个记录Bug的窗口所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部