Exemple #1
0
        public static void AutoCode(List <string> classes)
        {
            // 自动生成所有需要委托
            SortedDictionary <string, Funs> allfuns = new SortedDictionary <string, Funs>(); // 所有的需要导出的函数原形列表

            var flag = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.IgnoreCase | BindingFlags.DeclaredOnly;
            var alls = new List <System.Type>();

            HashSet <int>    ObjectsParamCount = new HashSet <int>();
            HashSet <string> exports           = new HashSet <string>(classes);
            {
                var assembly = Assembly.Load("Assembly-CSharp");
                var types    = assembly.GetTypes();
                foreach (var type in types)
                {
                    if (exports.Contains(type.FullName.Replace('+', '/')) || type.GetCustomAttributes(typeof(HotfixAttribute), false).Length != 0)
                    {
                        //wxb.L.LogFormat("type:{0}", type.FullName);
                        if (type.IsGenericType)
                        {
                            continue;
                        }

                        foreach (var method in type.GetMethods(flag))
                        {
                            if (method.IsGenericMethod)
                            {
                                continue;
                            }

                            if (IsEditorAttribute(method))
                            {
                                continue;
                            }

                            Funs fun = new Funs(method, method.IsStatic ? false : true);
                            if (!fun.isExport)
                            {
                                continue;
                            }

                            string key = fun.oid;
                            Funs   rs;
                            if (allfuns.TryGetValue(key, out rs))
                            {
                                rs.methods.Add(method);
                                continue;
                            }

                            allfuns.Add(key, fun);
                        }

                        // MonoBehaviour类型不重载构造函数
                        if (IsUnityObjectType(type))
                        {
                            continue;
                        }

                        foreach (var ctor in type.GetConstructors(flag))
                        {
                            if (ctor.IsGenericMethod)
                            {
                                continue;
                            }

                            if (IsEditorAttribute(ctor))
                            {
                                continue;
                            }

                            Funs fun = new Funs(ctor, ctor.IsStatic ? false : true);
                            if (!fun.isExport)
                            {
                                continue;
                            }

                            string key = fun.oid;
                            Funs   rs;
                            if (allfuns.TryGetValue(key, out rs))
                            {
                                rs.methods.Add(ctor);
                                continue;
                            }

                            allfuns.Add(key, fun);
                        }
                    }
                }
            }

            string marco, suffix;

            AutoRegILType.GetPlatform(out marco, out suffix);
            string file = string.Format("Assets/XIL/Auto/GenDelegateBridge_{0}.cs", suffix);

            System.IO.Directory.CreateDirectory(file.Substring(0, file.LastIndexOf('/')));

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            string name  = "__Gen_Delegate_Imp";
            int    index = 0;

            foreach (var ator in allfuns)
            {
                ator.Value.toInfo("        ", sb);
                int paramCount = 0;
                sb.AppendFormat("        {0}", ator.Value.toString(name + (++index), out paramCount));
                sb.AppendLine();
                if (paramCount != 0)
                {
                    ObjectsParamCount.Add(paramCount);
                }
            }

            System.IO.File.WriteAllText(file, string.Format(file_format + "#endif", marco, sb.ToString()));
            wxb.L.LogFormat("count:{0}", allfuns.Count);

            sb.Length = 0;
            sb.AppendLine(string.Format("countType:{0}", classes.Count));
            foreach (var ator in classes)
            {
                sb.AppendLine(ator);
            }
            wxb.L.LogFormat(sb.ToString());

            GeneratorObjects.Gen(ObjectsParamCount);
            AssetDatabase.Refresh();
        }
Exemple #2
0
        public static void AutoCode(List <string> classes)
        {
            // 自动生成所有需要委托
            Dictionary <string, Funs> allfuns = new Dictionary <string, Funs>(); // 所有的需要导出的函数原形列表

            var flag = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.IgnoreCase | BindingFlags.DeclaredOnly;
            var alls = new List <System.Type>();

            HashSet <int>    ObjectsParamCount = new HashSet <int>();
            HashSet <string> exports           = new HashSet <string>(classes);

            foreach (var ator in System.AppDomain.CurrentDomain.GetAssemblies().Select((assemblies) => assemblies.GetTypes()))
            {
                foreach (var type in ator)
                {
                    if (exports.Contains(type.FullName.Replace('+', '/')) || type.GetCustomAttributes(typeof(HotfixAttribute), false).Length != 0)
                    {
                        //Debug.LogFormat("type:{0}", type.FullName);
                        if (type.IsGenericType)
                        {
                            continue;
                        }

                        foreach (var method in type.GetMethods(flag))
                        {
                            if (method.IsGenericMethod)
                            {
                                continue;
                            }

                            Funs fun = new Funs(method, method.IsStatic ? false : true);
                            if (!fun.isExport)
                            {
                                continue;
                            }

                            string key = fun.oid;
                            Funs   rs;
                            if (allfuns.TryGetValue(key, out rs))
                            {
                                rs.methods.Add(method);
                                continue;
                            }

                            allfuns.Add(key, fun);
                        }

                        // MonoBehaviour类型不重载构造函数
                        if (IsUnityObjectType(type))
                        {
                            continue;
                        }

                        foreach (var ctor in type.GetConstructors(flag))
                        {
                            if (ctor.IsGenericMethod)
                            {
                                continue;
                            }

                            Funs fun = new Funs(ctor, ctor.IsStatic ? false : true);
                            if (!fun.isExport)
                            {
                                continue;
                            }

                            string key = fun.oid;
                            Funs   rs;
                            if (allfuns.TryGetValue(key, out rs))
                            {
                                rs.methods.Add(ctor);
                                continue;
                            }

                            allfuns.Add(key, fun);
                        }
                    }
                }
            }

#if UNITY_IOS
            string marco = "UNITY_IOS";
            string file  = "Assets/XIL/Auto/GenDelegateBridge_ios.cs";
#elif UNITY_ANDROID
            string marco = "UNITY_ANDROID";
            string file  = "Assets/XIL/Auto/GenDelegateBridge_ad.cs";
#else
            string marco = "UNITY_STANDALONE_WIN";
            string file  = "Assets/XIL/Auto/GenDelegateBridge_pc.cs";
#endif
            System.IO.Directory.CreateDirectory(file.Substring(0, file.LastIndexOf('/')));

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            string name  = "__Gen_Delegate_Imp";
            int    index = 0;
            foreach (var ator in allfuns)
            {
                ator.Value.toInfo("        ", sb);
                int paramCount = 0;
                sb.AppendFormat("        {0}", ator.Value.toString(name + (++index), out paramCount));
                sb.AppendLine();
                if (paramCount != 0)
                {
                    ObjectsParamCount.Add(paramCount);
                }
            }

            System.IO.File.WriteAllText(file, string.Format(file_format + "#endif", marco, sb.ToString()));
            Debug.LogFormat("count:{0}", allfuns.Count);

            sb.Length = 0;
            sb.AppendLine(string.Format("countType:{0}", classes.Count));
            foreach (var ator in classes)
            {
                sb.AppendLine(ator);
            }
            Debug.LogFormat(sb.ToString());

            GeneratorObjects.Gen(ObjectsParamCount);
            AssetDatabase.Refresh();
        }