Exemplo n.º 1
0
        private void CookBundle(string bundleName)
        {
            string bundlePath        = The.Workspace.GetBundlePath(Target.Platform, bundleName);
            bool   wasBundleModified = false;

            using (var bundle = CreateBundle(bundleName)) {
                AssetBundle.SetCurrent(bundle, false);
                (AssetBundle.Current as PackedAssetBundle).OnModifying += () => {
                    if (!wasBundleModified)
                    {
                        wasBundleModified = true;
                        string backupFilePath;
                        TryMakeBackup(bundlePath, out backupFilePath);
                        bundleBackupFiles.Add(backupFilePath);
                    }
                };
                CookBundleHelper(bundleName);
                // Open the bundle again in order to make some plugin post-processing (e.g. generate code from scene assets)
                using (new DirectoryChanger(The.Workspace.AssetsDirectory)) {
                    PluginLoader.AfterAssetsCooked(bundleName);
                }
            }
            if (wasBundleModified)
            {
                PackedAssetBundle.RefreshBundleCheckSum(bundlePath);
            }
        }
Exemplo n.º 2
0
        private AssetBundle CreateOutputBundle(string bundleName, List <string> bundleBackups)
        {
            var bundlePath = The.Workspace.GetBundlePath(Target.Platform, bundleName);

            // Create directory for bundle if it placed in subdirectory
            try {
                Directory.CreateDirectory(Path.GetDirectoryName(bundlePath));
            } catch (System.Exception) {
                Lime.Debug.Write("Failed to create directory: {0} {1}", Path.GetDirectoryName(bundlePath));
                throw;
            }
            var bundle = new PackedAssetBundle(bundlePath, AssetBundleFlags.Writable);

            bundle.OnWrite += () => {
                var backupPath = bundlePath + ".bak";
                if (bundleBackups.Contains(backupPath) || !File.Exists(bundlePath))
                {
                    return;
                }
                try {
                    File.Copy(bundlePath, backupPath, overwrite: true);
                } catch (System.Exception e) {
                    Console.WriteLine(e);
                }
                bundleBackups.Add(backupPath);
            };
            return(bundle);
        }
Exemplo n.º 3
0
 public void CleanupBundle()
 {
     using (var cacheBundle = new PackedAssetBundle(Orange.The.Workspace.TangerineCacheBundle, AssetBundleFlags.Writable)) {
         foreach (var path in cacheBundle.EnumerateFiles())
         {
             cacheBundle.DeleteFile(path);
         }
         Serialization.WriteObjectToBundle(cacheBundle, VersionFile, new CacheMeta(), Serialization.Format.Binary, string.Empty, AssetAttributes.None, new byte[0]);
     }
 }
Exemplo n.º 4
0
 private Stream OpenFbx(string path)
 {
     using (var cacheBundle = new PackedAssetBundle(Orange.The.Workspace.TangerineCacheBundle, AssetBundleFlags.Writable)) {
         var fbxPath = Path.ChangeExtension(path, "fbx");
         if (!cacheBundle.FileExists(path) || GetFileLastWriteTime(fbxPath) > cacheBundle.GetFileLastWriteTime(path))
         {
             var fullPath = Path.Combine(Orange.The.Workspace.AssetsDirectory, fbxPath);
             var model    = new Orange.FbxModelImporter(fullPath, Orange.The.Workspace.ActiveTarget, new Dictionary <string, Orange.CookingRules>()).Model;
             TangerineYuzu.Instance.Value.WriteObjectToBundle(cacheBundle, path, model, Serialization.Format.Binary, ".t3d", AssetAttributes.None, new byte[0]);
         }
     }
     using (var cacheBundle = new PackedAssetBundle(Orange.The.Workspace.TangerineCacheBundle)) {
         return(cacheBundle.OpenFile(path));
     }
 }
Exemplo n.º 5
0
        private static int GetAssetsToRevealCount(TargetPlatform platform, List <string> bundles)
        {
            var assetCount = 0;

            foreach (var bundleName in bundles)
            {
                string bundlePath = The.Workspace.GetBundlePath(platform, bundleName);
                if (!File.Exists(bundlePath))
                {
                    continue;
                }
                using (var bundle = new PackedAssetBundle(bundlePath, AssetBundleFlags.None)) {
                    AssetBundle.SetCurrent(bundle, false);
                    assetCount += AssetBundle.Current.EnumerateFiles().Count();
                }
            }
            return(assetCount);
        }
Exemplo n.º 6
0
        private static void UnpackBundle(TargetPlatform platform, string bundlePath)
        {
            if (!File.Exists(bundlePath))
            {
                Console.WriteLine($"WARNING: {bundlePath} do not exists! Skipping...");
                return;
            }
            string outputDirectory = bundlePath + UnpackedSuffix;

            using (var bundle = new PackedAssetBundle(bundlePath, AssetBundleFlags.None)) {
                AssetBundle.SetCurrent(bundle, false);
                Console.WriteLine("Extracting game content into \"{0}\"", outputDirectory);
                if (Directory.Exists(outputDirectory))
                {
                    Directory.Delete(outputDirectory, true);
                }
                Directory.CreateDirectory(outputDirectory);
                using (new DirectoryChanger(outputDirectory)) {
                    foreach (string asset in AssetBundle.Current.EnumerateFiles())
                    {
                        using (var stream = AssetBundle.Current.OpenFile(asset)) {
                            using (var streamCopy = new MemoryStream()) {
                                stream.CopyTo(streamCopy);
                                streamCopy.Seek(0, SeekOrigin.Begin);
                                var assetPath = ChangeExtensionIfKtx(platform, streamCopy, asset);
                                Console.WriteLine("> " + assetPath);
                                var assetDirectory = Path.GetDirectoryName(assetPath);
                                if (assetDirectory != "")
                                {
                                    Directory.CreateDirectory(assetDirectory);
                                }
                                using (var file = new FileStream(assetPath, FileMode.Create)) {
                                    streamCopy.CopyTo(file);
                                }
                            }
                        }
                        The.UI.IncreaseProgressBar();
                    }
                }
            }
        }
Exemplo n.º 7
0
 public bool IsActual()
 {
     using (var cacheBundle = new PackedAssetBundle(Orange.The.Workspace.TangerineCacheBundle, AssetBundleFlags.Writable)) {
         if (!cacheBundle.FileExists(VersionFile))
         {
             return(false);
         }
         try {
             using (var stream = cacheBundle.OpenFile(VersionFile)) {
                 var cacheMeta = Serialization.ReadObject <CacheMeta>(VersionFile, stream);
                 if (!cacheMeta.IsActual)
                 {
                     return(false);
                 }
             }
         } catch {
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 8
0
        private static void CookBundle(string bundleName)
        {
            string bundlePath = The.Workspace.GetBundlePath(bundleName);
            string backupFilePath;

            TryMakeBackup(bundlePath, out backupFilePath);
            bundleBackupFiles.Add(backupFilePath);

            using (AssetBundle.Current = CreateBundle(bundleName)) {
                CookBundleHelper(bundleName);
            }
            // Open the bundle again in order to make some plugin post-processing (e.g. generate code from scene assets)
            using (AssetBundle.Current = CreateBundle(bundleName)) {
                using (new DirectoryChanger(The.Workspace.AssetsDirectory)) {
                    PluginLoader.AfterAssetsCooked(bundleName);
                }
            }
            if (Platform != TargetPlatform.Unity)
            {
                PackedAssetBundle.RefreshBundleCheckSum(bundlePath);
            }
        }