项目中引用了XLua,后来看到网上有写Unity的插件,想着应该也能判断后缀名然后调用指定的编辑器,果然可以。直接贴代码了\
1 using UnityEngine; 2 using UnityEditor; 3 using System; 4 5 public class LuaTxtEditor 6 { 7 9 10 [UnityEditor.Callbacks.OnOpenAssetAttribute(1)] 11 public static bool Step1(int instanceID, int line) 12 { 13 //string name = EditorUtility.InstanceIDToObject(instanceID).name; 14 //Debug.Log("Open Asset step: 1 (" + name + ")"); 15 16 return false; 17 } 18 19 [UnityEditor.Callbacks.OnOpenAssetAttribute(2)] 20 public static bool Step2(int instanceID, int line) 21 { 22 string strFilePath = AssetDatabase.GetAssetPath(EditorUtility.InstanceIDToObject(instanceID)); 23 string strFileName = Application.dataPath + "/" + strFilePath.Replace("Assets/", ""); 24 25 if (strFileName.EndsWith(".lua")) 26 { 27 System.Diagnostics.Process process = new System.Diagnostics.Process(); 28 System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); 29 startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; 30 startInfo.FileName = "D:/sofe/Notepad++/notepad++.exe"; 31 startInfo.Arguments = strFileName; 32 process.StartInfo = startInfo; 33 process.Start(); 34 //Debug.Log(startInfo.FileName + " \t " + startInfo.Arguments); 35 36 37 } 38 39 //string name = EditorUtility.InstanceIDToObject(instanceID).name; 40 //Debug.Log("Open Asset step: 1 (" + name + ")"); 41 42 return false; 43 } 44 45 }
使用的是notepad,其他的有兴趣可以根据自己的爱好修改