unity3d 右键快速打开文件
在开发中如果只是想快速查看某个(如.lua)文件的话,可以活用右键功能,这个在打开多个工程并调试的情况下略显高效。
如图:
写了一个工具类,并添加了两个方法:可选用notepad++或记事本快速打开文件。
代码如下:
usingUnityEngine;usingSystem.Collections;usingUnityEditor;usingthisObject=UnityEngine.Object;usingSystem.Threading;usingSystem;publicclassEasyTool{constintOpenMax=10;//一次打开文件的最大数量conststringNotePadJJ_APP_NAME="notepad++.exe";conststringNotePad_APP_NAME="notepad.exe";///<summary>///用notepad++打开文件///</summary>[MenuItem("Assets/EasyTool/Open_NotePad++")]staticpublicvoidOpenForNotePadJJ(){intcount=0;foreach(vargoinGetSelectObject()){if(go!=null){stringdir_path=GetPath(go);InvokeCmd(NotePadJJ_APP_NAME,dir_path);}count++;if(count>OpenMax){break;}}}//<summary>///用记事本打开文件///</summary>[MenuItem("Assets/EasyTool/Open_NotePad")]staticpublicvoidOpenForNotePad(){intcount=0;foreach(vargoinGetSelectObject()){if(go!=null){stringdir_path=GetPath(go);InvokeCmd(NotePad_APP_NAME,dir_path);count++;if(count>OpenMax){break;}}}}///<summary>///调用CMD命令///</summary>publicstaticvoidInvokeCmd(stringcmd,stringdir_path){UnityEngine.Debug.Log(cmd);AssetDatabase.Refresh();newThread(newThreadStart(()=>{try{System.Diagnostics.Processp=newSystem.Diagnostics.Process();p.StartInfo.FileName=cmd;p.StartInfo.Arguments=dir_path;p.Start();p.WaitForExit();p.Close();}catch(Exceptione){Debug.Log(e.Message);}})).Start();}///<summary>///获取选择的文件///</summary>///<returns></returns>staticpublicthisObject[]GetSelectObject(){if(Selection.objects.Length==0){returnnewthisObject[0];}returnSelection.objects;}///<summary>///获取文件路径///</summary>///<paramname="go"></param>///<returns></returns>staticpublicstringGetPath(thisObjectgo){stringstr=Application.dataPath.Replace("Assets","");stringpath=AssetDatabase.GetAssetPath(go);stringdir_path=System.IO.Path.GetFullPath(str+path);returndir_path;}}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。