Example #1
0
        internal static bool IsCacheDataValid(AddressableAssetSettings settings, AddressablesContentState cacheData)
        {
            if (cacheData == null)
            {
                return(false);
            }

            if (cacheData.editorVersion != Application.unityVersion)
            {
                Addressables.LogWarningFormat("Building content update with Unity editor version `{0}`, data was created with version `{1}`.  This may result in incompatible data.", Application.unityVersion, cacheData.editorVersion);
            }

            if (string.IsNullOrEmpty(cacheData.remoteCatalogLoadPath))
            {
                Addressables.LogError("Previous build had 'Build Remote Catalog' disabled.  You cannot update a player that has no remote catalog specified");
                return(false);
            }
            if (!settings.BuildRemoteCatalog)
            {
                Addressables.LogError("Current settings have 'Build Remote Catalog' disabled.  You cannot update a player that has no remote catalog to look to.");
                return(false);
            }

            if (cacheData.remoteCatalogLoadPath != settings.RemoteCatalogLoadPath.GetValue(settings))
            {
                Addressables.LogErrorFormat("Current 'Remote Catalog Load Path' does not match load path of original player.  Player will only know to look up catalog at original location. Original: {0}  Current: {1}", cacheData.remoteCatalogLoadPath, settings.RemoteCatalogLoadPath.GetValue(settings));
                return(false);
            }

            return(true);
        }
        protected override void Execute()
        {
            var rtd = m_RtdOp.Result;

            List <AsyncOperationHandle> initOperations = new List <AsyncOperationHandle>();

            foreach (var i in rtd.InitializationObjects)
            {
                if (i.ObjectType.Value == null)
                {
                    Addressables.LogFormat("Invalid initialization object type {0}.", i.ObjectType);
                    continue;
                }

                try
                {
                    var o = i.GetAsyncInitHandle(m_Addressables.ResourceManager);
                    initOperations.Add(o);
                    Addressables.LogFormat("Initialization object {0} created instance {1}.", i, o);
                }
                catch (Exception ex)
                {
                    Addressables.LogErrorFormat("Exception thrown during initialization of object {0}: {1}", i,
                                                ex.ToString());
                }
            }

            m_DepOp            = m_Addressables.ResourceManager.CreateGenericGroupOperation(initOperations, true);
            m_DepOp.Completed += (obj) =>
            {
                bool success = obj.Status == AsyncOperationStatus.Succeeded;
                Complete(true, success, success ? "" : $"{obj.DebugName} failed initialization.");
                m_Addressables.Release(m_DepOp);
            };
        }
Example #3
0
        protected override void Execute()
        {
            Addressables.LogFormat("Addressables - runtime data operation completed with status = {0}, result = {1}.", m_rtdOp.Status, m_rtdOp.Result);
            if (m_rtdOp.Result == null)
            {
                Addressables.LogWarningFormat("Addressables - Unable to load runtime data at location {0}.", m_rtdOp);
                Complete(Result, false, string.Format("Addressables - Unable to load runtime data at location {0}.", m_rtdOp));
                return;
            }
            var rtd = m_rtdOp.Result;

            m_Addressables.Release(m_rtdOp);
            if (rtd.CertificateHandlerType != null)
            {
                m_Addressables.ResourceManager.CertificateHandlerInstance = Activator.CreateInstance(rtd.CertificateHandlerType) as CertificateHandler;
            }

#if UNITY_EDITOR
            if (UnityEditor.EditorUserBuildSettings.activeBuildTarget.ToString() != rtd.BuildTarget)
            {
                Addressables.LogErrorFormat("Addressables - runtime data was built with a different build target.  Expected {0}, but data was built with {1}.  Certain assets may not load correctly including shaders.  You can rebuild player content via the Addressables window.", UnityEditor.EditorUserBuildSettings.activeBuildTarget, rtd.BuildTarget);
            }
#endif
            if (!rtd.LogResourceManagerExceptions)
            {
                ResourceManager.ExceptionHandler = null;
            }

            if (!rtd.ProfileEvents)
            {
                m_Diagnostics.Dispose();
                m_Diagnostics = null;
            }

            //   DiagnosticEventCollector.ResourceManagerProfilerEventsEnabled = rtd.ProfileEvents;
            Addressables.Log("Addressables - loading initialization objects.");

            ContentCatalogProvider ccp = m_Addressables.ResourceManager.ResourceProviders
                                         .FirstOrDefault(rp => rp.GetType() == typeof(ContentCatalogProvider)) as ContentCatalogProvider;
            if (ccp != null)
            {
                ccp.DisableCatalogUpdateOnStart = rtd.DisableCatalogUpdateOnStartup;
            }

            var locMap = new ResourceLocationMap("CatalogLocator", rtd.CatalogLocations);
            m_Addressables.AddResourceLocator(locMap);
            IList <IResourceLocation> catalogs;
            if (!locMap.Locate(ResourceManagerRuntimeData.kCatalogAddress, typeof(ContentCatalogData), out catalogs))
            {
                Addressables.LogWarningFormat(
                    "Addressables - Unable to find any catalog locations in the runtime data.");
                m_Addressables.RemoveResourceLocator(locMap);
                Complete(Result, false, "Addressables - Unable to find any catalog locations in the runtime data.");
            }
            else
            {
                Addressables.LogFormat("Addressables - loading content catalogs, {0} found.", catalogs.Count);
                LoadContentCatalogInternal(catalogs, 0, locMap);
            }
        }
 /// <summary>
 /// Adds a variable in the group
 /// </summary>
 /// <param name="variable"></param>
 /// <returns>True if the variable was added, false if the variable already exists</returns>
 internal bool AddVariable(GroupTypeVariable variable)
 {
     GroupTypeVariable exists = m_Variables.Where(ps => ps.Suffix == variable.Suffix).FirstOrDefault();
     if (exists != null)
     {
         Addressables.LogErrorFormat("{0} already exists.", GetName(variable));
         return false;
     }
     m_Variables.Add(variable);
     return true;
 }
Example #5
0
        /// <summary>
        /// Construct a new ResourceLocationMap object with a list of locations.
        /// </summary>
        /// <param name="id">The locator id.</param>
        /// <param name="locations">The list of locations to initialize with.</param>
        public ResourceLocationMap(string id, IList <ResourceLocationData> locations)
        {
            LocatorId = id;
            if (locations == null)
            {
                return;
            }
            Locations = new Dictionary <object, IList <IResourceLocation> >(locations.Count * 2);
            var locMap  = new Dictionary <string, ResourceLocationBase>();
            var dataMap = new Dictionary <string, ResourceLocationData>();

            //create and collect locations
            for (int i = 0; i < locations.Count; i++)
            {
                var rlData = locations[i];
                if (rlData.Keys == null || rlData.Keys.Length < 1)
                {
                    Addressables.LogErrorFormat("Address with id '{0}' does not have any valid keys, skipping...", rlData.InternalId);
                    continue;
                }
                if (locMap.ContainsKey(rlData.Keys[0]))
                {
                    Addressables.LogErrorFormat("Duplicate address '{0}' with id '{1}' found, skipping...", rlData.Keys[0], rlData.InternalId);
                    continue;
                }
                var loc = new ResourceLocationBase(rlData.Keys[0], Addressables.ResolveInternalId(rlData.InternalId), rlData.Provider, rlData.ResourceType);
                loc.Data = rlData.Data;
                locMap.Add(rlData.Keys[0], loc);
                dataMap.Add(rlData.Keys[0], rlData);
            }

            //fix up dependencies between them
            foreach (var kvp in locMap)
            {
                var data = dataMap[kvp.Key];
                if (data.Dependencies != null)
                {
                    foreach (var d in data.Dependencies)
                    {
                        kvp.Value.Dependencies.Add(locMap[d]);
                    }
                    kvp.Value.ComputeDependencyHash();
                }
            }
            foreach (KeyValuePair <string, ResourceLocationBase> kvp in locMap)
            {
                ResourceLocationData rlData = dataMap[kvp.Key];
                foreach (var k in rlData.Keys)
                {
                    Add(k, kvp.Value);
                }
            }
        }
 /// <summary>
 /// Removes a variable from the group
 /// </summary>
 /// <param name="variable"></param>
 internal void RemoveVariable(GroupTypeVariable variable)
 {
     GroupTypeVariable exists = m_Variables.Where(ps => ps.Suffix == variable.Suffix).FirstOrDefault();
     if (exists == null)
     {
         Addressables.LogErrorFormat("{0} does not exist.", GetName(variable));
         return;
     }
     else
     {
         m_Variables.Remove(variable);
     }
 }
        protected override void Execute()
        {
            var rtd = m_RtdOp.Result;

            if (rtd == null)
            {
                Addressables.LogError("RuntimeData is null.  Please ensure you have built the correct Player Content.");
                Complete(true, true, "");
                return;
            }

            string buildLogsPath = m_Addressables.ResolveInternalId(PlayerPrefs.GetString(Addressables.kAddressablesRuntimeBuildLogPath));

            if (LogRuntimeWarnings(buildLogsPath))
            {
                File.Delete(buildLogsPath);
            }

            List <AsyncOperationHandle> initOperations = new List <AsyncOperationHandle>();

            foreach (var i in rtd.InitializationObjects)
            {
                if (i.ObjectType.Value == null)
                {
                    Addressables.LogFormat("Invalid initialization object type {0}.", i.ObjectType);
                    continue;
                }

                try
                {
                    var o = i.GetAsyncInitHandle(m_Addressables.ResourceManager);
                    initOperations.Add(o);
                    Addressables.LogFormat("Initialization object {0} created instance {1}.", i, o);
                }
                catch (Exception ex)
                {
                    Addressables.LogErrorFormat("Exception thrown during initialization of object {0}: {1}", i,
                                                ex.ToString());
                }
            }

            m_DepOp            = m_Addressables.ResourceManager.CreateGenericGroupOperation(initOperations, true);
            m_DepOp.Completed += (obj) =>
            {
                bool success = obj.Status == AsyncOperationStatus.Succeeded;
                Complete(true, success, success ? "" : $"{obj.DebugName}, status={obj.Status}, result={obj.Result} failed initialization.");
                m_Addressables.Release(m_DepOp);
            };
        }
        protected override void Execute()
        {
            Addressables.LogFormat("Addressables - runtime data operation completed with status = {0}, result = {1}.", m_rtdOp.Status, m_rtdOp.Result);
            if (m_rtdOp.Result == null)
            {
                Addressables.LogWarningFormat("Addressables - Unable to load runtime data at location {0}.", m_rtdOp);
                Complete(m_Result, false, string.Format("Addressables - Unable to load runtime data at location {0}.", m_rtdOp));
                return;
            }
            var rtd = m_rtdOp.Result;

            m_Addressables.Release(m_rtdOp);
            if (rtd.CertificateHandlerType != null)
            {
                m_Addressables.ResourceManager.CertificateHandlerInstance = Activator.CreateInstance(rtd.CertificateHandlerType) as CertificateHandler;
            }

#if UNITY_EDITOR
            if (UnityEditor.EditorUserBuildSettings.activeBuildTarget.ToString() != rtd.BuildTarget)
            {
                Addressables.LogErrorFormat("Addressables - runtime data was built with a different build target.  Expected {0}, but data was built with {1}.  Certain assets may not load correctly including shaders.  You can rebuild player content via the Addressable Assets window.", UnityEditor.EditorUserBuildSettings.activeBuildTarget, rtd.BuildTarget);
            }
#endif
            if (!rtd.LogResourceManagerExceptions)
            {
                ResourceManager.ExceptionHandler = null;
            }

            if (!rtd.ProfileEvents)
            {
                m_Diagnostics.Dispose();
                m_Diagnostics = null;
            }

            //   DiagnosticEventCollector.ResourceManagerProfilerEventsEnabled = rtd.ProfileEvents;
            Addressables.Log("Addressables - loading initialization objects.");
            foreach (var i in rtd.InitializationObjects)
            {
                if (i.ObjectType.Value == null)
                {
                    Addressables.LogFormat("Invalid initialization object type {0}.", i.ObjectType);
                    continue;
                }
                try
                {
                    var o = i.CreateInstance <object>();
                    Addressables.LogFormat("Initialization object {0} created instance {1}.", i, o);
                }
                catch (Exception ex)
                {
                    Addressables.LogErrorFormat("Exception thrown during initialization of object {0}: {1}", i, ex.ToString());
                }
            }

            var locMap = new ResourceLocationMap(rtd.CatalogLocations);
            m_Addressables.ResourceLocators.Add(locMap);
            IList <IResourceLocation> catalogs;
            if (!locMap.Locate(ResourceManagerRuntimeData.kCatalogAddress, typeof(ContentCatalogData), out catalogs))
            {
                Addressables.LogWarningFormat("Addressables - Unable to find any catalog locations in the runtime data.");
                m_Addressables.ResourceLocators.Remove(locMap);
                Complete(m_Result, false, "Addressables - Unable to find any catalog locations in the runtime data.");
            }
            else
            {
                Addressables.LogFormat("Addressables - loading content catalogs, {0} found.", catalogs.Count);
                LoadContentCatalogInternal(catalogs, 0, locMap);
            }
        }
        protected override void Execute()
        {
            Addressables.LogFormat("Addressables - runtime data operation completed with status = {0}, result = {1}.", m_rtdOp.Status, m_rtdOp.Result);
            if (m_rtdOp.Result == null)
            {
                Addressables.LogWarningFormat("Addressables - Unable to load runtime data at location {0}.", m_rtdOp);
                Complete(Result, false, string.Format("Addressables - Unable to load runtime data at location {0}.", m_rtdOp));
                return;
            }
            Addressables.LogFormat("Initializing Addressables version {0}.", m_rtdOp.Result.AddressablesVersion);
            var rtd = m_rtdOp.Result;

            m_Addressables.ResourceManager.postProfilerEvents = rtd.ProfileEvents;
            WebRequestQueue.SetMaxConcurrentRequests(rtd.MaxConcurrentWebRequests);
            m_Addressables.CatalogRequestsTimeout = rtd.CatalogRequestsTimeout;
            foreach (var catalogLocation in rtd.CatalogLocations)
            {
                if (catalogLocation.Data != null && catalogLocation.Data is ProviderLoadRequestOptions loadData)
                {
                    loadData.WebRequestTimeout = rtd.CatalogRequestsTimeout;
                }
            }

            m_Addressables.Release(m_rtdOp);
            if (rtd.CertificateHandlerType != null)
            {
                m_Addressables.ResourceManager.CertificateHandlerInstance = Activator.CreateInstance(rtd.CertificateHandlerType) as CertificateHandler;
            }

#if UNITY_EDITOR
            if (UnityEditor.EditorUserBuildSettings.activeBuildTarget.ToString() != rtd.BuildTarget)
            {
                Addressables.LogErrorFormat("Addressables - runtime data was built with a different build target.  Expected {0}, but data was built with {1}.  Certain assets may not load correctly including shaders.  You can rebuild player content via the Addressables window.", UnityEditor.EditorUserBuildSettings.activeBuildTarget, rtd.BuildTarget);
            }
#endif
            if (!rtd.LogResourceManagerExceptions)
            {
                ResourceManager.ExceptionHandler = null;
            }

            if (!rtd.ProfileEvents)
            {
                m_Diagnostics.Dispose();
                m_Diagnostics = null;
                m_Addressables.ResourceManager.ClearDiagnosticCallbacks();
            }

            Addressables.Log("Addressables - loading initialization objects.");

            ContentCatalogProvider ccp = m_Addressables.ResourceManager.ResourceProviders
                                         .FirstOrDefault(rp => rp.GetType() == typeof(ContentCatalogProvider)) as ContentCatalogProvider;
            if (ccp != null)
            {
                ccp.DisableCatalogUpdateOnStart = rtd.DisableCatalogUpdateOnStartup;
                ccp.IsLocalCatalogInBundle      = rtd.IsLocalCatalogInBundle;
            }

            var locMap = new ResourceLocationMap("CatalogLocator", rtd.CatalogLocations);
            m_Addressables.AddResourceLocator(locMap);
            IList <IResourceLocation> catalogs;
            if (!locMap.Locate(ResourceManagerRuntimeData.kCatalogAddress, typeof(ContentCatalogData), out catalogs))
            {
                Addressables.LogWarningFormat(
                    "Addressables - Unable to find any catalog locations in the runtime data.");
                m_Addressables.RemoveResourceLocator(locMap);
                Complete(Result, false, "Addressables - Unable to find any catalog locations in the runtime data.");
            }
            else
            {
                Addressables.LogFormat("Addressables - loading content catalogs, {0} found.", catalogs.Count);
                IResourceLocation remoteHashLocation = null;
                if (catalogs[0].Dependencies.Count == 2 && rtd.DisableCatalogUpdateOnStartup)
                {
                    remoteHashLocation = catalogs[0].Dependencies[(int)ContentCatalogProvider.DependencyHashIndex.Remote];
                    catalogs[0].Dependencies[(int)ContentCatalogProvider.DependencyHashIndex.Remote] = catalogs[0].Dependencies[(int)ContentCatalogProvider.DependencyHashIndex.Cache];
                }
                m_loadCatalogOp = LoadContentCatalogInternal(catalogs, 0, locMap, remoteHashLocation);
            }
        }