//Attempts to load each catalog in order, stopping at first success.
 void LoadContentCatalogInternal(IList <IResourceLocation> catalogs, int index, ResourceLocationMap locMap)
 {
     Addressables.LogFormat("Addressables - loading content catalog from {0}.", catalogs[index].InternalId);
     LoadContentCatalog(catalogs[index], m_ProviderSuffix).Completed += op =>
     {
         if (op.Result != null)
         {
             m_Addressables.RemoveResourceLocator(locMap);
             Result = op.Result;
             Complete(Result, true, string.Empty);
             m_Addressables.Release(op);
             Addressables.Log("Addressables - initialization complete.");
         }
         else
         {
             Addressables.LogFormat("Addressables - failed to load content catalog from {0}.", op);
             if (index + 1 >= catalogs.Count)
             {
                 Addressables.LogWarningFormat("Addressables - initialization failed.", op);
                 m_Addressables.RemoveResourceLocator(locMap);
                 Complete(Result, false, op.OperationException != null ? op.OperationException.Message : "LoadContentCatalogInternal");
                 m_Addressables.Release(op);
             }
             else
             {
                 LoadContentCatalogInternal(catalogs, index + 1, locMap);
                 m_Addressables.Release(op);
             }
         }
     };
 }
Example #2
0
 void LoadOpComplete(AsyncOperationHandle <IResourceLocator> op, IList <IResourceLocation> catalogs, ResourceLocationMap locMap, int index)
 {
     if (op.Result != null)
     {
         m_Addressables.RemoveResourceLocator(locMap);
         Result = op.Result;
         Complete(Result, true, string.Empty);
         m_Addressables.Release(op);
         Addressables.Log("Addressables - initialization complete.");
     }
     else
     {
         Addressables.LogFormat("Addressables - failed to load content catalog from {0}.", op);
         if (index + 1 >= catalogs.Count)
         {
             Addressables.LogWarningFormat("Addressables - initialization failed.", op);
             m_Addressables.RemoveResourceLocator(locMap);
             Complete(Result, false, op.OperationException != null ? op.OperationException.Message : "LoadContentCatalogInternal");
             m_Addressables.Release(op);
         }
         else
         {
             m_loadCatalogOp = LoadContentCatalogInternal(catalogs, index + 1, locMap);
             m_Addressables.Release(op);
         }
     }
 }
Example #3
0
 object CreateObject(Entry e)
 {
     try
     {
         var assembly = Assembly.Load(e.AssemblyName);
         var objType  = assembly.GetType(e.ClassName);
         if (objType == typeof(string))
         {
             return(e.Data);
         }
         if (objType.IsEnum)
         {
             return(Enum.Parse(objType, e.Data));
         }
         var parseMethod = objType.GetMethod("Parse", BindingFlags.Static | BindingFlags.Public, null, CallingConventions.Any, new[] { typeof(string) }, null);
         if (parseMethod == null || parseMethod.ReturnType != objType)
         {
             return(JsonUtility.FromJson(e.Data, objType));
         }
         return(parseMethod.Invoke(null, new object[] { e.Data }));
     }
     catch (Exception ex)
     {
         Addressables.LogWarningFormat("KeyDataStore unable to deserizalize entry {0} from assembly {1} of type {2}, exception: {3}", e.Key, e.AssemblyName, e.ClassName, ex);
         return(null);
     }
 }
Example #4
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);
        }
Example #5
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);
            }
        }
        //Attempts to load each catalog in order, stopping at first success.
        internal AsyncOperationHandle <IResourceLocator> LoadContentCatalogInternal(IList <IResourceLocation> catalogs, int index, ResourceLocationMap locMap, IResourceLocation remoteHashLocation)
        {
            Addressables.LogFormat("Addressables - loading content catalog from {0}.", m_Addressables.ResourceManager.TransformInternalId(catalogs[index]));
            var loadOp = LoadContentCatalog(catalogs[index], m_ProviderSuffix, remoteHashLocation);

            if (loadOp.IsDone)
            {
                LoadOpComplete(loadOp, catalogs, locMap, index, remoteHashLocation);
            }
            else
            {
                loadOp.Completed += op =>
                {
                    LoadOpComplete(op, catalogs, locMap, index, remoteHashLocation);
                }
            };
            return(loadOp);
        }

        void LoadOpComplete(AsyncOperationHandle <IResourceLocator> op, IList <IResourceLocation> catalogs, ResourceLocationMap locMap, int index, IResourceLocation remoteHashLocation)
        {
            if (op.Result != null)
            {
                m_Addressables.RemoveResourceLocator(locMap);
                Result = op.Result;
                Complete(Result, true, string.Empty);
                m_Addressables.Release(op);
                Addressables.Log("Addressables - initialization complete.");
            }
            else
            {
                Addressables.LogFormat("Addressables - failed to load content catalog from {0}.", op);
                if (index + 1 >= catalogs.Count)
                {
                    Addressables.LogWarningFormat("Addressables - initialization failed.", op);
                    m_Addressables.RemoveResourceLocator(locMap);
                    if (op.OperationException != null)
                    {
                        Complete(Result, false, op.OperationException);
                    }
                    else
                    {
                        Complete(Result, false, "LoadContentCatalogInternal");
                    }
                    m_Addressables.Release(op);
                }
                else
                {
                    m_loadCatalogOp = LoadContentCatalogInternal(catalogs, index + 1, locMap, remoteHashLocation);
                    m_Addressables.Release(op);
                }
            }
        }
    }
        static void LoadProvider(AddressablesImpl addressables, ObjectInitializationData providerData, string providerSuffix)
        {
            //don't add providers that have the same id...
            var indexOfExistingProvider = -1;
            var newProviderId           = string.IsNullOrEmpty(providerSuffix) ? providerData.Id : (providerData.Id + providerSuffix);

            for (int i = 0; i < addressables.ResourceManager.ResourceProviders.Count; i++)
            {
                var rp = addressables.ResourceManager.ResourceProviders[i];
                if (rp.ProviderId == newProviderId)
                {
                    indexOfExistingProvider = i;
                    break;
                }
            }

            //if not re-initializing, just use the old provider
            if (indexOfExistingProvider >= 0 && string.IsNullOrEmpty(providerSuffix))
            {
                return;
            }

            var provider = providerData.CreateInstance <IResourceProvider>(newProviderId);

            if (provider != null)
            {
                if (indexOfExistingProvider < 0 || !string.IsNullOrEmpty(providerSuffix))
                {
                    Addressables.LogFormat("Addressables - added provider {0} with id {1}.", provider, provider.ProviderId);
                    addressables.ResourceManager.ResourceProviders.Add(provider);
                }
                else
                {
                    Addressables.LogFormat("Addressables - replacing provider {0} at index {1}.", provider, indexOfExistingProvider);
                    addressables.ResourceManager.ResourceProviders[indexOfExistingProvider] = provider;
                }
            }
            else
            {
                Addressables.LogWarningFormat("Addressables - Unable to load resource provider from {0}.", providerData);
            }
        }
Example #8
0
        Entry CreateEntry(string key, object value)
        {
            var entry = new Entry();

            entry.Key = key;
            var objType = value.GetType();

            entry.AssemblyName = objType.Assembly.FullName;
            entry.ClassName    = objType.FullName;
            try
            {
                if (objType == typeof(string))
                {
                    entry.Data = value as string;
                }
                else if (objType.IsEnum)
                {
                    entry.Data = value.ToString();
                }
                else
                {
                    var parseMethod = objType.GetMethod("Parse", BindingFlags.Static | BindingFlags.Public, null, CallingConventions.Any, new[] { typeof(string) }, null);
                    if (parseMethod == null || parseMethod.ReturnType != objType)
                    {
                        entry.Data = JsonUtility.ToJson(value);
                    }
                    else
                    {
                        entry.Data = value.ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                Addressables.LogWarningFormat("KeyDataStore unable to serizalize entry {0} with value {1}, exception: {2}", key, value, ex);
            }
            return(entry);
        }
        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);
            }
        }