static void GenLuaDelegates() { if (!beAutoGen && EditorApplication.isCompiling) { EditorUtility.DisplayDialog("警告", "请等待编辑器完成编译在执行此功能", "确定"); return; } ToLuaExport.Clear(); List <DelegateType> list = new List <DelegateType>(); list.AddRange(CustomSettings.customDelegateList); HashSet <Type> set = GetCustomTypeDelegates(); foreach (Type t in set) { if (null == list.Find((p) => { return(p.type == t); })) { list.Add(new DelegateType(t)); } } ToLuaExport.GenDelegates(list.ToArray()); set.Clear(); ToLuaExport.Clear(); AssetDatabase.Refresh(); Debug.Log("Create lua delegate over"); }
static void GenLuaDelegates() { ToLuaExport.Clear(); List <DelegateType> list = new List <DelegateType>(); list.AddRange(new DelegateType[] { _DT(typeof(Action <GameObject>)), _DT(typeof(Action)), _DT(typeof(UnityEngine.Events.UnityAction)), }); HashSet <Type> set = beAutoGen ? ToLuaExport.eventSet : GetCustomDelegateTypes(); foreach (Type t in set) { if (null == list.Find((p) => { return(p.type == t); })) { list.Add(_DT(t)); } } ToLuaExport.GenDelegates(list.ToArray()); set.Clear(); ToLuaExport.Clear(); AssetDatabase.Refresh(); Debug.Log("Create lua delegate over"); }
//[MenuItem("Lua/Clear wrap files", false, 6)] static void ClearLuaWraps() { string[] files = Directory.GetFiles(CustomSettings.saveDir, "*.cs", SearchOption.TopDirectoryOnly); for (int i = 0; i < files.Length; i++) { File.Delete(files[i]); } ToLuaExport.Clear(); List <DelegateType> list = new List <DelegateType>(); ToLuaExport.GenDelegates(list.ToArray()); ToLuaExport.Clear(); }
static void GenLuaDelegates() { ToLuaExport.Clear(); DelegateType[] list = new DelegateType[] { _DT(typeof(Action <GameObject>)), //_DT(typeof(Action<GameObject, int, string>)), //_DT(typeof(Action<int, int, int, List<int>>)), //_DT(typeof(UIEventListener.VoidDelegate)).SetName("VoidDelegate"), }; ToLuaExport.GenDelegates(list); Debug.Log("Create lua delegate over"); }
static void ClearLuaWraps() { string[] files = Directory.GetFiles(CustomSettings.saveDir, "*.cs", SearchOption.TopDirectoryOnly); for (int i = 0; i < files.Length; i++) { File.Delete(files[i]); } string filename = Path.GetFullPath(CustomSettings.saveBaseDir); if (!Directory.Exists(filename)) { Directory.CreateDirectory(filename); } ToLuaExport.Clear(); List <DelegateType> list = new List <DelegateType>(); ToLuaExport.GenDelegates(list.ToArray(), CustomSettings.saveBaseDir + "DelegateFactory.cs"); ToLuaExport.Clear(); StringBuilder sb = new StringBuilder(); sb.AppendLineEx("using System;"); sb.AppendLineEx("using LuaInterface;"); sb.AppendLineEx(); sb.AppendLineEx("public static class LuaBinder"); sb.AppendLineEx("{"); sb.AppendLineEx("\tpublic static void Bind(LuaState L)"); sb.AppendLineEx("\t{"); sb.AppendLineEx("\t\tthrow new LuaException(\"Please generate LuaBinder files first!\");"); sb.AppendLineEx("\t}"); sb.AppendLineEx("}"); string file = CustomSettings.saveBaseDir + "LuaBinder.cs"; using (StreamWriter textWriter = new StreamWriter(file, false, Encoding.UTF8)) { textWriter.Write(sb.ToString()); textWriter.Flush(); textWriter.Close(); } AssetDatabase.Refresh(); }
static void ClearLuaWraps() { string[] files = Directory.GetFiles(WrapFiles.saveDir, "*.cs", SearchOption.TopDirectoryOnly); for (int i = 0; i < files.Length; i++) { File.Delete(files[i]); } ToLuaExport.Clear(); List <DelegateType> list = new List <DelegateType>(); ToLuaExport.GenDelegates(list.ToArray()); ToLuaExport.Clear(); StringBuilder sb = new StringBuilder(); sb.AppendLineEx("using System;"); sb.AppendLineEx("using LuaInterface;"); sb.AppendLineEx(); sb.AppendLineEx("public static class LuaBinder"); sb.AppendLineEx("{"); sb.AppendLineEx("\tpublic static void Bind(LuaState L)"); sb.AppendLineEx("\t{"); sb.AppendLineEx("\t}"); sb.AppendLineEx("}"); string file = WrapFiles.saveDir + "LuaBinder.cs"; using (StreamWriter textWriter = new StreamWriter(file, false, Encoding.UTF8)) { textWriter.Write(sb.ToString()); textWriter.Flush(); textWriter.Close(); } AssetDatabase.Refresh(); }
static void GenLuaDelegates() { // 如果 beAutoGen 为假且脚本正在编译中就弹窗警告 if (!beAutoGen && EditorApplication.isCompiling) { EditorUtility.DisplayDialog("警告", "请等待编辑器完成编译再执行此功能", "确定"); return; } // 重置 ToLuaExport ToLuaExport.Clear(); // 新建一个委托类型信息类 list,并将 CustomSettings.customDelegateList 中所有元素添加进来 List <DelegateType> list = new List <DelegateType>(); list.AddRange(CustomSettings.customDelegateList); // 以 HashSet<Type> 形式获取 CustomSettings.customTypeList 中所有委托类型元素(字段、属性、方法参数)的类型 HashSet <Type> set = GetCustomTypeDelegates(); // 如果委托 list 中找不到当前类型的委托类型信息类,就新建一个并添加到 HashSet 中 foreach (Type t in set) { if (null == list.Find((p) => { return(p.type == t); })) { list.Add(new DelegateType(t)); } } // 生成 "DelegateFactory.cs" 脚本 ToLuaExport.GenDelegates(list.ToArray()); // 释放资源 set.Clear(); ToLuaExport.Clear(); // 刷新 AssetDatabase、打印消息 AssetDatabase.Refresh(); Debug.Log("Create lua delegate over"); }
public void GenDelegate() { ToLuaExport.Clear(); ToLuaExport.GenDelegates(GetAllBuildedDelegate().ToArray(), delegateFactoryFilePath); ToLuaExport.Clear(); }