Unity3d Seal Log

Source: Internet
Author: User
Tags getcolor

1 usingSystem;2 usingSystem.Text;3 usingSystem.Text.RegularExpressions;4 usingUnityengine;5 #ifUnity_editor6 usingSystem.Reflection;7 usingUnityeditor;8 #endif9 Ten  Public classLogutil One { A     Private StaticLogLevel LOGLV =Loglevel.info; -  -      Public enumLogLevel:byte the     { -NONE =0, -INFO =1, -WARNING =2, +ERROR =3, -EXCEPTION =4, +     } A  at      Public Static voidInfo (ObjectMessage, Unityengine.object sender =NULL) -     { -         if(Loglevel.info <loglv) -             return; - Format (loglevel.info,message,sender); -     } in  -      Public Static voidWarning (ObjectMessage, Unityengine.object sender =NULL) to     { +         if(Loglevel.warning <loglv) -             return; the Format (loglevel.warning, message, sender); *     } $ Panax Notoginseng      Public Static voidError (ObjectMessage, Unityengine.object sender =NULL) -     { the         if(Loglevel.error <loglv) +             return; A Format (loglevel.error, message, sender); the     } +  -      Public Static voidException (Exception exption, unityengine.object sender =NULL) $     { $         if(Loglevel.exception <loglv) -             return; - Format (loglevel.exception, exption, sender); the     } - Wuyi      Public Static voidBreak (ObjectMessage, Unityengine.object sender =NULL) the     { - Info (message, sender); Wu debug.break (); -     } About  $     Private Static voidFormat (LogLevel LV,Objectmessage, Unityengine.object sender) -     { -StringBuilder SB =NewStringBuilder (); -Sb. AppendFormat ("<color={0}>[{1}] {2}</color>", GetColor (LV), LV. ToString (), message); A Debug.Log (SB, sender); +     } the  -     Private Static stringGetColor (LogLevel LV) $     { the         stringstr ="#909090"; the  the         if(Loglevel.warning = =LV) thestr ="Orange"; -         Else if(Loglevel.error = =LV) instr ="Red"; the  the         returnstr; About     } the  the     #ifUnity_editor the[UnityEditor.Callbacks.OnOpenAssetAttribute (0)] +     Static BOOLOnopenasset (intInstanceID,intLine ) { -         stringStackTrace =getstacktrace (); the         if(string. IsNullOrEmpty (stackTrace))Bayi             return false; the  theMatch matches = Regex.match (StackTrace,@"\ (at Assets (. +) \)"); -          while(matches. Success) { -             stringstr = matches. Groups [1]. Value; the             if(str. Contains ("LogUtil.cs")) { theMatches =matches. NextMatch (); the                 Continue; the             } -  the             intSplitidx = str. LastIndexOf (":"); the             stringPath = str. Substring (0, SPLITIDX); theInt32.TryParse (str. Substring (Splitidx +1), outLine );94Path = Application.datapath +path; theUnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal (path. Replace ('/','\\'), line); the             return true; the         }98  About         return false; -     }101 102     Static stringGetstacktrace () {103         //Get Consolewindow104Assembly editorwinassembly = assembly.getassembly (typeof(Editorwindow)); theType Consolewintype = Editorwinassembly.gettype ("Unityeditor.consolewindow");106FieldInfo FieldInfo = Consolewintype.getfield ("Ms_consolewindow", BindingFlags.Static |bindingflags.nonpublic);107         ObjectConsolewin = Fieldinfo.getvalue (NULL);108         if((NULL= = Consolewin) | | ((Object) Editorwindow.focusedwindow! =Consolewin))109             return NULL; the 111         //Get listviewstate in Consolewindow theType Listviewstatetype = Editorwinassembly.gettype ("unityeditor.listviewstate");113FieldInfo = Consolewintype.getfield ("M_listview", BindingFlags.Instance |bindingflags.nonpublic); the         ObjectListView =Fieldinfo.getvalue (Consolewin); the  the         //Get row in Listviewstate117FieldInfo = Listviewstatetype.getfield ("Row", BindingFlags.Instance |bindingflags.public);118 119         //Get M_activetext in Consolewindow -FieldInfo = Consolewintype.getfield ("M_activetext", BindingFlags.Instance |bindingflags.nonpublic);121         stringText =Fieldinfo.getvalue (Consolewin). ToString ();122 123         returntext;124     } the     #endif126}

Unity3d Seal Log

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.