Beispiel #1
0
    static void ExportResourceTables()
    {
        Type requestType = typeof(ITableManager);

        foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
        {
            Type[] types = assembly.GetTypes();
            foreach (Type type in types)
            {
                if (!requestType.IsAssignableFrom(type) ||
                    type.IsInterface ||
                    type.IsAbstract)
                {
                    continue;
                }

                ITableManager tableInstance = Activator.CreateInstance(type) as ITableManager;
                PropertyInfo  tableInfo     = type.GetProperty("TableData");
                object        tableData     = tableInfo.GetValue(tableInstance, null);
                string        path          = string.Format("{0}/Table/{1}.bytes", Application.dataPath, tableInstance.TableName());
                using (FileStream stream = new FileStream(path, FileMode.Create))
                {
                    ProtoBuf.Meta.RuntimeTypeModel.Default.Serialize(stream, tableData);
                    stream.Close();
                }
            }
        }
        AssetDatabase.Refresh();
    }