public static AssetBundleBuildMap GetBuildMap() { if (s_map == null) { if (!Load()) { // Create vanilla db s_map = ScriptableObject.CreateInstance <AssetBundleBuildMap>(); s_map.m_assetBundles = new List <AssetBundleEntry>(); #if UNITY_EDITOR s_map.m_version = VERSION; var DBDir = AssetGraphBasePath.TemporalSettingFilePath; if (!Directory.Exists(DBDir)) { Directory.CreateDirectory(DBDir); } AssetDatabase.CreateAsset(s_map, Config.BuildMapPath); #endif } } return(s_map); }
private static bool Load() { bool loaded = false; #if UNITY_EDITOR try { var dbPath = Config.BuildMapPath; if (File.Exists(dbPath)) { AssetBundleBuildMap m = AssetDatabase.LoadAssetAtPath <AssetBundleBuildMap>(dbPath); if (m != null && m.m_version == VERSION) { s_map = m; loaded = true; } } } catch (Exception e) { Debug.LogException(e); } #endif return(loaded); }
public static AssetBundleBuildMap GetBuildMap() { if (s_map == null) { if (!Load()) { // Create vanilla db s_map = ScriptableObject.CreateInstance <AssetBundleBuildMap>(); s_map.m_assetBundles = new List <AssetBundleEntry>(); s_map.m_version = VERSION; var filePath = UserSettings.AssetBundleBuildMapPath; var dirPath = Path.GetDirectoryName(filePath); if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } AssetDatabase.CreateAsset(s_map, filePath); } } return(s_map); }
private static bool Load() { bool loaded = false; try { var filePath = UserSettings.AssetBundleBuildMapPath; if (File.Exists(filePath)) { AssetBundleBuildMap m = AssetDatabase.LoadAssetAtPath <AssetBundleBuildMap>(filePath); if (m != null && m.m_version == VERSION) { s_map = m; loaded = true; } } } catch (Exception e) { Debug.LogException(e); } return(loaded); }
public void AddAssets(string id, IEnumerable <string> assets) { foreach (var a in assets) { m_assets.Add(new AssetPathString(a)); } AssetBundleBuildMap.SetMapDirty(); }
public AssetBundleEntry(string registererId, string assetBundleName, string variantName) { m_registererId = registererId; m_assetBundleName = assetBundleName.ToLower(); m_assetBundleVariantName = variantName.ToLower(); m_fullName = AssetBundleBuildMap.MakeFullName(assetBundleName, variantName); m_assets = new List <AssetPathString>(); }
public AssetBundleEntry GetAssetBundle(string registererId, string assetBundleFullName) { var entry = m_assetBundles.Find(v => v.m_fullName == assetBundleFullName); if (entry == null) { string[] names = AssetBundleBuildMap.FullNameToNameAndVariant(assetBundleFullName); entry = new AssetBundleEntry(registererId, names[0], names[1]); m_assetBundles.Add(entry); SetMapDirty(); } return(entry); }
private void UpdateBuildMap() { UpdateGraphInfo(); string path = AssetDatabase.GUIDToAssetPath(m_graphGuid); if (string.IsNullOrEmpty(path)) { return; } AssetBundleBuildMap.GetBuildMap().Clear(); AssetGraphUtility.ExecuteGraphSetup(path); }
/// <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, Action <Model.NodeData, string, float> updateHandler = null) { 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, false, updateHandler); 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); }
public bool BuildAssetBundles(AssetBundleBrowser.AssetBundleDataSource.ABBuildInfo info) { AssetBundleBuildMap.GetBuildMap().Clear(); UpdateGraphInfo(); if (string.IsNullOrEmpty(m_graphGuid)) { return(false); } string path = AssetDatabase.GUIDToAssetPath(m_graphGuid); if (string.IsNullOrEmpty(path)) { return(false); } var graph = AssetDatabase.LoadAssetAtPath <Model.ConfigGraph>(path); Type infoType = info.GetType(); var fieldInfo = infoType.GetField("buildTarget"); if (fieldInfo != null) { BuildTarget target = (BuildTarget)fieldInfo.GetValue(info); var result = AssetGraphUtility.ExecuteGraph(target, graph); if (result.IsAnyIssueFound) { return(false); } } return(true); }
public string[] GetAssetPathsFromAssetBundle(string assetBundleName) { return(AssetBundleBuildMap.GetBuildMap().GetAssetPathsFromAssetBundle(assetBundleName)); }
/** * 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("Bundle Name Template is empty.", "Set valid bundle name template.", node); } if (m_groupExtractedAssets[target] != 0) { if (m_groupSizeByte[target] < 0) { throw new NodeException("Invalid size. Size property must be a positive number.", "Set valid size.", node); } } // Pass incoming assets straight to Output if (Output != null) { var destination = (connectionsToOutput == null || !connectionsToOutput.Any()) ? null : connectionsToOutput.First(); if (incoming == null) { // Overwrite output with empty Dictionary when no there is incoming asset Output(destination, new Dictionary <string, System.Collections.Generic.List <AssetReference> >()); return; } var buildMap = AssetBundleBuildMap.GetBuildMap(); buildMap.ClearFromId(node.Id); var dependencyCollector = new Dictionary <string, System.Collections.Generic.List <string> >(); // [asset path:group name] var sharedDependency = new Dictionary <string, System.Collections.Generic.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 System.Collections.Generic.List <AssetReference>(); } sharedDependency[groupName].Add(AssetReference.CreateReference(entry.Key)); } } if (sharedDependency.Keys.Count == 0) { foreach (var ag in incoming) { Output(destination, ag.assetGroups); } } // subgroup shared dependency bundles by size if (m_groupExtractedAssets[target] != 0) { System.Collections.Generic.List <string> devidingBundleNames = new System.Collections.Generic.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 System.Collections.Generic.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)); } //remove doubles foreach (var shDep in sharedDependency) { foreach (var assetReference in shDep.Value) { foreach (var ag in incoming) { foreach (var agAssetGroup in ag.assetGroups) { List <AssetReference> toDel = new List <AssetReference>(); foreach (var incomingAssetReference in agAssetGroup.Value) { if (incomingAssetReference.path == assetReference.path && incomingAssetReference.fileNameAndExtension == assetReference.fileNameAndExtension) { toDel.Add(incomingAssetReference); Debug.LogWarning("Found duplicate " + incomingAssetReference.fileNameAndExtension); } } foreach (var reference in toDel) { agAssetGroup.Value.Remove(reference); Debug.LogWarning("Removed duplicate " + reference.fileNameAndExtension); } } } } } foreach (var ag in incoming) { Output(destination, new Dictionary <string, System.Collections.Generic.List <AssetReference> >(ag.assetGroups)); } Output(destination, sharedDependency); } }
public void Clear() { m_assets.Clear(); AssetBundleBuildMap.SetMapDirty(); }
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("Bundle Name Template is empty.", "Set valid bundle name template from inspector.", node); }, () => { throw new NodeException("Bundle Name Template can not contain '" + Model.Settings.KEYWORD_WILDCARD.ToString() + "' when group name is used for variants.", "Set valid bundle name without '" + Model.Settings.KEYWORD_WILDCARD.ToString() + "' from inspector.", node); }, () => { throw new NodeException("Bundle Name Template must contain '" + Model.Settings.KEYWORD_WILDCARD.ToString() + "' when group name is not used for variants and expecting multiple incoming groups.", "Set valid bundle name without '" + Model.Settings.KEYWORD_WILDCARD.ToString() + "' from inspector.", node); } ); var variantNames = m_variants.Select(v => v.Name).ToList(); foreach (var variant in m_variants) { ValidateVariantName(variant.Name, variantNames, () => { throw new NodeException("Variant name is empty.", "Set valid variant name from inspector.", node); }, () => { throw new NodeException("Variant name cannot contain whitespace \"" + variant.Name + "\".", "Remove whitespace from variant name.", node); }, () => { throw new NodeException("Variant name already exists \"" + variant.Name + "\".", "Avoid variant name collision.", node); }); } 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( "Invalid files are found. Following files need to be imported to put into asset bundle: " + string.Join(", ", invalids.Select(a => a.absolutePath).ToArray()), "Import these files before building asset bundles.", node); } } 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); } }
public string GetImplicitAssetBundleName(string assetPath) { return(AssetBundleBuildMap.GetBuildMap().GetImplicitAssetBundleName(assetPath)); }
public string[] GetAllAssetBundleNames() { UpdateBuildMap(); return(AssetBundleBuildMap.GetBuildMap().GetAllAssetBundleNames()); }
public AssetBundleEntry GetAssetBundleWithNameAndVariant(string registererId, string assetBundleName, string variantName) { return(GetAssetBundle(registererId, AssetBundleBuildMap.MakeFullName(assetBundleName, variantName))); }