void DoExportAll()
        {
            Util.PrepareExportDirectory(ExportPath);
            var managedPath   = Path.Combine(GameDir, "Managed");
            var mainAssetPath = GetMainAssetPath();
            var gameStructure = GameStructure.Load(new string[]
            {
                mainAssetPath,
                managedPath
            });

            fileCollection = gameStructure.FileCollection;
            var scripts = fileCollection.FetchAssets().Where(o => o is MonoScript ms).ToArray();

            foreach (Object asset in scripts)
            {
                MonoScript script = (MonoScript)asset;
                if (ScriptByName)
                {
                    using (MD5 md5 = MD5.Create())
                    {
                        var data = md5.ComputeHash(Encoding.UTF8.GetBytes($"{script.AssemblyName}.{script.Namespace}.{script.ClassName}"));
                        Util.SetGUID(script, data);
                    }
                }
            }
            gameStructure.Export(ExportPath, asset => asset is MonoScript);
        }
示例#2
0
        //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(gameStructure.FileCollection.Layout, 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();
        }
示例#3
0
        public void Export(string path, GameCollection fileCollection, IEnumerable <SerializedFile> files, ExportOptions options)
        {
            EventExportPreparationStarted?.Invoke();

            LayoutInfo               info         = new LayoutInfo(options.Version, options.Platform, options.Flags);
            AssetLayout              exportLayout = new AssetLayout(info);
            VirtualSerializedFile    virtualFile  = new VirtualSerializedFile(exportLayout);
            List <IExportCollection> collections  = new List <IExportCollection>();
            // speed up fetching
            List <Object>    depList = new List <Object>();
            HashSet <Object> depSet  = new HashSet <Object>();
            HashSet <Object> queued  = new HashSet <Object>();

            foreach (SerializedFile file in files)
            {
                foreach (Object asset in file.FetchAssets())
                {
                    if (!options.Filter(asset))
                    {
                        continue;
                    }

                    depList.Add(asset);
                    depSet.Add(asset);
                }
            }


            for (int i = 0; i < depList.Count; i++)
            {
                Object asset = depList[i];
                if (!queued.Contains(asset))
                {
                    IExportCollection collection = CreateCollection(virtualFile, asset, options);
                    foreach (Object element in collection.Assets)
                    {
                        queued.Add(element);
                    }
                    collections.Add(collection);
                }

                if (options.ExportDependencies)
                {
                    DependencyContext context = new DependencyContext(exportLayout, true);
                    foreach (PPtr <Object> pointer in asset.FetchDependencies(context))
                    {
                        if (pointer.IsNull)
                        {
                            continue;
                        }

                        Object dependency = pointer.FindAsset(asset.File);
                        if (dependency == null)
                        {
                            string hierarchy = $"[{asset.File.Name}]" + asset.File.GetAssetLogString(asset.PathID) + "." + context.GetPointerPath();
                            Logger.Log(LogType.Warning, LogCategory.Export, $"{hierarchy}'s dependency {context.PointerName} = {pointer.ToLogString(asset.File)} wasn't found");
                            continue;
                        }

                        if (!depSet.Contains(dependency))
                        {
                            depList.Add(dependency);
                            depSet.Add(dependency);
                        }
                    }
                }
            }
            depList.Clear();
            depSet.Clear();
            queued.Clear();
            EventExportPreparationFinished?.Invoke();

            EventExportStarted?.Invoke();
            ProjectAssetContainer container = new ProjectAssetContainer(this, options, virtualFile, fileCollection.FetchAssets(), collections);

            for (int i = 0; i < collections.Count; i++)
            {
                IExportCollection collection = collections[i];
                container.CurrentCollection = collection;
                bool isExported = collection.Export(container, path);
                if (isExported)
                {
                    Logger.Log(LogType.Info, LogCategory.Export, $"'{collection.Name}' exported");
                }
                EventExportProgressUpdated?.Invoke(i, collections.Count);
            }
            EventExportFinished?.Invoke();
        }