lua------------------Unity3D研究院编辑器之打开unity不可识别的文件(十三)
生活随笔
收集整理的這篇文章主要介紹了
lua------------------Unity3D研究院编辑器之打开unity不可识别的文件(十三)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Unity3D研究院編輯器之打開unity不可識別的文件(十三)
?雨松MOMO?【Unity3D拓展編輯器】?圍觀8597次?9 條評論?編輯日期:2017-03-02?字體:大?中?小?
有些特殊后綴名的文件在unity里是不可識別的。如下圖所示,這里我把文本的后綴改成了*.xx 這樣unity就不認(rèn)識了。那么雙擊就沒反應(yīng)了,我想做的就是在雙擊此類文件的時候指定一個應(yīng)用程序打開它。
?
代碼中我指定了用sublime來打開后綴是.xx的文件。
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | using UnityEngine; using UnityEditor; using UnityEditor.Callbacks; public class MyAssetHandler { ????[OnOpenAssetAttribute(1)] ????public static bool step1(int instanceID, int line) ????{ ?????? //string name = EditorUtility.InstanceIDToObject(instanceID).name; ?????? // Debug.Log("Open Asset step: 1 (" + name + ")"); ????????return false; // we did not handle the open ????} ????// step2 has an attribute with index 2, so will be called after step1 ????[OnOpenAssetAttribute(2)] ????public static bool step2(int instanceID, int line) ????{ ????????string path = AssetDatabase.GetAssetPath(EditorUtility.InstanceIDToObject(instanceID)); ????????string name = Application.dataPath + "/" + path.Replace("Assets/", ""); ????????if (name.EndsWith(".xx")) ????????{ ????????????System.Diagnostics.Process process = new System.Diagnostics.Process(); ????????????System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); ????????????startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; ????????????startInfo.FileName = "D:/Program Files/Sublime Text 3/sublime_text.exe"; //改成能夠打開.lua文件的IDE工具即可 ????????????startInfo.Arguments = name; ????????????process.StartInfo = startInfo; ????????????process.Start(); ????????????return true; ????????} ?????? // Debug.Log("Open Asset step: 2 (" + name + ")"); ????????return false; // we did not handle the open ????} } |
這樣就OK啦。我在雙擊的時候sublime就打開啦。
?
?
如果想直接定位在某一行,比如lua文件的某一行。 Windows下可以直接設(shè)置VS打開,但是MAC下沒有, 不過可以傳入文件路徑 和文件的 行數(shù)直接定位。
?
C#| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | static bool OpenFileAtLineExternal(string fileName, int line) { #if UNITY_EDITOR_OSX string sublimePath = @"/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl"; if(File.Exists(sublimePath)){ System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.StartInfo.FileName =sublimePath; proc.StartInfo.Arguments = string.Format("{0}:{1}:0",fileName,line); proc.Start(); return true; }else{ return InternalEditorUtility.OpenFileAtLineExternal(fileName, line); } #else return InternalEditorUtility.OpenFileAtLineExternal(fileName, line); #endif } |
?
轉(zhuǎn)載于:https://www.cnblogs.com/w-wfy/p/7763005.html
總結(jié)
以上是生活随笔為你收集整理的lua------------------Unity3D研究院编辑器之打开unity不可识别的文件(十三)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 梦到跟室友吵架是什么意思
- 下一篇: 梦到死去的人给钱是什么意思