最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Unity輸出帶點擊跳轉(zhuǎn)功能的Log實現(xiàn)技巧詳解

 更新時間:2022年11月18日 14:43:02   作者:7_erQ  
這篇文章主要為大家介紹了Unity輸出帶點擊跳轉(zhuǎn)功能的Log實現(xiàn)技巧詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪

正文

在平常的Unity開發(fā)過程中,可能會遇到如:

1.使用Debug.Log替代輸出異常信息;

2.調(diào)試代碼時,源代碼在try{}代碼塊內(nèi)有較多或深層的調(diào)用;

3.想在輸出的Log中提示或是引導其他開發(fā)人員打開指定的腳本等情景。

在上述情景中,Debug.Log輸出的Log一般都是不帶點擊跳轉(zhuǎn)功能的,使得我們需要在長長的Log中尋找目標文件,然后再對照著文件名,方法名在IDE中點開,并不是很方便。

不帶點擊跳轉(zhuǎn)的Log

public static void TestFunc() {
    try {
        TestCall_1("", 0);
    } catch (System.Exception e) {
        // 平時使用Debug輸出的Log是不帶點擊跳轉(zhuǎn)的
        Debug.LogError(e.ToString());
    }
}

輸出結(jié)果

如果在try catch中做了很復雜的操作,這樣的Log將會又長又亂

后來經(jīng)過反復比對帶點擊跳轉(zhuǎn)和不帶點擊跳轉(zhuǎn)的兩行Log,發(fā)現(xiàn)了Unity識別這種跳轉(zhuǎn)路徑的基本格式為:()[空格](at X:0),(空格不能省略)。因此只要把要跳轉(zhuǎn)的腳本路徑照這個格式封裝就能實現(xiàn)高亮點擊跳轉(zhuǎn)了。下面是演示代碼。

帶點擊跳轉(zhuǎn)的Log

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Text.RegularExpressions;
???????public class TestEditor {
    [MenuItem("測試/打印異常")]
    public static void TestFunc() {
        try {
            TestCall_1("", 0);
        } catch (System.Exception e) {
            string output = "使Log帶跳轉(zhuǎn)功能 \n";
            // 1.這是能被識別為帶點擊跳轉(zhuǎn)的格式:() (at XXX:0)
            output += "() (at X:0) \n";
             // 2.可以是絕對路徑,但格式好像只能是.cs文件,若.cs文件不存在,則會在IDE中打開一個新文檔
? ? ? ? ? ? output += "() (at " + @"C:/Users/7_erQ/Desktop/test.cs" + ":0) \n";

? ? ? ? ? ? // 3.用正則替換原Log為 XXX.xxx() (at XXX.cs:nnn)的格式,就能使Log帶跳轉(zhuǎn)功能了
? ? ? ? ? ? // 原Log: ?at TestEditor.TestCall_4 (System.String arg1, System.Int32 arg2) [0x00001] in F:\WorkStation\CodeSpace\UnityProjects\AssetLinkMapDemo\Assets\Temp\Editor\TestEditor.cs:41
? ? ? ? ? ? // 替換后: ?at TestEditor.TestCall_4 (System.String arg1, System.Int32 arg2) (at F:\WorkStation\CodeSpace\UnityProjects\AssetLinkMapDemo\Assets\Temp\Editor\TestEditor.cs:42)
? ? ? ? ? ? Regex reg = new Regex(@"\)\s\[0x[0-9,a-f]*\]\sin\s(.*:[0-9]*)\s");
? ? ? ? ? ? output += reg.Replace(e.ToString(), ") (at $1) ");
? ? ? ? ? ? Debug.LogError(output);
? ? ? ? }
? ? }

? ? public static void TestCall_1(string arg1, int arg2) {
? ? ? ? TestCall_2(arg1, arg2);
? ? }

? ? public static void TestCall_2(string arg1, int arg2) {
? ? ? ? TestCall_3(arg1, arg2);
? ? }

? ? public static void TestCall_3(string arg1, int arg2) {
? ? ? ? TestCall_4(arg1, arg2);
? ? }

? ? public static void TestCall_4(string arg1, int arg2) {
? ? ? ? throw new System.Exception();
? ? }
}

輸出結(jié)果

帶點擊跳轉(zhuǎn)的Log

這樣就可以直接點開定位到目標文件和方法了 作者:7_erQ https://www.bilibili.com/read/cv15464238 出處:bilibili

以上就是Unity輸出帶點擊跳轉(zhuǎn)功能的Log實現(xiàn)技巧詳解的詳細內(nèi)容,更多關(guān)于Unity輸出點擊跳轉(zhuǎn)Log的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論

阿坝县| 肃南| 平昌县| 枝江市| 武穴市| 普安县| 荔波县| 汕头市| 太仓市| 栾城县| 威信县| 石门县| 克什克腾旗| 合阳县| 德格县| 弋阳县| 库车县| 孟州市| 湾仔区| 渑池县| 贺州市| 佛坪县| 佛山市| 沙坪坝区| 淮滨县| 京山县| 石阡县| 阳原县| 耒阳市| 阜康市| 兴化市| 台山市| 桂阳县| 枣庄市| 黄平县| 江门市| 利川市| 大宁县| 清流县| 阳谷县| 巴中市|