Exemple #1
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();
        }
Exemple #2
0
        public void Export(string path, FileCollection fileCollection, IEnumerable <Object> assets)
        {
            EventExportPreparationStarted?.Invoke();
            VirtualSerializedFile    virtualFile = new VirtualSerializedFile();
            List <IExportCollection> collections = new List <IExportCollection>();
            // speed up fetching a little bit
            List <Object>    depList = new List <Object>();
            HashSet <Object> depSet  = new HashSet <Object>();
            HashSet <Object> queued  = new HashSet <Object>();

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

#warning TODO: if IsGenerateGUIDByContent set it should build collections and write actual references with persistent GUIS, but skip dependencies
                if (Config.IsExportDependencies)
                {
                    foreach (Object dependency in asset.FetchDependencies(true))
                    {
                        if (dependency == null)
                        {
                            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, fileCollection.FetchAssets(), virtualFile, 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();
        }