Beispiel #1
0
        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
        }
Beispiel #2
0
        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;
        }