Exemple #1
0
        protected void ExportMeta(IExportCollection collection, string filePath)
        {
            Meta   meta     = new Meta(collection);
            string metaPath = $"{filePath}.meta";

            YAMLExporter.Export(meta, metaPath, false);
        }
Exemple #2
0
        public void Export(string path, IEnumerable <Object> objects)
        {
            if (IsExporting)
            {
                throw new InvalidOperationException("Unable to start a new export process until the old one is completed");
            }

            // 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(objects);
            depSet.UnionWith(depList);
            for (int i = 0; i < depList.Count; i++)
            {
                Object current = depList[i];
                if (!queued.Contains(current))
                {
                    ClassIDType       exportID   = current.IsAsset ? current.ClassID : ClassIDType.Component;
                    IAssetExporter    exporter   = m_exporters[exportID];
                    IExportCollection collection = exporter.CreateCollection(current);

                    foreach (Object element in collection.Objects)
                    {
                        queued.Add(element);
                    }
                    m_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 dep in current.FetchDependencies(true))
                    {
                        if (!depSet.Contains(dep))
                        {
                            depList.Add(dep);
                            depSet.Add(dep);
                        }
                    }
                }
            }
            depList.Clear();
            depSet.Clear();
            queued.Clear();

            foreach (IExportCollection collection in m_collections)
            {
                m_currentCollection = collection;
                bool isExported = collection.AssetExporter.Export(collection, path);
                if (isExported)
                {
                    Logger.Log(LogType.Info, LogCategory.Export, $"'{collection.Name}' exported");
                }
            }

            m_currentCollection = null;
            m_collections.Clear();
        }
Exemple #3
0
        public override bool Export(IAssetsExporter exporter, IExportCollection collection, string dirPath)
        {
            AssetExportCollection asset = (AssetExportCollection)collection;

            exporter.File = asset.Asset.File;

            string subFolder = asset.Asset.ClassID.ToString();
            string subPath   = Path.Combine(dirPath, subFolder);
            string fileName  = GetUniqueFileName(asset.Asset, subPath);
            string filePath  = Path.Combine(subPath, fileName);

            if (!Directory.Exists(subPath))
            {
                Directory.CreateDirectory(subPath);
            }

            exporter.File = asset.Asset.File;
            using (FileStream fileStream = new FileStream(filePath, FileMode.CreateNew, FileAccess.Write))
            {
                asset.Asset.ExportBinary(exporter, fileStream);
            }

            ExportMeta(exporter, asset, filePath);
            return(true);
        }
Exemple #4
0
        public override bool Export(IExportCollection collection, string dirPath)
        {
            AssetExportCollection asset = (AssetExportCollection)collection;

            byte[] data = asset.Asset.ExportBinary();
            if (data == null)
            {
                return(false);
            }

            string subFolder = asset.Asset.ClassID.ToString();
            string subPath   = Path.Combine(dirPath, subFolder);
            string fileName  = GetUniqueFileName(asset.Asset, subPath);
            string filePath  = Path.Combine(subPath, fileName);

            if (!Directory.Exists(subPath))
            {
                Directory.CreateDirectory(subPath);
            }
            using (FileStream fileStream = new FileStream(filePath, FileMode.CreateNew, FileAccess.Write))
            {
                using (BinaryWriter writer = new BinaryWriter(fileStream))
                {
                    writer.Write(data);
                }
            }
            ExportMeta(asset, filePath);
            return(true);
        }
        public override bool Export(IAssetsExporter exporter, IExportCollection collection, string dirPath)
        {
            AssetExportCollection asset = (AssetExportCollection)collection;
            string subFolder            = asset.Asset.ClassID.ToString();
            string subPath  = Path.Combine(dirPath, subFolder);
            string fileName = GetUniqueFileName(asset.Asset, subPath);
            string filePath = Path.Combine(subPath, fileName);

            if (!Directory.Exists(subPath))
            {
                Directory.CreateDirectory(subPath);
            }

            if (asset is PrefabExportCollection prefab)
            {
                ExportYAML(exporter, prefab.Objects, filePath);
            }
            else
            {
                ExportYAML(exporter, asset.Asset, filePath);
            }

            exporter.File = asset.Asset.File;
            ExportMeta(exporter, asset, filePath);

            return(true);
        }
Exemple #6
0
        public void Export(string path, IEnumerable <Object> objects)
        {
            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(objects);
            depSet.UnionWith(depList);
            for (int i = 0; i < depList.Count; i++)
            {
                Object current = depList[i];
                if (!queued.Contains(current))
                {
                    ClassIDType       exportID   = current.IsAsset ? current.ClassID : ClassIDType.Component;
                    IAssetExporter    exporter   = m_exporters[exportID];
                    IExportCollection collection = exporter.CreateCollection(current);

                    foreach (Object element in collection.Objects)
                    {
                        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 current.FetchDependencies(true))
                    {
                        if (dependency == null)
                        {
                            continue;
                        }

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

            AssetsExportContainer container = new AssetsExportContainer(this, collections);
            foreach (IExportCollection collection in collections)
            {
                container.CurrentCollection = collection;
                bool isExported = collection.AssetExporter.Export(container, collection, path);
                if (isExported)
                {
                    Logger.Log(LogType.Info, LogCategory.Export, $"'{collection.Name}' exported");
                }
            }
        }
Exemple #7
0
 public Meta(IExportCollection collection)
 {
     if (collection == null)
     {
         throw new ArgumentNullException(nameof(collection));
     }
     m_collection = collection;
 }
        public void Export(string path, FileCollection fileCollection, IEnumerable <Object> assets)
        {
            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();

            ProjectAssetContainer container = new ProjectAssetContainer(this, fileCollection.FetchAssets(), virtualFile, collections);
            foreach (IExportCollection collection in collections)
            {
                container.CurrentCollection = collection;
                bool isExported = collection.Export(container, path);
                if (isExported)
                {
                    Logger.Log(LogType.Info, LogCategory.Export, $"'{collection.Name}' exported");
                }
            }
        }
Exemple #9
0
        public override bool Export(IAssetsExporter exporter, IExportCollection collection, string dirPath)
        {
            switch (collection)
            {
#warning TODO: make universal!
            case SceneExportCollection scene:
            {
                string subFolder = "Scenes";
                string subPath   = Path.Combine(dirPath, subFolder);
                string fileName  = $"{scene.Name}.unity";
                string filePath  = Path.Combine(subPath, fileName);

                if (!Directory.Exists(subPath))
                {
                    Directory.CreateDirectory(subPath);
                }

                ExportYAML(exporter, scene.Objects, filePath);
                ExportMeta(exporter, scene, filePath);
            }
            break;

            case AssetExportCollection asset:
            {
                string subFolder = asset.Asset.ClassID.ToString();
                string subPath   = Path.Combine(dirPath, subFolder);
                string fileName  = GetUniqueFileName(asset.Asset, subPath);
                string filePath  = Path.Combine(subPath, fileName);

                if (!Directory.Exists(subPath))
                {
                    Directory.CreateDirectory(subPath);
                }

                if (asset is PrefabExportCollection prefab)
                {
                    ExportYAML(exporter, prefab.Objects, filePath);
                }
                else
                {
                    ExportYAML(exporter, asset.Asset, filePath);
                }

                exporter.File = asset.Asset.File;
                ExportMeta(exporter, asset, filePath);
            }
            break;

            default:
                throw new NotSupportedException(collection.GetType().Name);
            }

            return(true);
        }
        protected void ExportMeta(IAssetsExporter exporter, IExportCollection collection, string filePath)
        {
            Meta   meta     = new Meta(collection);
            string metaPath = $"{filePath}.meta";

            using (FileStream fileStream = File.Open(metaPath, FileMode.Create, FileAccess.Write))
            {
                using (StreamWriter streamWriter = new StreamWriter(fileStream))
                {
                    YAMLWriter   writer = new YAMLWriter();
                    YAMLDocument doc    = meta.ExportYAMLDocument(exporter);
                    writer.IsWriteDefaultTag = false;
                    writer.IsWriteVersion    = false;
                    writer.AddDocument(doc);
                    writer.Write(streamWriter);
                }
            }
        }
        public override void Export(IExportCollection collection, string dirPath)
        {
            AssetExportCollection asset = (AssetExportCollection)collection;
            string subFolder            = asset.Asset.ClassID.ToString();
            string subPath  = Path.Combine(dirPath, subFolder);
            string fileName = GetUniqueFileName(asset.Asset, subPath);
            string filePath = Path.Combine(subPath, fileName);

            PrefabExportCollection prefab = collection as PrefabExportCollection;

            if (prefab == null)
            {
                YAMLExporter.Export(asset.Asset, filePath);
            }
            else
            {
                YAMLExporter.Export(prefab.Objects, filePath);
            }
            ExportMeta(collection, filePath);
        }
Exemple #12
0
        public override bool Export(IAssetsExporter exporter, IExportCollection collection, string dirPath)
        {
            AssetExportCollection asset     = (AssetExportCollection)collection;
            AudioClip             audioClip = (AudioClip)asset.Asset;

            exporter.File = audioClip.File;

            string subFolder = audioClip.ClassID.ToString();
            string subPath   = Path.Combine(dirPath, subFolder);
            string fileName  = GetUniqueFileName(audioClip, subPath);

            if (IsSupported(audioClip))
            {
                fileName = $"{Path.GetFileNameWithoutExtension(fileName)}.wav";
            }
            string filePath = Path.Combine(subPath, fileName);

            if (!Directory.Exists(subPath))
            {
                Directory.CreateDirectory(subPath);
            }

            exporter.File = audioClip.File;

            using (FileStream fileStream = new FileStream(filePath, FileMode.CreateNew, FileAccess.Write))
            {
                if (IsSupported(audioClip))
                {
                    ExportAudioClip(fileStream, audioClip);
                }
                else
                {
                    Logger.Instance.Log(LogType.Warning, LogCategory.Export, $"AudioClip type {GetAudioType(audioClip)} isn't supported");
                    audioClip.ExportBinary(exporter, fileStream);
                }
            }

            ExportMeta(exporter, asset, filePath);
            return(IsSupported(audioClip));
        }
        public override bool Export(IAssetsExporter exporter, IExportCollection collection, string dirPath)
        {
            AssetExportCollection asset = (AssetExportCollection)collection;

            exporter.File = asset.Asset.File;

            string subFolder = asset.Asset.ClassID.ToString();
            string subPath   = Path.Combine(dirPath, subFolder);
            string fileName  = GetUniqueFileName(asset.Asset, subPath);
            string filePath  = Path.Combine(subPath, fileName);

            if (!Directory.Exists(subPath))
            {
                Directory.CreateDirectory(subPath);
            }

            exporter.File = asset.Asset.File;
            using (FileStream fileStream = new FileStream(filePath, FileMode.CreateNew, FileAccess.Write))
            {
                asset.Asset.ExportBinary(exporter, fileStream);
            }

            // Exporting file without encoded in here with .bytes extension
            if (asset.Asset.ClassIDName == "TextAsset")
            {
                byte[] bytes = ((TextAsset)asset.Asset).OriginalBytes;
                if (bytes != null)
                {
                    FileStream fs = new FileStream(filePath + ".bytes", FileMode.CreateNew, FileAccess.Write);
                    fs.Write(bytes, 0, bytes.Length);
                    fs.Close();
                }
            }

            ExportMeta(exporter, asset, filePath);
            return(true);
        }
 public bool Export(IExportCollection collection, string dirPath)
 {
     return(false);
 }
Exemple #15
0
 public abstract void Export(IExportCollection collection, string dirPath);
Exemple #16
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 #17
0
 public bool Export(IAssetsExporter exporter, IExportCollection collection, string dirPath)
 {
     return(false);
 }
Exemple #18
0
 public void Export(IExportCollection collection, string dirPath)
 {
 }
 public abstract bool Export(IAssetsExporter exporter, IExportCollection collection, string dirPath);