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);
        }
        public override IExportCollection CreateCollection(Object @object)
        {
            if (@object is Component comp)
            {
                @object = comp.GameObject.GetObject(comp.File);
            }
            if (@object.ClassID == ClassIDType.GameObject)
            {
                GameObject go = (GameObject)@object;
                @object = go.GetRoot();
            }

            if (@object.ClassID == ClassIDType.GameObject)
            {
                GameObject go     = (GameObject)@object;
                Prefab     prefab = new Prefab(go);
                IEnumerable <EditorExtension> prefabContent = EnumeratePrefabContent(prefab);
                PrefabExportCollection        collection    = new PrefabExportCollection(this, prefab, prefabContent);
                return(collection);
            }
            else
            {
                if ([email protected])
                {
                    throw new ArgumentException($"Unsupported export object type {@object.ClassID}", nameof(@object));
                }

                AssetExportCollection collection = new AssetExportCollection(this, @object);
                return(collection);
            }
        }
Example #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);
        }
        public string GetExportID(Object @object)
        {
            if (CurrentCollection.IsContains(@object))
            {
                return(CurrentCollection.GetExportID(@object));
            }
            foreach (IExportCollection collection in m_collections)
            {
                if (collection.IsContains(@object))
                {
                    return(collection.GetExportID(@object));
                }
            }

            if (Config.IsExportDependencies)
            {
                throw new InvalidOperationException($"Object {@object} wasn't found in any export collection");
            }
            else
            {
                return(AssetExportCollection.GetMainExportID(@object));
            }
        }
        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 ExportPointer CreateExportPointer(Object @object)
        {
            if (CurrentCollection.IsContains(@object))
            {
                return(CurrentCollection.CreateExportPointer(@object, true));
            }
            foreach (IExportCollection collection in m_collections)
            {
                if (collection.IsContains(@object))
                {
                    return(collection.CreateExportPointer(@object, false));
                }
            }

            if (Config.IsExportDependencies)
            {
                throw new InvalidOperationException($"Object {@object} wasn't found in any export collection");
            }
            else
            {
                string exportID = AssetExportCollection.GetMainExportID(@object);
                return(new ExportPointer(exportID, UtinyGUID.MissingReference, AssetType.Meta));
            }
        }