Exemple #1
0
        private BuildPipelineCodes ExperimentalBuildPipeline()
        {
            var playerSettings = PlayerBuildPipeline.GeneratePlayerBuildSettings(m_Settings.buildTarget, m_Settings.buildGroup);
            ScriptCompilationResult scriptResults;
            var errorCode = PlayerBuildPipeline.BuildPlayerScripts(playerSettings, out scriptResults);

            if (errorCode < BuildPipelineCodes.Success)
            {
                return(errorCode);
            }

            var bundleSettings = BundleBuildPipeline.GenerateBundleBuildSettings(scriptResults.typeDB, m_Settings.buildTarget, m_Settings.buildGroup);

            BuildCompression compression = BuildCompression.DefaultLZ4;

            if (m_Settings.compressionType == CompressionType.None)
            {
                compression = BuildCompression.DefaultUncompressed;
            }
            else if (m_Settings.compressionType == CompressionType.Lzma)
            {
                compression = BuildCompression.DefaultLZMA;
            }

            BundleBuildResult bundleResult;

            errorCode = BundleBuildPipeline.BuildAssetBundles(BundleBuildInterface.GenerateBuildInput(), bundleSettings, compression, m_Settings.outputPath, out bundleResult, null, m_Settings.useBuildCache);
            return(errorCode);
        }
Exemple #2
0
        private void WriteSerialziedFiles(string bundleName, IWriteOperation op, List <WriteCommand> allCommands, BuildSettings settings, BuildUsageTagGlobal globalUsage, ref List <WriteResult> outResults)
        {
            WriteResult result;
            var         dependencies = op.CalculateDependencies(allCommands);

            var objectIDs    = op.command.serializeObjects.Select(x => x.serializationObject).ToArray();
            var dependentIDs = dependencies.SelectMany(x => x.serializeObjects.Select(y => y.serializationObject)).ToArray();

            BuildUsageTagSet buildUsage = new BuildUsageTagSet();

            BundleBuildInterface.CalculateBuildUsageTags(objectIDs, dependentIDs, globalUsage, buildUsage);

            Hash128 hash = CalculateInputHash(op, dependencies, settings, globalUsage, buildUsage);

            if (UseCache && BuildCache.TryLoadCachedResults(hash, out result))
            {
                outResults.Add(result);
                return;
            }

            result = op.Write(GetBuildPath(hash), dependencies, settings, globalUsage, buildUsage);
            outResults.Add(result);

            if (UseCache && !BuildCache.SaveCachedResults(hash, result))
            {
                BuildLogger.LogWarning("Unable to cache CommandSetWriter results for command '{0}'.", op.command.internalName);
            }
        }
        public override BuildPipelineCodes Convert(GUID asset, BuildSettings settings, out AssetLoadInfo output)
        {
            StartProgressBar("Calculating Asset Dependencies", 2);

            if (!ValidAsset(asset))
            {
                output = new AssetLoadInfo();
                EndProgressBar();
                return(BuildPipelineCodes.Error);
            }

            Hash128 hash = CalculateInputHash(asset, settings);

            if (UseCache && BuildCache.TryLoadCachedResults(hash, out output))
            {
                if (!EndProgressBar())
                {
                    return(BuildPipelineCodes.Canceled);
                }
                return(BuildPipelineCodes.SuccessCached);
            }

            output       = new AssetLoadInfo();
            output.asset = asset;

            if (!UpdateProgressBar("Calculating included objects"))
            {
                EndProgressBar();
                return(BuildPipelineCodes.Canceled);
            }
            output.includedObjects = new List <ObjectIdentifier>(BundleBuildInterface.GetPlayerObjectIdentifiersInAsset(asset, settings.target));

            if (!UpdateProgressBar("Calculating referenced objects"))
            {
                EndProgressBar();
                return(BuildPipelineCodes.Canceled);
            }
            output.referencedObjects = new List <ObjectIdentifier>(BundleBuildInterface.GetPlayerDependenciesForObjects(output.includedObjects.ToArray(), settings.target, settings.typeDB));

            if (UseCache && !BuildCache.SaveCachedResults(hash, output))
            {
                BuildLogger.LogWarning("Unable to cache AssetDependency results for asset '{0}'.", asset);
            }

            if (!EndProgressBar())
            {
                return(BuildPipelineCodes.Canceled);
            }
            return(BuildPipelineCodes.Success);
        }
        public override BuildPipelineCodes Convert(List <BuildOutput.Result> writenData, SceneResourceMap sceneResources, BuildCompression compression, string outputFolder, out BundleCRCMap output)
        {
            StartProgressBar("Archiving Resource Files", writenData.Count);
            output = new BundleCRCMap();

            foreach (var bundle in writenData)
            {
                if (!UpdateProgressBar(string.Format("Bundle: {0}", bundle.assetBundleName)))
                {
                    EndProgressBar();
                    return(BuildPipelineCodes.Canceled);
                }

                var resourceFiles = new List <ResourceFile>(bundle.resourceFiles);
                foreach (var asset in bundle.assetBundleAssets)
                {
                    ResourceFile[] sceneFiles;
                    if (!sceneResources.TryGetValue(asset, out sceneFiles))
                    {
                        continue;
                    }
                    resourceFiles.AddRange(sceneFiles);
                }

                var filePath = string.Format("{0}/{1}", outputFolder, bundle.assetBundleName);

                uint    crc;
                Hash128 hash = CalculateInputHash(resourceFiles, compression);
                if (UseCache && TryLoadFromCache(hash, outputFolder, out crc))
                {
                    output[filePath] = crc;
                    continue;
                }

                crc = BundleBuildInterface.ArchiveAndCompress(resourceFiles.ToArray(), filePath, compression);
                output[filePath] = crc;

                if (UseCache && !TrySaveToCache(hash, bundle.assetBundleName, crc, outputFolder))
                {
                    BuildLogger.LogWarning("Unable to cache ResourceFileArchiver result for bundle {0}.", bundle.assetBundleName);
                }
            }

            if (!EndProgressBar())
            {
                return(BuildPipelineCodes.Canceled);
            }
            return(BuildPipelineCodes.Success);
        }
        public override BuildPipelineCodes Convert(GUID scene, BuildSettings settings, BuildUsageTagSet usageSet, out SceneDependencyInfo output)
        {
            StartProgressBar("Calculating Scene Dependencies", 1);
            if (!ValidScene(scene))
            {
                output = new SceneDependencyInfo();
                EndProgressBar();
                return(BuildPipelineCodes.Error);
            }

            var scenePath = AssetDatabase.GUIDToAssetPath(scene.ToString());

            if (!UpdateProgressBar(scenePath))
            {
                output = new SceneDependencyInfo();
                EndProgressBar();
                return(BuildPipelineCodes.Canceled);
            }

            Hash128 hash = CalculateInputHash(scene, settings);

            if (UseCache && BuildCache.TryLoadCachedResults(hash, out output) && BuildCache.TryLoadCachedResults(hash, out usageSet))
            {
                if (!EndProgressBar())
                {
                    return(BuildPipelineCodes.Canceled);
                }
                return(BuildPipelineCodes.SuccessCached);
            }

            output = BundleBuildInterface.PrepareScene(scenePath, settings, usageSet, GetBuildPath(hash));

            if (UseCache && !BuildCache.SaveCachedResults(hash, output) && !BuildCache.SaveCachedResults(hash, usageSet))
            {
                BuildLogger.LogWarning("Unable to cache SceneDependency results for asset '{0}'.", scene);
            }

            if (!EndProgressBar())
            {
                return(BuildPipelineCodes.Canceled);
            }
            return(BuildPipelineCodes.Success);
        }
Exemple #6
0
        public override BuildPipelineCodes Convert(BuildResultInfo resultInfo, BuildCompression compression, string outputFolder, out BundleCRCMap output)
        {
            StartProgressBar("Archiving Resource Files", resultInfo.bundleResults.Count);
            output = new BundleCRCMap();

            foreach (var bundle in resultInfo.bundleResults)
            {
                if (!UpdateProgressBar(string.Format("Bundle: {0}", bundle.Key)))
                {
                    EndProgressBar();
                    return(BuildPipelineCodes.Canceled);
                }

                var resourceFiles = new List <ResourceFile>(bundle.Value.SelectMany(x => x.resourceFiles));

                var filePath = string.Format("{0}/{1}", outputFolder, bundle.Key);

                uint    crc;
                Hash128 hash = CalculateInputHash(resourceFiles, compression);
                if (UseCache && TryLoadFromCache(hash, outputFolder, out crc))
                {
                    output[filePath] = crc;
                    continue;
                }

                crc = BundleBuildInterface.ArchiveAndCompress(resourceFiles.ToArray(), filePath, compression);
                output[filePath] = crc;

                if (UseCache && !TrySaveToCache(hash, bundle.Key, crc, outputFolder))
                {
                    BuildLogger.LogWarning("Unable to cache ResourceFileArchiver result for bundle {0}.", bundle.Key);
                }
            }

            if (!EndProgressBar())
            {
                return(BuildPipelineCodes.Canceled);
            }
            return(BuildPipelineCodes.Success);
        }
        public override BuildPipelineCodes Convert(BuildCommandSet commandSet, BuildSettings settings, out List <WriteResult> output)
        {
            StartProgressBar("Writing Resource Files", commandSet.commands.Count);
            CacheDataForCommandSet(commandSet);

            output = new List <WriteResult>();
            foreach (var command in commandSet.commands)
            {
                if (!UpdateProgressBar(string.Format("Bundle: {0}", command.assetBundleName)))
                {
                    EndProgressBar();
                    return(BuildPipelineCodes.Canceled);
                }

                BuildOutput result;
                Hash128     hash = CalculateInputHash(command, settings);
                if (UseCache && BuildCache.TryLoadCachedResults(hash, out result))
                {
                    output.AddRange(result.results);
                    continue;
                }

                result = BundleBuildInterface.WriteResourceFilesForBundle(commandSet, command.assetBundleName, settings, GetBuildPath(hash));
                output.AddRange(result.results);

                if (UseCache && !BuildCache.SaveCachedResults(hash, result))
                {
                    BuildLogger.LogWarning("Unable to cache CommandSetWriter results for command '{0}'.", command.assetBundleName);
                }
            }

            if (!EndProgressBar())
            {
                return(BuildPipelineCodes.Canceled);
            }
            return(BuildPipelineCodes.Success);
        }
 public virtual WriteResult Write(string outputFolder, List <WriteCommand> dependencies, BuildSettings settings, BuildUsageTagGlobal globalUsage, BuildUsageTagSet buildUsage)
 {
     return(BundleBuildInterface.WriteSerializedFile(outputFolder, command, dependencies, settings, globalUsage, buildUsage));
 }
 public override WriteResult Write(string outputFolder, List <WriteCommand> dependencies, BuildSettings settings, BuildUsageTagGlobal globalUsage, BuildUsageTagSet buildUsage)
 {
     buildUsage.UnionWith(usageTags);
     return(BundleBuildInterface.WriteSceneSerializedFile(outputFolder, scene, processedScene, command, dependencies, settings, globalUsage, buildUsage, preloadInfo, info));
 }
Exemple #10
0
        public static AssetBundleManifest BuildAssetBundles(string outputPath, BuildAssetBundleOptions assetBundleOptions, BuildTarget targetPlatform)
        {
            var buildInput = BundleBuildInterface.GenerateBuildInput();

            return(BuildAssetBundles_Internal(outputPath, buildInput, assetBundleOptions, targetPlatform));
        }
Exemple #11
0
        public override BuildPipelineCodes Convert(BuildDependencyInfo input, BuildSettings settings, bool aggressive, out BuildDependencyInfo output)
        {
            StartProgressBar("Generated shared object bundles", 3);

            Hash128 hash = CalculateInputHash(input);

            if (UseCache && BuildCache.TryLoadCachedResults(hash, out output))
            {
                EndProgressBar();
                return(BuildPipelineCodes.SuccessCached);
            }

            // Mutating the input
            output = input;

            if (!UpdateProgressBar("Generate lookup of all objects"))
            {
                EndProgressBar();
                return(BuildPipelineCodes.Canceled);
            }

            // Generate mapping of each object to the bundles it would be used by
            var objectToBundles = new Dictionary <ObjectIdentifier, HashSet <string> >();
            var objectToAssets  = new Dictionary <ObjectIdentifier, HashSet <GUID> >();

            foreach (var asset in input.assetInfo.Values)
            {
                var dependencies = input.assetToBundles[asset.asset];

                if (aggressive && !asset.includedObjects.IsNullOrEmpty())
                {
                    for (int i = 1; i < asset.includedObjects.Count; ++i)
                    {
                        var objectID = asset.includedObjects[i];

                        HashSet <string> bundles;
                        objectToBundles.GetOrAdd(objectID, out bundles);
                        bundles.Add(dependencies[0]);

                        HashSet <GUID> assets;
                        objectToAssets.GetOrAdd(objectID, out assets);
                        assets.Add(asset.asset);
                    }
                }

                foreach (var referenceID in asset.referencedObjects)
                {
                    if (!aggressive && input.assetToBundles.ContainsKey(referenceID.guid))
                    {
                        continue;
                    }

                    if (referenceID.filePath == BuildWriteProcessor.kUnityDefaultResourcePath)
                    {
                        continue;
                    }

                    HashSet <string> bundles;
                    objectToBundles.GetOrAdd(referenceID, out bundles);
                    bundles.Add(dependencies[0]);

                    HashSet <GUID> assets;
                    objectToAssets.GetOrAdd(referenceID, out assets);
                    assets.Add(asset.asset);
                }
            }


            if (!UpdateProgressBar("Finding set of reused objects"))
            {
                EndProgressBar();
                return(BuildPipelineCodes.Canceled);
            }

            // Generate the set of reused objects
            var hashToObjects = new Dictionary <Hash128, List <ObjectIdentifier> >();

            foreach (var objectPair in objectToBundles)
            {
                if (objectPair.Value.Count <= 1)
                {
                    continue;
                }

                var bundleHash = HashingMethods.CalculateMD5Hash(objectPair.Value.ToArray());

                List <ObjectIdentifier> objectIDs;
                hashToObjects.GetOrAdd(bundleHash, out objectIDs);
                objectIDs.Add(objectPair.Key);
            }


            if (!UpdateProgressBar("Creating shared object bundles"))
            {
                EndProgressBar();
                return(BuildPipelineCodes.Canceled);
            }

            // Generate Shared Bundles
            foreach (var hashPair in hashToObjects)
            {
                // Generate Dependency Information for virtual asset
                var assetInfo = new AssetLoadInfo();
                assetInfo.asset             = new GUID(hashPair.Key.ToString());
                assetInfo.address           = hashPair.Key.ToString();
                assetInfo.includedObjects   = hashPair.Value.ToList();
                assetInfo.referencedObjects = new List <ObjectIdentifier>();
                assetInfo.includedObjects.Sort((x, y) => { if (x < y)
                                                           {
                                                               return(-1);
                                                           }
                                                           if (x > y)
                                                           {
                                                               return(1);
                                                           }
                                                           return(0); });

                // Add new AssetLoadInfo for virtual asset
                output.assetInfo.Add(assetInfo.asset, assetInfo);
                var assetBundles = new List <string>();
                assetBundles.Add(assetInfo.address);

                // Add new bundle as dependency[0] for virtual asset
                output.assetToBundles.Add(assetInfo.asset, assetBundles);
                var bundleAssets = new List <GUID>();
                bundleAssets.Add(assetInfo.asset);

                // Add virtual asset to the list of assets for new bundle
                output.bundleToAssets.Add(assetInfo.address, bundleAssets);

                // Add virtual asset to lookup
                output.virtualAssets.Add(assetInfo.asset);

                foreach (var objectID in assetInfo.includedObjects)
                {
                    // Add objects in virtual asset to lookup
                    output.objectToVirtualAsset.Add(objectID, assetInfo.asset);
                    var assets = objectToAssets[objectID];
                    foreach (var asset in assets)
                    {
                        if (!output.assetToBundles.TryGetValue(asset, out assetBundles))
                        {
                            continue;
                        }

                        if (assetBundles.Contains(assetInfo.address))
                        {
                            continue;
                        }

                        // Add new bundle as dependency to assets referencing virtual asset objects
                        assetBundles.Add(assetInfo.address);
                    }
                }
            }

            // Generate Shared Bundle Build Dependencies
            foreach (var virtualAsset in output.virtualAssets)
            {
                var assetInfo    = output.assetInfo[virtualAsset];
                var dependencies = output.assetToBundles[virtualAsset];

                var references = BundleBuildInterface.GetPlayerDependenciesForObjects(assetInfo.includedObjects.ToArray(), settings.target, settings.typeDB);
                foreach (var reference in references)
                {
                    GUID          dependency;
                    List <string> bundles;

                    string depStr = "";

                    // If the reference is to an object in a virtual asset, no major checks, just add it as a dependency
                    if (output.objectToVirtualAsset.TryGetValue(reference, out dependency))
                    {
                        if (dependency == virtualAsset)
                        {
                            continue;
                        }

                        depStr = dependency.ToString();
                    }
                    // Otherwise if this reference is part of an asset assigned to a bundle, then set the bundle as a dependency to the virtual asset
                    else if (output.assetToBundles.TryGetValue(reference.guid, out bundles))
                    {
                        if (bundles.IsNullOrEmpty())
                        {
                            continue;
                        }

                        depStr = bundles[0];
                    }

                    if (dependencies.Contains(depStr))
                    {
                        continue;
                    }

                    dependencies.Add(depStr);
                }
            }

            if (UseCache && !BuildCache.SaveCachedResults(hash, output))
            {
                BuildLogger.LogWarning("Unable to cache SharedObjectProcessor results.");
            }

            if (!EndProgressBar())
            {
                return(BuildPipelineCodes.Canceled);
            }
            return(BuildPipelineCodes.Success);
        }