Ejemplo n.º 1
0
        public bool BuildAssetBundles(AssetBundleDataSource.ABBuildInfo info)
        {
            AssetBundleBuildMap.GetBuildMap().Clear();

            var guids = AssetDatabase.FindAssets(Model.Settings.GRAPH_SEARCH_CONDITION);

            foreach (var guid in guids)
            {
                string path  = AssetDatabase.GUIDToAssetPath(guid);
                var    graph = AssetDatabase.LoadAssetAtPath <Model.ConfigGraph>(path);
                if (!graph.UseAsAssetPostprocessor)
                {
                    Type infoType   = info.GetType();
                    var  targetInfo = infoType.GetProperty("buildTarget");
                    if (targetInfo.GetValue(info, null) is BuildTarget)
                    {
                        BuildTarget target = (BuildTarget)targetInfo.GetValue(info, null);
                        var         result = AssetBundleGraphUtility.ExecuteGraph(target, graph);
                        if (result.IsAnyIssueFound)
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Executes the graph collection.
        /// </summary>
        /// <returns>The graph collection.</returns>
        /// <param name="t">T.</param>
        /// <param name="c">C.</param>
        public static List<ExecuteGraphResult> ExecuteGraphCollection(BuildTarget t, BatchBuildConfig.GraphCollection c)
        {
            AssetBundleBuildMap.GetBuildMap ().Clear ();

            List<ExecuteGraphResult> resultCollection = new List<ExecuteGraphResult>(c.GraphGUIDs.Count);

            foreach(var guid in c.GraphGUIDs) {
                string path = AssetDatabase.GUIDToAssetPath(guid);
                if(path != null) {
                    var r = ExecuteGraph(t, path);
                    resultCollection.Add(r);
                } else {
                    LogUtility.Logger.LogFormat(LogType.Warning, "Failed to build graph in collection {0}: graph with guid {1} not found.",
                        c.Name, guid);
                }
            }

            return  resultCollection;
        }
Ejemplo n.º 3
0
        /**
         * Prepare is called whenever graph needs update.
         */
        public override void Prepare(BuildTarget target,
                                     Model.NodeData node,
                                     IEnumerable <PerformGraph.AssetGroups> incoming,
                                     IEnumerable <Model.ConnectionData> connectionsToOutput,
                                     PerformGraph.Output Output)
        {
            if (string.IsNullOrEmpty(m_bundleNameTemplate))
            {
                throw new NodeException(node.Name + ":Bundle Name Template is empty.", node.Id);
            }
            if (m_groupExtractedAssets [target] != 0)
            {
                if (m_groupSizeByte[target] < 0)
                {
                    throw new NodeException("Invalid size. Size property must be a positive number.", node.Id);
                }
            }

            // Pass incoming assets straight to Output
            if (Output != null)
            {
                var destination = (connectionsToOutput == null || !connectionsToOutput.Any())?
                                  null : connectionsToOutput.First();

                if (incoming != null)
                {
                    var buildMap = AssetBundleBuildMap.GetBuildMap();
                    buildMap.ClearFromId(node.Id);

                    var dependencyCollector = new Dictionary <string, List <string> >(); // [asset path:group name]
                    var sharedDependency    = new Dictionary <string, List <AssetReference> >();
                    var groupNameMap        = new Dictionary <string, string>();

                    // build dependency map
                    foreach (var ag in incoming)
                    {
                        foreach (var key in ag.assetGroups.Keys)
                        {
                            var assets = ag.assetGroups[key];

                            foreach (var a in assets)
                            {
                                CollectDependencies(key, new string[] { a.importFrom }, ref dependencyCollector);
                            }
                        }
                    }

                    foreach (var entry in dependencyCollector)
                    {
                        if (entry.Value != null && entry.Value.Count > 1)
                        {
                            var joinedName = string.Join("-", entry.Value.ToArray());
                            if (!groupNameMap.ContainsKey(joinedName))
                            {
                                var count   = groupNameMap.Count;
                                var newName = m_bundleNameTemplate.Replace("*", count.ToString());
                                if (newName == m_bundleNameTemplate)
                                {
                                    newName = m_bundleNameTemplate + count.ToString();
                                }
                                groupNameMap.Add(joinedName, newName);
                            }
                            var groupName = groupNameMap[joinedName];

                            if (!sharedDependency.ContainsKey(groupName))
                            {
                                sharedDependency[groupName] = new List <AssetReference>();
                            }
                            sharedDependency[groupName].Add(AssetReference.CreateReference(entry.Key));
                        }
                    }

                    if (sharedDependency.Keys.Count > 0)
                    {
                        // subgroup shared dependency bundles by size
                        if (m_groupExtractedAssets [target] != 0)
                        {
                            List <string> devidingBundleNames = new List <string> (sharedDependency.Keys);
                            long          szGroup             = m_groupSizeByte[target] * 1000;

                            foreach (var bundleName in devidingBundleNames)
                            {
                                var  assets       = sharedDependency[bundleName];
                                int  groupCount   = 0;
                                long szGroupCount = 0;
                                foreach (var a in assets)
                                {
                                    var subGroupName = string.Format("{0}_{1}", bundleName, groupCount);
                                    if (!sharedDependency.ContainsKey(subGroupName))
                                    {
                                        sharedDependency[subGroupName] = new List <AssetReference>();
                                    }
                                    sharedDependency[subGroupName].Add(a);

                                    szGroupCount += GetSizeOfAsset(a, (GroupingType)m_groupingType[target]);
                                    if (szGroupCount >= szGroup)
                                    {
                                        szGroupCount = 0;
                                        ++groupCount;
                                    }
                                }
                                sharedDependency.Remove(bundleName);
                            }
                        }

                        foreach (var bundleName in sharedDependency.Keys)
                        {
                            var bundleConfig = buildMap.GetAssetBundleWithNameAndVariant(node.Id, bundleName, string.Empty);
                            bundleConfig.AddAssets(node.Id, sharedDependency[bundleName].Select(a => a.importFrom));
                        }

                        foreach (var ag in incoming)
                        {
                            Output(destination, new Dictionary <string, List <AssetReference> >(ag.assetGroups));
                        }
                        Output(destination, sharedDependency);
                    }
                    else
                    {
                        foreach (var ag in incoming)
                        {
                            Output(destination, ag.assetGroups);
                        }
                    }
                }
                else
                {
                    // Overwrite output with empty Dictionary when no there is incoming asset
                    Output(destination, new Dictionary <string, List <AssetReference> >());
                }
            }
        }
Ejemplo n.º 4
0
        public override void Prepare(BuildTarget target,
                                     Model.NodeData node,
                                     IEnumerable <PerformGraph.AssetGroups> incoming,
                                     IEnumerable <Model.ConnectionData> connectionsToOutput,
                                     PerformGraph.Output Output)
        {
            int groupCount = 0;

            if (incoming != null)
            {
                var groupNames = new List <string>();
                foreach (var ag in incoming)
                {
                    foreach (var groupKey in ag.assetGroups.Keys)
                    {
                        if (!groupNames.Contains(groupKey))
                        {
                            groupNames.Add(groupKey);
                        }
                    }
                }
                groupCount = groupNames.Count;
            }

            ValidateBundleNameTemplate(
                m_bundleNameTemplate[target],
                m_useGroupAsVariants,
                groupCount,
                () => {
                throw new NodeException(node.Name + ":Bundle Name Template is empty.", node.Id);
            },
                () => {
                throw new NodeException(node.Name + ":Bundle Name Template can not contain '" + Model.Settings.KEYWORD_WILDCARD.ToString()
                                        + "' when group name is used for variants.", node.Id);
            },
                () => {
                throw new NodeException(node.Name + ":Bundle Name Template must contain '" + Model.Settings.KEYWORD_WILDCARD.ToString()
                                        + "' when group name is not used for variants and expecting multiple incoming groups.", node.Id);
            }
                );

            var variantNames = m_variants.Select(v => v.Name).ToList();

            foreach (var variant in m_variants)
            {
                ValidateVariantName(variant.Name, variantNames,
                                    () => {
                    throw new NodeException(node.Name + ":Variant name is empty.", node.Id);
                },
                                    () => {
                    throw new NodeException(node.Name + ":Variant name cannot contain whitespace \"" + variant.Name + "\".", node.Id);
                },
                                    () => {
                    throw new NodeException(node.Name + ":Variant name already exists \"" + variant.Name + "\".", node.Id);
                });
            }


            if (incoming != null)
            {
                /**
                 * Check if incoming asset has valid import path
                 */
                var invalids = new List <AssetReference>();
                foreach (var ag in incoming)
                {
                    foreach (var groupKey in ag.assetGroups.Keys)
                    {
                        ag.assetGroups[groupKey].ForEach(a => { if (string.IsNullOrEmpty(a.importFrom))
                                                                {
                                                                    invalids.Add(a);
                                                                }
                                                         });
                    }
                }
                if (invalids.Any())
                {
                    throw new NodeException(node.Name +
                                            ": Invalid files are found. Following files need to be imported to put into asset bundle: " +
                                            string.Join(", ", invalids.Select(a => a.absolutePath).ToArray()), node.Id);
                }
            }

            Dictionary <string, List <AssetReference> > output = null;

            if (Output != null)
            {
                output = new Dictionary <string, List <AssetReference> >();
            }

            if (incoming != null)
            {
                Dictionary <string, List <string> > variantsInfo = new Dictionary <string, List <string> > ();

                var buildMap = AssetBundleBuildMap.GetBuildMap();
                buildMap.ClearFromId(node.Id);

                foreach (var ag in incoming)
                {
                    string variantName = null;
                    if (!m_useGroupAsVariants)
                    {
                        var currentVariant = m_variants.Find(v => v.ConnectionPointId == ag.connection.ToNodeConnectionPointId);
                        variantName = (currentVariant == null) ? null : currentVariant.Name;
                    }

                    // set configured assets in bundle name
                    foreach (var groupKey in ag.assetGroups.Keys)
                    {
                        if (m_useGroupAsVariants)
                        {
                            variantName = groupKey;
                        }
                        var bundleName = GetBundleName(target, node, groupKey);
                        var assets     = ag.assetGroups[groupKey];

                        ConfigureAssetBundleSettings(variantName, assets);

                        if (!string.IsNullOrEmpty(variantName))
                        {
                            if (!variantsInfo.ContainsKey(bundleName))
                            {
                                variantsInfo [bundleName] = new List <string> ();
                            }
                            variantsInfo [bundleName].Add(variantName.ToLower());
                        }

                        if (output != null)
                        {
                            if (!output.ContainsKey(bundleName))
                            {
                                output[bundleName] = new List <AssetReference>();
                            }
                            output[bundleName].AddRange(assets);
                        }

                        var bundleConfig = buildMap.GetAssetBundleWithNameAndVariant(node.Id, bundleName, variantName);
                        bundleConfig.AddAssets(node.Id, assets.Select(a => a.importFrom));
                    }
                }

                if (output != null)
                {
                    ValidateVariantsProperlyConfiguired(node, output, variantsInfo);
                }
            }

            if (Output != null)
            {
                var dst = (connectionsToOutput == null || !connectionsToOutput.Any())?
                          null : connectionsToOutput.First();
                Output(dst, output);
            }
        }
Ejemplo n.º 5
0
 public string[] GetAllAssetBundleNames()
 {
     return(AssetBundleBuildMap.GetBuildMap().GetAllAssetBundleNames());
 }
Ejemplo n.º 6
0
 public string GetImplicitAssetBundleName(string assetPath)
 {
     return(AssetBundleBuildMap.GetBuildMap().GetImplicitAssetBundleName(assetPath));
 }
Ejemplo n.º 7
0
 public string[] GetAssetPathsFromAssetBundle(string assetBundleName)
 {
     return(AssetBundleBuildMap.GetBuildMap().GetAssetPathsFromAssetBundle(assetBundleName));
 }