Exemplo n.º 1
0
        public static void Serialize(string path, AssemblyConfig config)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(AssemblyConfig));

            config.exportClasses.Sort((x, y) => x.name.CompareTo(y.name));
            FileStream file = new FileStream(path, FileMode.Create);

            serializer.Serialize(file, config);
            file.Flush();
            file.Close();
        }
Exemplo n.º 2
0
        public static AssemblyConfig Deserialize(string xml)
        {
            AssemblyConfig config     = null;
            XmlSerializer  serializer = new XmlSerializer(typeof(AssemblyConfig));
            StringReader   reader     = new StringReader(xml);

            config = (AssemblyConfig)serializer.Deserialize(reader);
            reader.Close();

            return(config);
        }
Exemplo n.º 3
0
        //[MenuItem("MHJ/Lua/Create Config")]
        public static void ExportXMLByRegisterTxt()
        {
            AssemblyConfig config     = null;
            string         configPath = Application.dataPath.Replace("\\", "/") + "/ClientCode/client-tools/CSRegisterToLua/config.xml";

            if (File.Exists(configPath))
            {
                config = AssemblyConfig.Deserialize(File.ReadAllText(configPath));
            }
            else
            {
                config = new AssemblyConfig();
            }

            string        filePath = Application.streamingAssetsPath.Replace("\\", "/") + "/Script/Utils/RegisterClass.txt";
            String        content  = File.ReadAllText(filePath);
            StringReader  sr       = new StringReader(content);
            List <string> delList  = new List <string>();
            string        line     = null;

            while ((line = sr.ReadLine()) != null)
            {
                line = line.Trim();
                if (line.StartsWith("--"))
                {
                    continue;
                }
                if (line.StartsWith("Register.RegisterClass"))
                {
                    line = line.Replace("Register.RegisterClass", "");
                    line = line.Substring(line.IndexOf("\"") + 1, line.LastIndexOf("\"") - 2);
                    ClassConfig classConfig = null;
                    //if(line.StartsWith("PBProto") || line.StartsWith("t3config"))
                    {
                        bool isNew = true;
                        foreach (ClassConfig cc in config.exportClasses)
                        {
                            if (cc.name == line)
                            {
                                classConfig = cc;
                                isNew       = false;
                                break;
                            }
                        }
                        if (isNew)
                        {
                            classConfig      = new ClassConfig();
                            classConfig.name = line;
                            config.exportClasses.Add(classConfig);
                        }

                        if (classConfig != null)
                        {
                            if (classConfig.name.StartsWith("PBProto"))
                            {
                                classConfig.isConstructor = true;
                            }
                        }
                    }
                }
            }

            FileInfo      fi = new FileInfo(configPath);
            DirectoryInfo di = fi.Directory;

            if (!di.Exists)
            {
                di.Create();
            }

            for (int i = config.exportClasses.Count - 1; i >= 0; i--)
            {
                Type type  = CSToLuaRegisterHelper.GetTypeByName(config.exportClasses[i].name);
                bool isDel = false;
                if (type == null)
                {
                    isDel = true;
                }
                if (!isDel)
                {
                    EventInfo[] events = type.GetEvents(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy);
                    if (events != null && events.Length > 0)
                    {
                        isDel = true;
                    }
                }
                if (!isDel)
                {
                    FieldInfo[] fields = type.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy);
                    foreach (FieldInfo f in fields)
                    {
                        if (f.FieldType.IsSubclassOf(typeof(Delegate)))
                        {
                            isDel = true;
                            break;
                        }
                    }
                }

                if (!isDel)
                {
                    PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy);
                    foreach (PropertyInfo p in properties)
                    {
                        if (p.PropertyType.IsSubclassOf(typeof(Delegate)))
                        {
                            isDel = true;
                            break;
                        }
                    }
                }
                if (!isDel)
                {
                    if (type.IsGenericType)
                    {
                        isDel = true;
                    }
                }

                if (isDel)
                {
                    config.exportClasses.RemoveAt(i);
                }
            }

            AssemblyConfig.Serialize(configPath, config);
            AssetDatabase.Refresh();
        }
Exemplo n.º 4
0
 public void Init(string configDir)
 {
     aConfig = AssemblyConfig.Deserialize(File.ReadAllText(configDir + "/" + Assembly_Config_Path));
 }