public FastModeInitializationOperation(AddressablesImpl addressables, AddressableAssetSettings settings)
 {
     m_addressables = addressables;
     m_settings     = settings;
     m_addressables.ResourceManager.RegisterForCallbacks();
     m_Diagnostics = new ResourceManagerDiagnostics(m_addressables.ResourceManager);
 }
예제 #2
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);
            }
        }
        protected override void Execute()
        {
            var db = GetBuilderOfType <BuildScriptFastMode>(m_settings);

            if (db == null)
            {
                UnityEngine.Debug.Log($"Unable to find {nameof(BuildScriptFastMode)} builder in settings assets. Using default Instance and Scene Providers.");
            }

            var locator = new AddressableAssetSettingsLocator(m_settings);

            m_addressables.AddResourceLocator(locator);
            m_addressables.AddResourceLocator(new DynamicResourceLocator(m_addressables));
            m_addressables.ResourceManager.postProfilerEvents = ProjectConfigData.PostProfilerEvents;
            if (!m_addressables.ResourceManager.postProfilerEvents)
            {
                m_Diagnostics.Dispose();
                m_Diagnostics = null;
                m_addressables.ResourceManager.ClearDiagnosticCallbacks();
            }
            //NOTE: for some reason, the data builders can get lost from the settings asset during a domain reload - this only happens in tests and custom instance and scene providers are not needed
            m_addressables.InstanceProvider = db == null ? new InstanceProvider() : ObjectInitializationData.CreateSerializedInitializationData(db.instanceProviderType.Value).CreateInstance <IInstanceProvider>();
            m_addressables.SceneProvider    = db == null ? new SceneProvider() : ObjectInitializationData.CreateSerializedInitializationData(db.sceneProviderType.Value).CreateInstance <ISceneProvider>();
            m_addressables.ResourceManager.ResourceProviders.Add(new AssetDatabaseProvider());
            m_addressables.ResourceManager.ResourceProviders.Add(new TextDataProvider());
            m_addressables.ResourceManager.ResourceProviders.Add(new JsonAssetProvider());
            m_addressables.ResourceManager.ResourceProviders.Add(new LegacyResourcesProvider());
            m_addressables.ResourceManager.ResourceProviders.Add(new AtlasSpriteProvider());
            m_addressables.ResourceManager.ResourceProviders.Add(new ContentCatalogProvider(m_addressables.ResourceManager));
            WebRequestQueue.SetMaxConcurrentRequests(m_settings.MaxConcurrentWebRequests);

            if (m_settings.InitializationObjects.Count == 0)
            {
                Complete(locator, true, null);
            }
            else
            {
                List <AsyncOperationHandle> initOperations = new List <AsyncOperationHandle>();
                foreach (var io in m_settings.InitializationObjects)
                {
                    if (io is IObjectInitializationDataProvider)
                    {
                        var ioData = (io as IObjectInitializationDataProvider).CreateObjectInitializationData();
                        var h      = ioData.GetAsyncInitHandle(m_addressables.ResourceManager);
                        initOperations.Add(h);
                    }
                }

                groupOp            = m_addressables.ResourceManager.CreateGenericGroupOperation(initOperations, true);
                groupOp.Completed += op =>
                {
                    bool success = op.Status == AsyncOperationStatus.Succeeded;
                    Complete(locator, success, success ? "" : $"{op.DebugName}, status={op.Status}, result={op.Result} failed initialization.");
                    m_addressables.Release(op);
                };
            }
        }
 public InitializationOperation(AddressablesImpl aa)
 {
     m_Addressables = aa;
     m_Diagnostics  = new ResourceManagerDiagnostics(aa.ResourceManager);
 }
        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);
            }
        }