|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public class CreateLuaBehaviourClassFile | 
|---|
|  |  |  | { | 
|---|
|  |  |  | static string templatePath = "Assets/Editor/ScriptTemplate/LuaBehaviourTemplate.txt"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | [MenuItem("Assets/Create/Lua/LuaBehaviour", false, 4)] | 
|---|
|  |  |  | public static void CreateLuaClass() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | var path = GetSelectedPathOrFallback() + "/NewBehaviour.lua"; | 
|---|
|  |  |  | AssetDatabase.DeleteAsset(path); | 
|---|
|  |  |  | ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, ScriptableObject.CreateInstance<LuaBehaviourTemplate>(), path, null, templatePath); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static string GetSelectedPathOrFallback() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | string path = "Assets"; | 
|---|
|  |  |  | foreach (UnityEngine.Object obj in Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.Assets)) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | path = AssetDatabase.GetAssetPath(obj); | 
|---|
|  |  |  | if (!string.IsNullOrEmpty(path) && File.Exists(path)) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | path = Path.GetDirectoryName(path); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return path; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | class LuaBehaviourTemplate : EndNameEditAction | 
|---|
|  |  |  | { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public override void Action(int instanceId, string pathName, string resourceFile) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | UnityEngine.Object o = CreateScriptAssetFromTemplate(pathName, resourceFile); | 
|---|
|  |  |  | ProjectWindowUtil.ShowCreatedAsset(o); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | internal static UnityEngine.Object CreateScriptAssetFromTemplate(string pathName, string resourceFile) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | string fullPath = Path.GetFullPath(pathName); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | StreamReader streamReader = new StreamReader(resourceFile); | 
|---|
|  |  |  | string text = streamReader.ReadToEnd(); | 
|---|
|  |  |  | streamReader.Close(); | 
|---|
|  |  |  | var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(pathName); | 
|---|
|  |  |  | text = Regex.Replace(text, "#ClassName#", fileNameWithoutExtension); | 
|---|
|  |  |  | text = Regex.Replace(text, "#DateTime#", System.DateTime.Now.ToLongDateString()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | bool encoderShouldEmitUTF8Identifier = true; | 
|---|
|  |  |  | bool throwOnInvalidBytes = false; | 
|---|
|  |  |  | UTF8Encoding encoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier, throwOnInvalidBytes); | 
|---|
|  |  |  | bool append = false; | 
|---|
|  |  |  | StreamWriter streamWriter = new StreamWriter(fullPath, append, encoding); | 
|---|
|  |  |  | streamWriter.Write(text); | 
|---|
|  |  |  | streamWriter.Close(); | 
|---|
|  |  |  | AssetDatabase.ImportAsset(pathName); | 
|---|
|  |  |  | return AssetDatabase.LoadAssetAtPath(pathName, typeof(UnityEngine.Object)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public class CreateLuaConfigClassFile | 
|---|
|  |  |  | { | 
|---|
|  |  |  | static string templatePath = "Assets/Editor/ScriptTemplate/LuaConfigTemplate.txt"; | 
|---|
|  |  |  | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return string.Format("subTable.{0} = stringArray_to_numberArray(Split(contents[{1}], '|'))", _field, _index); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else if (_type.Contains("Int2[]")) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return string.Format("subTable.{0} = stringArray_to_Int2Array(Split(contents[{1}], '|'))", _field, _index); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else if (_type.Contains("string[]")) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return string.Format("subTable.{0} = Split(contents[{1}], '|')", _field, _index); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else if (_type.Contains("Int2")) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return string.Format("subTable.{0} = toInt2(Split(contents[{1}], '|'))", _field, _index); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else if (_type.Contains("int") || _type.Contains("float")) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return string.Format("subTable.{0} = tonumber(contents[{1}])", _field, _index); | 
|---|