//Refer MonoManager, ScriptAssetExporter, ScriptExportManager
        void DoExport(Func <MonoScript, bool> selector = null)
        {
            var managedPath            = Path.Combine(GameDir, "Managed");
            var globalgamemanagersPath = Path.Combine(GameDir, "globalgamemanagers.assets");
            var gameStructure          = GameStructure.Load(new string[]
            {
                globalgamemanagersPath,
                managedPath
            });

            fileCollection = gameStructure.FileCollection;
            if (selector == null)
            {
                selector = (o) => true;
            }
            var assets = fileCollection.FetchAssets().Where(o => o is MonoScript ms && selector(ms)).ToArray();
            ScriptExportManager scriptManager = new ScriptExportManager(ExportPath);
            Dictionary <Object, ScriptExportType> exportTypes = new Dictionary <Object, ScriptExportType>();

            foreach (Object asset in assets)
            {
                MonoScript       script     = (MonoScript)asset;
                ScriptExportType exportType = script.GetExportType(scriptManager);
                exportTypes.Add(asset, exportType);
            }
            foreach (KeyValuePair <Object, ScriptExportType> exportType in exportTypes)
            {
                string path = scriptManager.Export(exportType.Value);
            }
            //scriptManager.ExportRest();
        }
        void DoExportDLL(string dllPath)
        {
            fileCollection = new FileCollection(new FileCollection.Parameters()
            {
                RequestAssemblyCallback = RequestAssembly,
                RequestResourceCallback = RequestResource
            });
            fileCollection.AssemblyManager.ScriptingBackEnd = ScriptingBackEnd.Mono;
            var assemblyManager = (AssemblyManager)fileCollection.AssemblyManager;

            fileCollection.AssemblyManager.Load(dllPath);
            fileCollection.Exporter.Export(ExportPath, fileCollection, new Object[] { }, options);
            ScriptExportManager scriptManager = new ScriptExportManager(ExportPath);
            AssemblyDefinition  myLibrary     = AssemblyDefinition.ReadAssembly(dllPath);
            var refrences = myLibrary.MainModule.AssemblyReferences;

            foreach (TypeDefinition type in myLibrary.MainModule.Types)
            {
                //TODO: only export unity serializable classes
                if (!type.IsClass || type.Name == "<Module>")
                {
                    continue;
                }
                var libName    = myLibrary.Name.Name;
                var @namespace = type.Namespace;
                var className  = type.Name;
                var scriptID   = assemblyManager.GetScriptID(libName, @namespace, className);
                var exportType = assemblyManager.GetExportType(scriptManager, scriptID);
                scriptManager.Export(exportType);
            }
        }
Ejemplo n.º 3
0
        void DoExportDLL(string dllPath)
        {
            var fileCollection  = Util.CreateGameCollection();
            var assemblyManager = (AssemblyManager)fileCollection.AssemblyManager;

            fileCollection.AssemblyManager.Load(dllPath);
            fileCollection.Exporter.Export(ExportPath, fileCollection, new SerializedFile[] { }, options);

            ScriptExportManager scriptManager = new ScriptExportManager(fileCollection.Layout, ExportPath);
            AssemblyDefinition  myLibrary     = AssemblyDefinition.ReadAssembly(dllPath);
            var refrences = myLibrary.MainModule.AssemblyReferences;

            foreach (TypeDefinition type in myLibrary.MainModule.Types)
            {
                //TODO: only export unity serializable classes
                if (!type.IsClass || type.Name == "<Module>")
                {
                    continue;
                }
                var libName    = myLibrary.Name.Name;
                var @namespace = type.Namespace;
                var className  = type.Name;
                var scriptID   = assemblyManager.GetScriptID(libName, @namespace, className);
                var exportType = assemblyManager.GetExportType(scriptManager, scriptID);
                scriptManager.Export(exportType);
            }
        }
Ejemplo n.º 4
0
        public void Export(IExportContainer container, IEnumerable <Object> assets, string dirPath, Action <IExportContainer, Object, string> callback)
        {
            ScriptExportManager scriptManager = new ScriptExportManager(dirPath);

            foreach (Object asset in assets)
            {
                MonoScript       script     = (MonoScript)asset;
                ScriptExportType exportType = script.CreateExportType(scriptManager);
                string           path       = scriptManager.Export(exportType);
                if (path != null)
                {
                    callback?.Invoke(container, asset, path);
                }
            }
            scriptManager.ExportRest();
        }
Ejemplo n.º 5
0
        public void Export(IExportContainer container, IEnumerable <Object> assets, string dirPath, Action <IExportContainer, Object, string> callback)
        {
            ScriptExportManager scriptManager = new ScriptExportManager(dirPath);
            Dictionary <Object, ScriptExportType> exportTypes = new Dictionary <Object, ScriptExportType>();

            foreach (Object asset in assets)
            {
                MonoScript       script     = (MonoScript)asset;
                ScriptExportType exportType = script.GetExportType(scriptManager);
                exportTypes.Add(asset, exportType);
            }
            foreach (KeyValuePair <Object, ScriptExportType> exportType in exportTypes)
            {
                string path = scriptManager.Export(exportType.Value);
                if (path != null)
                {
                    callback?.Invoke(container, exportType.Key, path);
                }
            }
            scriptManager.ExportRest();
        }
        //Refer MonoManager, ScriptAssetExporter, ScriptExportManager
        void DoExport(Func <MonoScript, bool> selector = null)
        {
            var managedPath            = Path.Combine(GameDir, "Managed");
            var globalgamemanagersPath = Path.Combine(GameDir, "globalgamemanagers.assets");
            var gameStructure          = GameStructure.Load(new string[]
            {
                globalgamemanagersPath,
                managedPath
            });

            fileCollection = gameStructure.FileCollection;
            if (selector == null)
            {
                selector = (o) => true;
            }
            var assets = fileCollection.FetchAssets().Where(o => o is MonoScript ms && selector(ms)).ToArray();
            ScriptExportManager scriptManager = new ScriptExportManager(ExportPath);
            Dictionary <Object, ScriptExportType> exportTypes = new Dictionary <Object, ScriptExportType>();

            foreach (Object asset in assets)
            {
                MonoScript script = (MonoScript)asset;
                if (ScriptByName)
                {
                    using (MD5 md5 = MD5.Create())
                    {
                        var data    = md5.ComputeHash(Encoding.UTF8.GetBytes($"{script.AssemblyName}.{script.Namespace}.{script.ClassName}"));
                        var newGuid = new Guid(data);
                        Util.SetGUID(script, newGuid);
                    }
                }
                ScriptExportType exportType = script.GetExportType(scriptManager);
                exportTypes.Add(asset, exportType);
            }
            foreach (KeyValuePair <Object, ScriptExportType> exportType in exportTypes)
            {
                string path = scriptManager.Export(exportType.Value);
            }
            //scriptManager.ExportRest();
        }