Beispiel #1
0
        public static BuildCommandSet GenerateBuildCommandSet(BuildInput input, BuildSettings settings)
        {
            // Need to specal case sprites as we only want to include the source texutre in certain situations
            m_SpriteMap.Clear();

            // Create commands array matching the size of the input
            var commandSet = new BuildCommandSet();

            commandSet.commands = new BuildCommandSet.Command[input.definitions.Length];
            for (var i = 0; i < input.definitions.Length; ++i)
            {
                var definition = input.definitions[i];

                // Populate each command from asset bundle definition
                var command = new BuildCommandSet.Command();
                command.assetBundleName = definition.assetBundleName;
                command.explicitAssets  = new BuildCommandSet.AssetLoadInfo[definition.explicitAssets.Length];

                // Fill out asset load info and references for each asset in the definition
                var allObjects = new HashSet <ObjectIdentifier>();
                for (var j = 0; j < definition.explicitAssets.Length; ++j)
                {
                    var explicitAsset = new BuildCommandSet.AssetLoadInfo();
                    explicitAsset.asset             = definition.explicitAssets[j];
                    explicitAsset.path              = AssetDatabase.GUIDToAssetPath(explicitAsset.asset.ToString());
                    explicitAsset.includedObjects   = AssetBundleBuildInterface.GetPlayerObjectIdentifiersInAsset(definition.explicitAssets[j]);
                    explicitAsset.referencedObjects = AssetBundleBuildInterface.GetPlayerDependenciesForObjects(explicitAsset.includedObjects);

                    // Is this asset a sprite?
                    var type = AssetDatabase.GetMainAssetTypeAtPath(explicitAsset.path);
                    if (type == typeof(Texture2D) && explicitAsset.referencedObjects.Length == 1)
                    {
                        // Source texture should always be the first included object, atlas should always be the first referenced object
                        m_SpriteMap.Add(explicitAsset.referencedObjects[0].guid);
                    }

                    command.explicitAssets[j] = explicitAsset;
                    allObjects.UnionWith(explicitAsset.includedObjects);
                    allObjects.UnionWith(explicitAsset.referencedObjects);
                }

                command.assetBundleObjects = allObjects.ToArray();
                commandSet.commands[i]     = command;
            }

            // TODO: Debug printing
            DebugPrintCommandSet(ref commandSet);

            // At this point, We have generated fully self contained asset bundles with 0 dependencies.
            // Default implementation is to reduce duplication of objects by declaring dependencies to other asset
            //    bundles if that other asset bundle has an explicit asset declared that contains the objects needed
            // We also remove any built in unity objects as they are built with the player (We may want to change this part in the future)
            CalculateAssetBundleBuildDependencies(ref commandSet);
            // Note: I may, or may not feel dirty doing mutable things to what otherwise should be immutable struct

            // TODO: Debug printing
            DebugPrintCommandSet(ref commandSet);

            return(commandSet);
        }
Beispiel #2
0
        static void BuildAssetBundlesMenuItem()
        {
            var input       = AssetBundleBuildInterface.GenerateAssetBundleBuildInput();
            var settings    = GenerateBuildSettings();
            var compression = GenerateBuildCompression();

            // Rebuild sprite atlas cache for correct dependency calculation & writting
            Packer.RebuildAtlasCacheIfNeeded(settings.target, true, Packer.Execution.Normal);

            // Generate command set with dependencies
            var commands = GenerateBuildCommandSet(input, settings);

            // Ensure the output path is created
            // TODO: mabe we should do something if it exists, incremental building?
            Directory.CreateDirectory(settings.outputFolder);
            var output = AssetBundleBuildInterface.WriteResourcefilesForAssetBundles(commands, settings);

            foreach (var bundle in output.results)
            {
                var filePath = Path.Combine(settings.outputFolder, bundle.assetBundleName);
                Directory.CreateDirectory(Path.GetDirectoryName(filePath));
                AssetBundleBuildInterface.ArchiveAndCompressAssetBundle(bundle.resourceFiles, filePath, compression);
            }

            CacheAssetBundleBuildOutput(output, settings);
        }
        static void BuildAssetBundlesMenuItem()
        {
            var input       = AssetBundleBuildInterface.GenerateAssetBundleBuildInput();
            var settings    = GenerateBuildSettings();
            var compression = GenerateBuildCompression();
            var commands    = GenerateBuildCommandSet(input, settings);

            // Ensure the output path is created
            // TODO: mabe we should do something if it exists, incremental building?
            Directory.CreateDirectory(settings.outputFolder);
            var output = AssetBundleBuildInterface.WriteResourcefilesForAssetBundles(commands, settings);
            //foreach (var bundle in output.results)
            //	AssetBundleBuildInterface.ArchiveAndCompressAssetBundle(bundle.resourceFiles, Path.Combine(settings.outputFolder, bundle.assetBundleName), compression);

            //CacheAssetBundleBuildOutput(output, settings);
        }