using System; using System.Collections.Generic; using UnityEditor.AddressableAssets.Settings; using UnityEditor.Build.Pipeline.Interfaces; using UnityEngine; using UnityEngine.AddressableAssets.Initialization; using UnityEngine.AddressableAssets.ResourceLocators; namespace UnityEditor.AddressableAssets.Build.DataBuilders { /// /// Interface for any Addressables specific context objects to be used in the Scriptable Build Pipeline context store /// public interface IAddressableAssetsBuildContext : IContextObject { } /// /// Simple context object for passing data through SBP, between different sections of Addressables code. /// public class AddressableAssetsBuildContext : IAddressableAssetsBuildContext { private AddressableAssetSettings m_Settings; /// /// The settings object to use. /// [Obsolete("Use Settings property instead.")] public AddressableAssetSettings settings; /// /// The settings object to use. /// public AddressableAssetSettings Settings { get { if (m_Settings == null && !string.IsNullOrEmpty(m_SettingsAssetPath)) m_Settings = AssetDatabase.LoadAssetAtPath(m_SettingsAssetPath); return m_Settings; } set { m_Settings = value; string guid; if (m_Settings != null && AssetDatabase.TryGetGUIDAndLocalFileIdentifier(m_Settings, out guid, out long localId)) m_SettingsAssetPath = AssetDatabase.GUIDToAssetPath(guid); else m_SettingsAssetPath = null; } } private string m_SettingsAssetPath; /// /// The time the build started /// public DateTime buildStartTime; /// /// The current runtime data being built. /// public ResourceManagerRuntimeData runtimeData; /// /// The list of catalog locations. /// public List locations; /// /// Mapping of bundles to asset groups. /// public Dictionary bundleToAssetGroup; /// /// Mapping of asset group to bundles. /// public Dictionary> assetGroupToBundles; /// /// Set of provider types needed in this build. /// public HashSet providerTypes; /// /// The list of all AddressableAssetEntry objects. /// public List assetEntries; /// /// Mapping of AssetBundle to the direct dependencies. /// public Dictionary> bundleToImmediateBundleDependencies; /// /// A mapping of AssetBundle to the full dependency tree, flattened into a single list. /// public Dictionary> bundleToExpandedBundleDependencies; /// /// A mapping of Asset GUID's to resulting ContentCatalogDataEntry entries. /// internal Dictionary> GuidToCatalogLocation = null; private Dictionary> m_PrimaryKeyToDependers = null; internal Dictionary> PrimaryKeyToDependerLocations { get { if (m_PrimaryKeyToDependers != null) return m_PrimaryKeyToDependers; if (locations == null || locations.Count == 0) { Debug.LogError("Attempting to get Entries dependent on key, but currently no locations"); return new Dictionary>(0); } m_PrimaryKeyToDependers = new Dictionary>(locations.Count); foreach (ContentCatalogDataEntry location in locations) { for (int i = 0; i < location.Dependencies.Count; ++i) { string dependencyKey = location.Dependencies[i] as string; if (string.IsNullOrEmpty(dependencyKey)) continue; if (!m_PrimaryKeyToDependers.TryGetValue(dependencyKey, out var dependers)) { dependers = new List(); m_PrimaryKeyToDependers.Add(dependencyKey, dependers); } dependers.Add(location); } } return m_PrimaryKeyToDependers; } } private Dictionary m_PrimaryKeyToLocation = null; internal Dictionary PrimaryKeyToLocation { get { if (m_PrimaryKeyToLocation != null) return m_PrimaryKeyToLocation; if (locations == null || locations.Count == 0) { Debug.LogError("Attempting to get Primary key to entries dependent on key, but currently no locations"); return new Dictionary(); } m_PrimaryKeyToLocation = new Dictionary(); foreach (var loc in locations) { if (loc != null && loc.Keys[0] != null && loc.Keys[0] is string && !m_PrimaryKeyToLocation.ContainsKey((string)loc.Keys[0])) m_PrimaryKeyToLocation[(string)loc.Keys[0]] = loc; } return m_PrimaryKeyToLocation; } } } }