public static BuildOutput WriteAllResourceFiles(BuildCommandSet commands, BuildSettings settings, BuildUsageTagSet usageSet, string outputFolder)
        {
            BuildOutput result;

            BundleBuildInterface.WriteAllResourceFiles_Injected(commands, ref settings, usageSet, outputFolder, out result);
            return(result);
        }
Example #2
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);
        }
Example #3
0
        public static BuildOutput WriteResourceFiles(BuildCommandSet commands, BuildSettings settings)
        {
            BuildOutput result;

            BuildInterface.WriteResourceFiles_Injected(ref commands, ref settings, out result);
            return(result);
        }
Example #4
0
        private static void DebugPrintCommandSet(ref BuildCommandSet commandSet)
        {
            var msg = "";

            if (commandSet.commands != null)
            {
                foreach (var bundle in commandSet.commands)
                {
                    msg += string.Format("{0}\n", bundle.assetBundleName);
                    if (bundle.explicitAssets != null)
                    {
                        foreach (var asset in bundle.explicitAssets)
                        {
                            msg += string.Format("\t{0}\n", asset.asset);
                            if (asset.includedObjects != null)
                            {
                                foreach (var obj in asset.includedObjects)
                                {
                                    msg += string.Format("\t\t{0}\n", obj);
                                }
                            }
                            msg += "\t\t------------------------------\n";
                            if (asset.referencedObjects != null)
                            {
                                foreach (var obj in asset.referencedObjects)
                                {
                                    msg += string.Format("\t\t{0}\n", obj);
                                }
                            }
                        }
                    }
                    if (bundle.assetBundleObjects != null)
                    {
                        foreach (var obj in bundle.assetBundleObjects)
                        {
                            msg += string.Format("\t{0}\n", obj);
                        }
                    }
                    if (bundle.assetBundleDependencies != null)
                    {
                        foreach (var dependency in bundle.assetBundleDependencies)
                        {
                            msg += string.Format("\t{0}\n", dependency);
                        }
                    }
                }
            }

            UnityEngine.Debug.Log(msg);
        }
Example #5
0
        public static void CalculateAssetBundleBuildDependencies(ref BuildCommandSet commandSet)
        {
            // Dictionary for quick included asset lookup
            var assetToBundleMap = new Dictionary <GUID, string>();

            for (var i = 0; i < commandSet.commands.Length; ++i)
            {
                var bundle = commandSet.commands[i];
                foreach (var asset in bundle.explicitAssets)
                {
                    assetToBundleMap.Add(asset.asset, commandSet.commands[i].assetBundleName);
                }
            }

            // Calculate dependencies for each bundle
            for (var i = 0; i < commandSet.commands.Length; ++i)
            {
                CalculateAssetBundleDependencies(ref commandSet.commands[i], assetToBundleMap);
            }
        }
 private static extern void WriteResourceFilesForBundle_Injected(BuildCommandSet commands, string bundleName, ref BuildSettings settings, BuildUsageTagSet usageSet, string outputFolder, out BuildOutput ret);
 extern public static BuildOutput WriteAllResourceFiles(BuildCommandSet commands, BuildSettings settings, BuildUsageTagSet usageSet, string outputFolder);
 extern public static BuildOutput WriteResourceFilesForBundles(BuildCommandSet commands, string[] bundleNames, BuildSettings settings, BuildUsageTagSet usageSet, string outputFolder);
Example #9
0
 private static extern void WriteResourceFiles_Injected(ref BuildCommandSet commands, ref BuildSettings settings, out BuildOutput ret);