본문 바로가기

도구의발견

[Unity] 콜스택 알아 오기

유니티를 사용하다 보면 디버깅을 위해 로그를 찍을때 리스트 뷰에서는 콜스택에 대한 정보를 볼수 없어 귀찮은 경우가 많다. 어셋 스토에서 판매하고 있는 'Console Pro'라는 어셋을 사용하면 편리하긴하지만..

using UnityEngine; // example : //     Debug.Log(LogHeader.Function + "any log text will be here"); // result :    //    CallStackLogMain:func_2() (at Assets/CallStackLogMain.cs:17)    //    any log text will be here public static class LogHeader { ​​​​public static string Path  ​​​​{        ​​​​​​​​get ​​​​​​​​{ #if UNITY_EDITOR || USE_DEBUGGING ​​​​​​​​​​​​string callStack = StackTraceUtility.ExtractStackTrace(); ​​​​​​​​​​​​callStack = callStack.Substring(callStack.IndexOf("\n") + 1); ​​​​​​​​​​​​callStack = callStack.Substring(0, callStack.IndexOf("\n") + 1); ​​​​​​​​​​​​return callStack; #else ​​​​​​​​​​​​return ""; #endif ​​​​​​​​}    ​​​​}    ​​​​ ​​​​public static string Function    ​​​​{ ​​​​​​​​get ​​​​​​​​{ #if UNITY_EDITOR || USE_DEBUGGING ​​​​​​​​​​​​string callStack = StackTraceUtility.ExtractStackTrace(); ​​​​​​​​​​​​callStack = callStack.Substring(callStack.IndexOf("\n") + 1); ​​​​​​​​​​​​callStack = callStack.Substring(0, callStack.IndexOf("(")); ​​​​​​​​​​​​return "[" + callStack + "] "; #else ​​​​​​​​​​​​return ""; #endif        ​​​​​​​​} ​​​​}    }

 

유익한 글이었다면 공감(❤) 버튼 꾹!! 추가 문의 사항은 댓글로!!