void bindAll(IntPtr l) { Assembly[] ams = AppDomain.CurrentDomain.GetAssemblies(); List <Type> bindlist = new List <Type>(); foreach (Assembly a in ams) { Type[] ts = a.GetExportedTypes(); foreach (Type t in ts) { if (t.GetCustomAttributes(typeof(LuaBinderAttribute), false).Length > 0) { bindlist.Add(t); } } } bindlist.Sort(new System.Comparison <Type>((Type a, Type b) => { LuaBinderAttribute la = (LuaBinderAttribute)a.GetCustomAttributes(typeof(LuaBinderAttribute), false)[0]; LuaBinderAttribute lb = (LuaBinderAttribute)b.GetCustomAttributes(typeof(LuaBinderAttribute), false)[0]; return(la.order.CompareTo(lb.order)); }) ); foreach (Type t in bindlist) { t.GetMethod("Bind").Invoke(null, new object[] { l }); } }
private void doBind(object state) { IntPtr L = (IntPtr)state; Assembly[] ams = AppDomain.CurrentDomain.GetAssemblies(); bindProgress = 0; List <Type> bindlist = new List <Type>(); foreach (Assembly a in ams) { Type[] ts = null; try { ts = a.GetExportedTypes(); } catch { continue; } foreach (Type t in ts) { if (t.GetCustomAttributes(typeof(LuaBinderAttribute), false).Length > 0) { bindlist.Add(t); } } } bindProgress = 1; bindlist.Sort(new System.Comparison <Type>((Type a, Type b) => { LuaBinderAttribute la = (LuaBinderAttribute)a.GetCustomAttributes(typeof(LuaBinderAttribute), false)[0]; LuaBinderAttribute lb = (LuaBinderAttribute)b.GetCustomAttributes(typeof(LuaBinderAttribute), false)[0]; return(la.order.CompareTo(lb.order)); })); List <Action <IntPtr> > list = new List <Action <IntPtr> >(); foreach (Type t in bindlist) { var sublist = (Action <IntPtr>[])t.GetMethod("GetBindList").Invoke(null, null); list.AddRange(sublist); } bindProgress = 2; int count = list.Count; for (int n = 0; n < count; n++) { Action <IntPtr> action = list[n]; action(L); bindProgress = (int)(((float)n / count) * 98.0) + 2; } bindProgress = 100; }
/// <summary> ///收集所有需要导出的类的reg方法 /// </summary> /// <returns></returns> List <Action <IntPtr> > collectBindInfo() { List <Action <IntPtr> > list = new List <Action <IntPtr> >(); #if !SLUA_STANDALONE #if !USE_STATIC_BINDER Assembly[] ams = AppDomain.CurrentDomain.GetAssemblies(); List <Type> bindlist = new List <Type>(); for (int n = 0; n < ams.Length; n++) { Assembly a = ams[n]; Type[] ts = null; try { ts = a.GetExportedTypes(); } catch { continue; } for (int k = 0; k < ts.Length; k++) { Type t = ts[k]; if (t.IsDefined(typeof(LuaBinderAttribute), false)) { bindlist.Add(t); } } } bindlist.Sort(new System.Comparison <Type>((Type a, Type b) => { LuaBinderAttribute la = System.Attribute.GetCustomAttribute(a, typeof(LuaBinderAttribute)) as LuaBinderAttribute; LuaBinderAttribute lb = System.Attribute.GetCustomAttribute(b, typeof(LuaBinderAttribute)) as LuaBinderAttribute; return(la.order.CompareTo(lb.order)); })); for (int n = 0; n < bindlist.Count; n++) { Type t = bindlist[n]; var sublist = (Action <IntPtr>[])t.GetMethod("GetBindList").Invoke(null, null); list.AddRange(sublist); } #else var assemblyName = "Assembly-CSharp"; Assembly assembly = Assembly.Load(assemblyName); list.AddRange(getBindList(assembly, "SLua.BindUnity")); list.AddRange(getBindList(assembly, "SLua.BindUnityUI")); list.AddRange(getBindList(assembly, "SLua.BindDll")); list.AddRange(getBindList(assembly, "SLua.BindCustom")); #endif #endif return(list); }
List <Action <IntPtr> > collectBindInfo() { List <Action <IntPtr> > list = new List <Action <IntPtr> >(); #if !SLUA_STANDALONE #if !USE_STATIC_BINDER Assembly[] ams = AppDomain.CurrentDomain.GetAssemblies(); List <Type> bindlist = new List <Type>(); for (int n = 0; n < ams.Length; n++) { Assembly a = ams[n]; Type[] ts = null; try { ts = a.GetExportedTypes(); } catch { continue; } bindlist.AddRange(ts.Where(t => t.IsDefined(typeof(LuaBinderAttribute), false))); } bindlist.Sort((a, b) => { LuaBinderAttribute la = Attribute.GetCustomAttribute(a, typeof(LuaBinderAttribute)) as LuaBinderAttribute; LuaBinderAttribute lb = Attribute.GetCustomAttribute(b, typeof(LuaBinderAttribute)) as LuaBinderAttribute; return(la.order.CompareTo(lb.order)); }); foreach (var t in bindlist) { var sublist = (IEnumerable <Action <IntPtr> >)t.GetMethod("GetBindList").Invoke(null, null); list.AddRange(sublist); } #else var assemblyName = "Assembly-CSharp"; Assembly assembly = Assembly.Load(assemblyName); list.AddRange(getBindList(assembly, "SLua.BindUnity")); list.AddRange(getBindList(assembly, "SLua.BindUnityUI")); list.AddRange(getBindList(assembly, "SLua.BindDll")); list.AddRange(getBindList(assembly, "SLua.BindCustom")); #endif #endif return(list); }
static void bindAll(IntPtr l) { // add RELEASE macro to switch on below codes #if RELEASE && (UNITY_IOS || UNITY_ANDROID) BindUnity.Bind(l); BindUnityUI.Bind(l); // delete this line if not found BindDll.Bind(l); // delete this line if not found BindCustom.Bind(l); #else Assembly[] ams = AppDomain.CurrentDomain.GetAssemblies(); List <Type> bindlist = new List <Type>(); foreach (Assembly a in ams) { Type[] ts = a.GetExportedTypes(); foreach (Type t in ts) { if (t.GetCustomAttributes(typeof(LuaBinderAttribute), false).Length > 0) { bindlist.Add(t); } } } bindlist.Sort(new System.Comparison <Type>((Type a, Type b) => { LuaBinderAttribute la = (LuaBinderAttribute)a.GetCustomAttributes(typeof(LuaBinderAttribute), false)[0]; LuaBinderAttribute lb = (LuaBinderAttribute)b.GetCustomAttributes(typeof(LuaBinderAttribute), false)[0]; return(la.order.CompareTo(lb.order)); }) ); foreach (Type t in bindlist) { t.GetMethod("Bind").Invoke(null, new object[] { l }); } #endif }
private void doBind(object state) { IntPtr L = (IntPtr)state; List <Action <IntPtr> > list = new List <Action <IntPtr> >(); #if !USE_STATIC_BINDER Assembly[] ams = AppDomain.CurrentDomain.GetAssemblies(); bindProgress = 0; List <Type> bindlist = new List <Type>(); for (int n = 0; n < ams.Length; n++) { Assembly a = ams[n]; Type[] ts = null; try { ts = a.GetExportedTypes(); } catch { continue; } for (int k = 0; k < ts.Length; k++) { Type t = ts[k]; if (t.IsDefined(typeof(LuaBinderAttribute), false)) { bindlist.Add(t); } } } bindProgress = 1; bindlist.Sort(new System.Comparison <Type>((Type a, Type b) => { LuaBinderAttribute la = System.Attribute.GetCustomAttribute(a, typeof(LuaBinderAttribute)) as LuaBinderAttribute; LuaBinderAttribute lb = System.Attribute.GetCustomAttribute(b, typeof(LuaBinderAttribute)) as LuaBinderAttribute; return(la.order.CompareTo(lb.order)); })); for (int n = 0; n < bindlist.Count; n++) { Type t = bindlist[n]; var sublist = (Action <IntPtr>[])t.GetMethod("GetBindList").Invoke(null, null); list.AddRange(sublist); } #else list.AddRange(BindUnity.GetBindList()); list.AddRange(BindDll.GetBindList()); list.AddRange(BindCustom.GetBindList()); #endif bindProgress = 2; int count = list.Count; for (int n = 0; n < count; n++) { Action <IntPtr> action = list[n]; action(L); bindProgress = (int)(((float)n / count) * 98.0) + 2; } bindProgress = 100; }