Exemplo n.º 1
0
        public static void Gen(HashSet <int> ps)
        {
            for (int i = 1; i <= 10; ++i)
            {
                ps.Remove(i);
            }

            int[] v = ps.ToArray();
            System.Array.Sort(v, (x, y) => { return(x.CompareTo(y)); });
            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            string marco, suffix;

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

            sb.AppendLine(string.Format("#if {0}", marco));
            sb.Append(@"namespace IL
{
    public partial struct Objects
    {"
                      );
            for (int i = 0; i < v.Length; ++i)
            {
                sb.AppendLine();
                Gen(sb, v[i]);
            }

            sb.Append(@"
    }
}
");
            sb.Append("#endif");
            System.IO.File.WriteAllText(filepath, sb.ToString());
        }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
0
 public static void GenClear()
 {
     Clear();
     AutoRegILType.Clear();
 }
Exemplo n.º 4
0
 public static void GenOne()
 {
     Gen();
     AutoRegILType.Build();
 }