public static void ExportAsset([DefaultVar] UnityParser parser, int pathID, string path) { Component asset = parser.Cabinet.FindComponent(pathID); if (asset != null) { FileInfo file = new FileInfo(path + "." + asset.classID1); DirectoryInfo dir = file.Directory; if (!dir.Exists) { dir.Create(); } using (FileStream fs = file.Create()) { NeedsSourceStreamForWriting notLoaded = asset as NeedsSourceStreamForWriting; if (notLoaded != null) { notLoaded.SourceStream = File.OpenRead(parser.FilePath); } asset.WriteTo(fs); if (notLoaded != null) { notLoaded.SourceStream.Close(); notLoaded.SourceStream.Dispose(); notLoaded.SourceStream = null; } } } }
public static void ExportUnity3d([DefaultVar] UnityParser parser, string path) { if (path == String.Empty) { path = @".\"; } DirectoryInfo dir = new DirectoryInfo(path); if (!dir.Exists) { dir.Create(); } using (Stream sourceStream = File.OpenRead(parser.FilePath)) { for (int i = 0; i < parser.Cabinet.Components.Count; i++) { var asset = parser.Cabinet.Components[i]; using (FileStream fs = File.Create(dir.FullName + @"\" + asset.pathID + "." + asset.classID1)) { NeedsSourceStreamForWriting notLoaded = asset as NeedsSourceStreamForWriting; if (notLoaded != null) { notLoaded.SourceStream = sourceStream; } asset.WriteTo(fs); if (notLoaded != null) { notLoaded.SourceStream = null; } } } } }
public static void ExportAsset([DefaultVar] UnityParser parser, Component asset, string path) { FileInfo file = new FileInfo(path + "." + (asset.classID() == UnityClassID.MonoBehaviour ? ((int)asset.classID1).ToString() : asset.classID().ToString())); DirectoryInfo dir = file.Directory; if (!dir.Exists) { dir.Create(); } using (FileStream fs = file.Create()) { NeedsSourceStreamForWriting notLoaded = asset as NeedsSourceStreamForWriting; if (notLoaded != null) { notLoaded.SourceStream = parser.Uncompressed == null?File.OpenRead(parser.FilePath) : parser.Uncompressed; } try { asset.WriteTo(fs); } finally { if (notLoaded != parser.Uncompressed) { notLoaded.SourceStream.Close(); notLoaded.SourceStream.Dispose(); notLoaded.SourceStream = null; } } } }