public void ProcessDependentOpResults_FailsWithErrorMessageOnInternalError() { var remoteHashLoc = new ResourceLocationBase("RemoteHash", "Remote", kRemoteHashProviderId, typeof(string)); var localHashLoc = new ResourceLocationBase("LocalHash", "Local", kLocalHashProviderId, typeof(string)); var catalogLoc = new ResourceLocationBase("cat", "cat_id", nameof(TestCatalogProvider), typeof(IResourceLocator), remoteHashLoc, localHashLoc); var op1 = new ExceptionTestOperation(new Exception("Bad operation"), null); var handle1 = new AsyncOperationHandle(op1); var results = new List <AsyncOperationHandle>(); var loc = new TestLocator(kLocatorId); var locInfo = new AddressablesImpl.ResourceLocatorInfo(loc, "same", catalogLoc); var locInfos = new List <AddressablesImpl.ResourceLocatorInfo>(); locInfos.Add(locInfo); var trivialHashes = new List <string>(new[] { "badHash" }); results.Add(handle1); bool success; string errorString; var result = CheckCatalogsOperation.ProcessDependentOpResults(results, locInfos, trivialHashes, out errorString, out success); LogAssert.Expect(LogType.Error, "System.Exception: Bad operation"); Assert.AreEqual(false, success, "Operation should not succeed when underlying operation op1 has a non null OperationException"); Assert.AreEqual(true, errorString.Contains("Bad operation"), "Error string should contain the error message thrown by the underlying operation"); Assert.IsNull(result, "Result should be null in the case where every operation within it failed."); }
public IEnumerator UpdateContent_UpdatesCatalogs_WhenAutoCleanCacheEnabled_AndCachingDisabled_ReturnsException() { #if !ENABLE_CACHING && !PLATFORM_SWITCH var remoteHashLoc = new ResourceLocationBase("RemoteHash", "Remote", kRemoteHashProviderId, typeof(string)); var localHashLoc = new ResourceLocationBase("LocalHash", "Local", kLocalHashProviderId, typeof(string)); var catalogLoc = new ResourceLocationBase("cat", "cat_id", typeof(TestCatalogProvider).FullName, typeof(object), remoteHashLoc, localHashLoc); m_Addressables.RuntimePath = m_RuntimeSettingsPath; m_Addressables.ResourceManager.ResourceProviders.Add(new TestHashProvider(kRemoteHashProviderId, "different")); m_Addressables.ResourceManager.ResourceProviders.Add(new TestHashProvider(kLocalHashProviderId, "same")); m_Addressables.ResourceManager.ResourceProviders.Add(new TestCatalogProvider(kNewLocatorId)); m_Addressables.AddResourceLocator(new TestLocator(kLocatorId, remoteHashLoc, localHashLoc, catalogLoc), "same", catalogLoc); LogAssert.Expect(LogType.Error, "System.Exception: Caching not enabled. There is no bundle cache to modify."); var updateOp = m_Addressables.UpdateCatalogs(null, false, true); yield return(updateOp); LogAssert.Expect(LogType.Error, "OperationException : CompletedOperation, status=Failed, result=False catalogs updated, but failed to clean bundle cache."); Assert.AreEqual(updateOp.OperationException.Message, "ChainOperation failed because dependent operation failed"); Assert.AreEqual(updateOp.OperationException.InnerException.Message, "CompletedOperation, status=Failed, result=False catalogs updated, but failed to clean bundle cache."); m_Addressables.Release(updateOp); #else Assert.Ignore("Caching is enabled, but test expects to run on caching-disabled platforms or platform was skipped."); yield return(null); #endif }
public void ProcessDependentOpResults_SucceedsOnNoErrorMessage() { var remoteHashLoc = new ResourceLocationBase("RemoteHash", "Remote", kRemoteHashProviderId, typeof(string)); var localHashLoc = new ResourceLocationBase("LocalHash", "Local", kLocalHashProviderId, typeof(string)); var catalogLoc = new ResourceLocationBase("cat", "cat_id", nameof(TestCatalogProvider), typeof(IResourceLocator), remoteHashLoc, localHashLoc); var op1 = new ExceptionTestOperation(null, "good result", true); var handle1 = new AsyncOperationHandle(op1); var results = new List <AsyncOperationHandle>(); var loc = new TestLocator(kLocatorId); var locInfo = new AddressablesImpl.ResourceLocatorInfo(loc, "same", catalogLoc); var locInfos = new List <AddressablesImpl.ResourceLocatorInfo>(); locInfos.Add(locInfo); var trivialHashes = new List <string>(new[] { "same" }); results.Add(handle1); bool success; string errorString; var result = CheckCatalogsOperation.ProcessDependentOpResults(results, locInfos, trivialHashes, out errorString, out success); Assert.AreEqual(true, success, "Operation should succeed when underlying operation op1 has a null OperationException"); Assert.IsNull(errorString, "Error string should be null when operation is succeeding without errors."); Assert.NotNull(result, "Result should only be null when every operation within it fails."); }
public IEnumerator UpdateContent_UpdatesCatalogs_WhenAutoCleanCacheDisabled_NoBundlesRemovedFromCache() { #if ENABLE_CACHING var remoteHashLoc = new ResourceLocationBase("RemoteHash", "Remote", kRemoteHashProviderId, typeof(string)); var localHashLoc = new ResourceLocationBase("LocalHash", "Local", kLocalHashProviderId, typeof(string)); var catalogLoc = new ResourceLocationBase("cat", "cat_id", typeof(TestCatalogProvider).FullName, typeof(object), remoteHashLoc, localHashLoc); m_Addressables.ResourceManager.ResourceProviders.Add(new TestHashProvider(kRemoteHashProviderId, "different")); m_Addressables.ResourceManager.ResourceProviders.Add(new TestHashProvider(kLocalHashProviderId, "same")); m_Addressables.ResourceManager.ResourceProviders.Add(new TestCatalogProvider(kNewLocatorId)); m_Addressables.AddResourceLocator(new TestLocator(kLocatorId, remoteHashLoc, localHashLoc, catalogLoc), "same", catalogLoc); string cachedBundleName = "UpdatesCatalogsTestFakeBundle"; string hash = "123"; string fakeCachePath = AddressablesIntegrationTests.CreateFakeCachedBundle(cachedBundleName, hash); var updateOp = m_Addressables.UpdateCatalogs(null, false, false); yield return(updateOp); string fakeCacheFolder = Path.GetDirectoryName(fakeCachePath); Assert.IsTrue(Directory.Exists(fakeCacheFolder)); m_Addressables.Release(updateOp); Directory.Delete(fakeCacheFolder, true); #else Assert.Ignore("Caching not enabled."); yield return(null); #endif }
public void AssetBundleLoadPathsCorrectForGetLoadInfo(string internalId, bool isLocal, bool useUnityWebRequestForLocalBundles) { if (internalId.StartsWith("jar") && Application.platform != RuntimePlatform.Android) { Assert.Ignore($"Skipping test {TestContext.CurrentContext.Test.Name} due jar based tests are only for running on Android Platform."); } var loc = new ResourceLocationBase("dummy", internalId, "dummy", typeof(Object)); loc.Data = new AssetBundleRequestOptions { UseUnityWebRequestForLocalBundles = useUnityWebRequestForLocalBundles }; ProviderOperation <Object> op = new ProviderOperation <Object>(); op.Init(m_Addressables.ResourceManager, null, loc, new AsyncOperationHandle <IList <AsyncOperationHandle> >()); ProvideHandle h = new ProvideHandle(m_Addressables.ResourceManager, op); AssetBundleResource.GetLoadInfo(h, out AssetBundleResource.LoadType loadType, out string path); var expectedLoadType = isLocal ? useUnityWebRequestForLocalBundles ? AssetBundleResource.LoadType.Web : AssetBundleResource.LoadType.Local : AssetBundleResource.LoadType.Web; Assert.AreEqual(expectedLoadType, loadType, "Incorrect load type found for internalId " + internalId); var expectedPath = internalId; if (isLocal && useUnityWebRequestForLocalBundles) { expectedPath = internalId.StartsWith("jar") ? internalId : "file:///" + Path.GetFullPath(internalId); } Assert.AreEqual(expectedPath, path); }
public void ProvideResource_ReceiveDiagnosticsCallback_IGenericProviderOperationHasLocation() { m_Provider.ProvideCallback = (pi) => { pi.Complete(int.Parse(pi.Location.InternalId), true, null); }; m_RM.ResourceProviders.Add(m_Provider); List <ResourceManager.DiagnosticEventContext> eventsRecieved = new List <ResourceManager.DiagnosticEventContext>(); m_RM.RegisterDiagnosticCallback(ctx => { eventsRecieved.Add(ctx); }); var locations = new ResourceLocationBase("1", "1", m_Provider.ProviderId, typeof(object)); AsyncOperationHandle <object> op = m_RM.ProvideResource <object>(locations); m_RM.Update(0.0f); m_RM.ClearDiagnosticCallbacks(); for (int i = 0; i < eventsRecieved.Count; ++i) { if (eventsRecieved[i].OperationHandle.m_InternalOp is IGenericProviderOperation) { Assert.NotNull(eventsRecieved[i].Location); Assert.IsTrue(eventsRecieved[i].Location.InternalId == "1"); } } op.Release(); }
public void OnDestroyed_DepOpReleasedAndProviderReleased() { ResourceLocationBase depLoc = new ResourceLocationBase("dep", "dep", m_Provider2.ProviderId, typeof(object)); ResourceLocationBase loc = new ResourceLocationBase("1", "1", m_Provider.ProviderId, typeof(object), depLoc); ResourceLocationBase loc2 = new ResourceLocationBase("2", "2", m_Provider.ProviderId, typeof(object), depLoc); var op1 = m_RM.ProvideResource <object>(loc); m_RM.Update(0.0f); Assert.AreEqual(1, m_Provider2.ProvideLog.Count); var op2 = m_RM.ProvideResource <object>(loc2); m_RM.Update(0.0f); Assert.AreEqual(1, m_Provider2.ProvideLog.Count); Assert.AreEqual(2, m_Provider.ProvideLog.Count); Assert.AreEqual(AsyncOperationStatus.Succeeded, op1.Status); Assert.AreEqual(AsyncOperationStatus.Succeeded, op2.Status); // decrement the first op. the second op should still be holding the dependency op1.Release(); Assert.AreEqual(0, m_Provider2.ReleaseLog.Count); // decrement the second op. the dependency should now have been released op2.Release(); Assert.AreEqual(1, m_Provider2.ReleaseLog.Count); Assert.AreEqual(2, m_Provider.ReleaseLog.Count); Assert.AreEqual(1, m_Provider2.ReleaseLog.Count); }
public IEnumerator CheckForUpdates_Returns_OnlyModifiedResults() { var remoteHashLoc = new ResourceLocationBase("RemoteHash1", "Remote", kRemoteHashProviderId + 1, typeof(string)); var localHashLoc = new ResourceLocationBase("LocalHash1", "Local", kLocalHashProviderId + 1, typeof(string)); var catalogLoc = new ResourceLocationBase("cat1", "cat_id", nameof(TestCatalogProvider), typeof(IResourceLocator), remoteHashLoc, localHashLoc); var remoteHashLoc2 = new ResourceLocationBase("RemoteHash2", "Remote", kRemoteHashProviderId + 2, typeof(string)); var localHashLoc2 = new ResourceLocationBase("LocalHash2", "Local", kLocalHashProviderId + 2, typeof(string)); var catalogLoc2 = new ResourceLocationBase("cat2", "cat_id", nameof(TestCatalogProvider), typeof(IResourceLocator), remoteHashLoc2, localHashLoc2); var aa = new AddressablesImpl(null); aa.ResourceManager.ResourceProviders.Add(new TestHashProvider(kRemoteHashProviderId + 1, "same")); aa.ResourceManager.ResourceProviders.Add(new TestHashProvider(kLocalHashProviderId + 1, "same")); aa.ResourceManager.ResourceProviders.Add(new TestHashProvider(kRemoteHashProviderId + 2, "different")); aa.ResourceManager.ResourceProviders.Add(new TestHashProvider(kLocalHashProviderId + 2, "same")); aa.ResourceManager.ResourceProviders.Add(new TestCatalogProvider(kNewLocatorId)); aa.AddResourceLocator(new TestLocator(kLocatorId), "same", catalogLoc); aa.AddResourceLocator(new TestLocator(kLocatorId + 2), "same", catalogLoc2); var op = aa.CheckForCatalogUpdates(false); yield return(op); Assert.IsNotNull(op.Result); Assert.AreEqual(1, op.Result.Count); Assert.AreEqual(kLocatorId + 2, op.Result[0]); Assert.AreEqual(1, aa.CatalogsWithAvailableUpdates.Count()); Assert.AreEqual(kLocatorId + 2, aa.CatalogsWithAvailableUpdates.First()); aa.Release(op); }
public IEnumerator InitializationObjects_CompletesWhenObjectsPresent() { if (m_RuntimeSettingsPath.StartsWith("GUID:")) { Debug.Log($"{nameof(InitializationObjects_CompletesWhenObjectsPresent)} skipped due to not having a runtime settings asset (Fast mode does not create this)."); yield break; } InitalizationObjectsOperation op = new InitalizationObjectsOperation(); op.Completed += obj => { Assert.AreEqual(AsyncOperationStatus.Succeeded, obj.Status); Assert.IsTrue(obj.Result); }; var runtimeDataLocation = new ResourceLocationBase("RuntimeData", m_RuntimeSettingsPath, typeof(JsonAssetProvider).FullName, typeof(ResourceManagerRuntimeData)); var rtdOp = m_Addressables.ResourceManager.ProvideResource <ResourceManagerRuntimeData>(runtimeDataLocation); rtdOp.Completed += obj => { ObjectInitializationData opData = ObjectInitializationData.CreateSerializedInitializationData <FakeInitializationObject>("fake", "fake"); obj.Result.InitializationObjects.Add(opData); }; yield return(rtdOp); op.Init(rtdOp, m_Addressables); var handle = m_Addressables.ResourceManager.StartOperation(op, rtdOp); yield return(handle); }
public override void Provide(ProvideHandle provideHandle) { var addressableId = provideHandle.Location.InternalId.Replace("playfab://", ""); PlayFabClientAPI.GetContentDownloadUrl( new GetContentDownloadUrlRequest() { Key = addressableId, ThruCDN = false }, result => { var dependenciesList = provideHandle.Location.Dependencies; var dependenciesArray = provideHandle.Location.Dependencies == null ? new IResourceLocation[0] : new IResourceLocation[dependenciesList.Count]; dependenciesList?.CopyTo(dependenciesArray, 0); var resourceLocation = new ResourceLocationBase(result.URL, result.URL, typeof(AssetBundleProvider).FullName, typeof(IResourceLocator), dependenciesArray) { Data = provideHandle.Location.Data, PrimaryKey = provideHandle.Location.PrimaryKey }; provideHandle.ResourceManager.ProvideResource <IAssetBundleResource>(resourceLocation).Completed += handle => { var contents = handle.Result; provideHandle.Complete(contents, true, handle.OperationException); }; }, error => Debug.LogError(error.GenerateErrorReport())); }
public void ProvideResources_ReleaseDependenciesOnFailure_DoesNotOverReleaseAfterCallingRelease() { ResourceLocationBase depLoc1a = new ResourceLocationBase("dep1a", "dep1a", "unknown provider", typeof(object)); ResourceLocationBase depLoc2a = new ResourceLocationBase("dep2a", "dep2a", m_Provider.ProviderId, typeof(object)); ResourceLocationBase loc_a = new ResourceLocationBase("loc_a", "1", m_Provider.ProviderId, typeof(object), depLoc1a, depLoc2a); ResourceLocationBase depLoc1b = new ResourceLocationBase("dep1b", "dep1b", "unknown provider", typeof(object)); ResourceLocationBase depLoc2b = new ResourceLocationBase("dep2b", "dep2b", m_Provider.ProviderId, typeof(object)); ResourceLocationBase loc_b = new ResourceLocationBase("loc_b", "2", m_Provider.ProviderId, typeof(object), depLoc1b, depLoc2b); ResourceLocationBase loc_shared = new ResourceLocationBase("loc_shared", "3", m_Provider.ProviderId, typeof(object), depLoc2a); var op_shared = m_RM.ProvideResources <object>(new List <IResourceLocation> { loc_shared }, true, null); var op = m_RM.ProvideResources <object>(new List <IResourceLocation> { loc_a, loc_b }, true, null); m_RM.Update(0.0f); Assert.AreEqual(AsyncOperationStatus.Failed, op.Status); Assert.AreEqual(AsyncOperationStatus.Succeeded, op_shared.Status); Assert.AreEqual(3, m_Provider.ProvideLog.Count); Assert.AreEqual(1, m_Provider.ReleaseLog.Count); Assert.IsNull(op.Result); op.Release(); Assert.AreEqual(1, m_Provider.ReleaseLog.Count); op_shared.Release(); Assert.AreEqual(3, m_Provider.ReleaseLog.Count); }
public void Locations_WithDiffNames_LocationEquals_Returns_True() { var l1 = new ResourceLocationBase("a", "b", "c", typeof(Mesh)); var l2 = new ResourceLocationBase("x", "b", "c", typeof(Mesh)); Assert.IsTrue(LocationUtils.LocationEquals(l1, l2)); }
public IEnumerator WhenWebRequestOverrideIsSet_CallbackIsCalled_AssetBundleProvider() { bool webRequestOverrideCalled = false; m_Addressables.WebRequestOverride = request => webRequestOverrideCalled = true; var prev = LogAssert.ignoreFailingMessages; LogAssert.ignoreFailingMessages = true; var nonExistingPath = "http://127.0.0.1/non-existing-bundle"; var loc = new ResourceLocationBase(nonExistingPath, nonExistingPath, typeof(AssetBundleProvider).FullName, typeof(AssetBundleResource)); loc.Data = new AssetBundleRequestOptions(); var h = m_Addressables.ResourceManager.ProvideResource <AssetBundleResource>(loc); yield return(h); if (h.IsValid()) { h.Release(); } LogAssert.ignoreFailingMessages = prev; Assert.IsTrue(webRequestOverrideCalled); }
internal static AsyncOperationHandle <IResourceLocator> CreateInitializationOperation(AddressablesImpl aa, string playerSettingsLocation, string providerSuffix) { var jp = new JsonAssetProvider(); jp.IgnoreFailures = true; aa.ResourceManager.ResourceProviders.Add(jp); var tdp = new TextDataProvider(); tdp.IgnoreFailures = true; aa.ResourceManager.ResourceProviders.Add(tdp); aa.ResourceManager.ResourceProviders.Add(new ContentCatalogProvider(aa.ResourceManager)); var runtimeDataLocation = new ResourceLocationBase("RuntimeData", playerSettingsLocation, typeof(JsonAssetProvider).FullName, typeof(ResourceManagerRuntimeData)); var initOp = new InitializationOperation(aa); initOp.m_rtdOp = aa.ResourceManager.ProvideResource <ResourceManagerRuntimeData>(runtimeDataLocation); initOp.m_ProviderSuffix = providerSuffix; initOp.m_InitGroupOps = new InitalizationObjectsOperation(); initOp.m_InitGroupOps.Init(initOp.m_rtdOp, aa); var groupOpHandle = aa.ResourceManager.StartOperation(initOp.m_InitGroupOps, initOp.m_rtdOp); return(aa.ResourceManager.StartOperation <IResourceLocator>(initOp, groupOpHandle)); }
public void ProvideInstance_CanProvide() { m_ResourceManager.ResourceProviders.Add(new GameObjectProvider()); ResourceLocationBase locDep = new ResourceLocationBase("prefab", "prefab1", "GOPRovider", typeof(UnityEngine.GameObject)); MockInstanceProvider iProvider = new MockInstanceProvider(); InstantiationParameters instantiationParameters = new InstantiationParameters(null, true); AsyncOperationHandle <GameObject>[] refResource = new AsyncOperationHandle <GameObject> [1]; iProvider.ProvideInstanceCallback = (rm, prefabHandle, iParam) => { refResource[0] = prefabHandle; Assert.AreEqual("prefab1", prefabHandle.Result.name); return(new GameObject("instance1")); }; iProvider.ReleaseInstanceCallback = (rm, go) => { rm.Release(refResource[0]); GameObject.Destroy(go); }; AsyncOperationHandle <GameObject> obj = m_ResourceManager.ProvideInstance(iProvider, locDep, instantiationParameters); m_ResourceManager.Update(0.0f); Assert.AreEqual(AsyncOperationStatus.Succeeded, obj.Status); Assert.AreEqual("instance1", obj.Result.name); Assert.AreEqual(1, m_ResourceManager.OperationCacheCount); obj.Release(); }
public IEnumerator ProvideResource_WhenRemote_ExceptionHandlerReceivesExceptionWithWebRequestError() { m_ResourceManager.ResourceProviders.Add(new AssetBundleProvider()); ResourceLocationBase location = new ResourceLocationBase("nonExistingResource", "http://urlThatCantPossiblyExistsaaaaaaaa.com/bundleName.bundle", typeof(AssetBundleProvider).FullName, typeof(IAssetBundleResource)); location.Data = new AssetBundleRequestOptions() { BundleName = "bundleName", Timeout = 0 }; var prevHandler = ResourceManager.ExceptionHandler; bool exceptionWithRequestResultReceived = false; ResourceManager.ExceptionHandler += (h, ex) => { exceptionWithRequestResultReceived |= ex is RemoteProviderException pEx && pEx.WebRequestResult != null; }; AsyncOperationHandle <IAssetBundleResource> handle = m_ResourceManager.ProvideResource <IAssetBundleResource>(location); yield return(handle); ResourceManager.ExceptionHandler = prevHandler; Assert.AreEqual(AsyncOperationStatus.Failed, handle.Status); Assert.IsTrue(exceptionWithRequestResultReceived); handle.Release(); }
public void ReleaseInstance_BeforeDependencyCompletes_InstantiatesAndReleasesAfterDependencyCompletes() { var prefabProv = new MockProvider(); ProvideHandle[] provHandle = new ProvideHandle[1]; prefabProv.ProvideCallback = h => provHandle[0] = h; m_ResourceManager.ResourceProviders.Add(prefabProv); ResourceLocationBase locDep = new ResourceLocationBase("prefab", "prefab1", prefabProv.ProviderId, typeof(UnityEngine.GameObject)); var iProvider = new MockInstanceProvider(); bool provideCalled = false; bool releaseCalled = false; iProvider.ProvideInstanceCallback = (rm, prefabHandle, iParam) => { provideCalled = true; prefabHandle.Release(); return(null); }; iProvider.ReleaseInstanceCallback = (rm, go) => { releaseCalled = true; }; var instHandle = m_ResourceManager.ProvideInstance(iProvider, locDep, default(InstantiationParameters)); Assert.IsFalse(instHandle.IsDone); m_ResourceManager.Release(instHandle); Assert.IsTrue(instHandle.IsValid()); Assert.IsFalse(provideCalled); Assert.IsFalse(releaseCalled); provHandle[0].Complete <GameObject>(null, true, null); Assert.IsTrue(provideCalled); Assert.IsTrue(releaseCalled); }
public override void Provide(ProvideHandle provideHandle) { if (provideHandle.Location.InternalId.StartsWith("playfab://") == false) { base.Provide(provideHandle); return; } var addressableId = provideHandle.Location.InternalId.Replace("playfab://", ""); PlayFabClientAPI.GetContentDownloadUrl( new GetContentDownloadUrlRequest() { Key = addressableId, ThruCDN = false }, result => { Assert.IsTrue(provideHandle.Location.ResourceType == typeof(ContentCatalogData), "Only catalogs supported"); var resourceLocation = new ResourceLocationBase(result.URL, result.URL, typeof(JsonAssetProvider).FullName, typeof(string)); provideHandle.ResourceManager.ProvideResource <ContentCatalogData>(resourceLocation).Completed += handle => { var contents = handle.Result; provideHandle.Complete(contents, true, handle.OperationException); }; }, error => Debug.LogError(error.GenerateErrorReport())); }
internal void LoadCatalog(string idToLoad, bool isLocalCatalogInBundle, bool isLocalCatalog) { try { if (isLocalCatalogInBundle && isLocalCatalog) { m_BundledCatalog = new BundledCatalog(idToLoad); m_BundledCatalog.OnLoaded += ccd => { m_ContentCatalogData = ccd; OnCatalogLoaded(ccd); }; m_BundledCatalog.LoadCatalogFromBundleAsync(); } else { IResourceLocation location = new ResourceLocationBase(idToLoad, idToLoad, typeof(JsonAssetProvider).FullName, typeof(ContentCatalogData)); m_ContentCatalogDataLoadOp = m_ProviderInterface.ResourceManager.ProvideResource <ContentCatalogData>(location); m_ContentCatalogDataLoadOp.Completed += CatalogLoadOpCompleteCallback; } } catch (Exception ex) { m_ProviderInterface.Complete <ContentCatalogData>(null, false, ex); } }
public IEnumerator UpdateContent_UpdatesCatalogs_Returns_ListOfLocators() { var remoteHashLoc = new ResourceLocationBase("RemoteHash", "Remote", kRemoteHashProviderId, typeof(string)); var localHashLoc = new ResourceLocationBase("LocalHash", "Local", kLocalHashProviderId, typeof(string)); var catalogLoc = new ResourceLocationBase("cat", "cat_id", typeof(TestCatalogProvider).FullName, typeof(object), remoteHashLoc, localHashLoc); var aa = new AddressablesImpl(null); aa.ResourceManager.ResourceProviders.Add(new TestHashProvider(kRemoteHashProviderId, "different")); aa.ResourceManager.ResourceProviders.Add(new TestHashProvider(kLocalHashProviderId, "same")); aa.ResourceManager.ResourceProviders.Add(new TestCatalogProvider(kNewLocatorId)); aa.AddResourceLocator(new TestLocator(kLocatorId, remoteHashLoc, localHashLoc, catalogLoc), "same", catalogLoc); var op = aa.CheckForCatalogUpdates(false); yield return(op); Assert.IsNotNull(op.Result); Assert.AreEqual(1, op.Result.Count); var updateOp = aa.UpdateCatalogs(op.Result, false); aa.Release(op); yield return(updateOp); Assert.IsNotNull(updateOp.Result); Assert.AreEqual(1, updateOp.Result.Count); Assert.AreEqual(kNewLocatorId, updateOp.Result[0].LocatorId); aa.Release(updateOp); }
public IEnumerator WhenWebRequestFails_RetriesCorrectAmount_AssetBundleProvider() { var prev = LogAssert.ignoreFailingMessages; LogAssert.ignoreFailingMessages = true; var nonExistingPath = "http://127.0.0.1/non-existing-bundle"; var loc = new ResourceLocationBase(nonExistingPath, nonExistingPath, typeof(AssetBundleProvider).FullName, typeof(AssetBundleResource)); var d = new AssetBundleRequestOptions(); d.RetryCount = 3; loc.Data = d; LogAssert.Expect(LogType.Log, new Regex(@"^(Web request failed, retrying \(0/3)")); LogAssert.Expect(LogType.Log, new Regex(@"^(Web request failed, retrying \(1/3)")); LogAssert.Expect(LogType.Log, new Regex(@"^(Web request failed, retrying \(2/3)")); var h = m_Addressables.ResourceManager.ProvideResource <AssetBundleResource>(loc); yield return(h); if (h.IsValid()) { h.Release(); } LogAssert.ignoreFailingMessages = prev; }
public IEnumerator InitializationObjects_CompletesWhenObjectsPresent() { InitalizationObjectsOperation op = new InitalizationObjectsOperation(); op.Completed += obj => { Assert.AreEqual(AsyncOperationStatus.Succeeded, obj.Status); Assert.IsTrue(obj.Result); }; var runtimeDataLocation = new ResourceLocationBase("RuntimeData", m_RuntimeSettingsPath, typeof(JsonAssetProvider).FullName, typeof(ResourceManagerRuntimeData)); var rtdOp = m_Addressables.ResourceManager.ProvideResource <ResourceManagerRuntimeData>(runtimeDataLocation); rtdOp.Completed += obj => { ObjectInitializationData opData = ObjectInitializationData.CreateSerializedInitializationData <FakeInitializationObject>("fake", "fake"); obj.Result.InitializationObjects.Add(opData); }; yield return(rtdOp); op.Init(rtdOp, m_Addressables); var handle = m_Addressables.ResourceManager.StartOperation(op, rtdOp); yield return(handle); }
public void WhenProviderCallsComplete_AndTypeIsIncorrect_Throws() { ResourceLocationBase loc = new ResourceLocationBase("1", "1", m_Provider.ProviderId, typeof(object)); Exception testException = null; m_Provider.ProvideCallback = (x) => { try { x.Complete(new Type2(), true, null); } catch (Exception e) { testException = e; } }; var op = m_RM.ProvideResource <Type1>(loc); m_RM.Update(0.0f); Assert.IsNotNull(testException); Assert.AreEqual(AsyncOperationStatus.Failed, op.Status); Assert.IsNull(op.Result); Assert.IsTrue(op.OperationException.Message.Contains("Provider of type")); op.Release(); }
public IEnumerator GetDownloadSize_CalculatesCachedBundles() { #if ENABLE_CACHING yield return(Init()); long expectedSize = 0; long bundleSize1 = 1000; long bundleSize2 = 500; var locMap = new ResourceLocationMap("TestLocator"); Caching.ClearCache(); //Simulating a cached bundle string fakeCachePath = CreateFakeCachedBundle("GetDownloadSize_CalculatesCachedBundlesBundle1", "be38e35d2177c282d5d6a2e54a803aab"); var bundleLoc1 = new ResourceLocationBase("sizeTestBundle1", "http://nowhere.com/GetDownloadSize_CalculatesCachedBundlesBundle1.bundle", typeof(AssetBundleProvider).FullName, typeof(object)); var sizeData1 = (bundleLoc1.Data = CreateLocationSizeData("cachedSizeTestBundle1", bundleSize1, 123, "be38e35d2177c282d5d6a2e54a803aab")) as ILocationSizeData; if (sizeData1 != null) { expectedSize += sizeData1.ComputeSize(bundleLoc1); } var bundleLoc2 = new ResourceLocationBase("cachedSizeTestBundle2", "http://nowhere.com/GetDownloadSize_CalculatesCachedBundlesBundle2.bundle", typeof(AssetBundleProvider).FullName, typeof(object)); var sizeData2 = (bundleLoc2.Data = CreateLocationSizeData("cachedSizeTestBundle2", bundleSize2, 123, "d9fe965a6b253fb9dbd3e1cb08b7d66f")) as ILocationSizeData; if (sizeData2 != null) { expectedSize += sizeData2.ComputeSize(bundleLoc2); } var assetLoc = new ResourceLocationBase("cachedSizeTestAsset", "myASset.asset", typeof(BundledAssetProvider).FullName, typeof(object), bundleLoc1, bundleLoc2); locMap.Add("cachedSizeTestBundle1", bundleLoc1); locMap.Add("cachedSizeTestBundle2", bundleLoc2); locMap.Add("cachedSizeTestAsset", assetLoc); m_Addressables.AddResourceLocator(locMap); var dOp = m_Addressables.GetDownloadSizeAsync("cachedSizeTestAsset"); yield return(dOp); Assert.IsTrue((bundleSize1 + bundleSize2) > dOp.Result); Assert.AreEqual(expectedSize, dOp.Result); dOp.Release(); m_Addressables.RemoveResourceLocator(locMap); Directory.Delete(fakeCachePath, true); #else Assert.Ignore(); yield break; #endif }
public AsyncOperationHandle <IResourceLocator> LoadContentCatalogAsync(string catalogPath, string providerSuffix = null) { var catalogLoc = new ResourceLocationBase(catalogPath, catalogPath, typeof(JsonAssetProvider).FullName, typeof(IResourceLocator)); if (!InitializationOperation.IsDone) { return(ResourceManager.CreateChainOperation(InitializationOperation, op => LoadContentCatalogAsync(catalogPath, providerSuffix))); } return(Initialization.InitializationOperation.LoadContentCatalog(this, catalogLoc, providerSuffix)); }
public void AssetDatabaseProvider_LoadAssetAtPath_WhenNotInAssetDatabase_DoesNotThrow() { var loc = new ResourceLocationBase("name", "id", "providerId", typeof(object)); ProviderOperation <Object> op = new ProviderOperation <Object>(); op.Init(m_ResourceManager, null, loc, new AsyncOperationHandle <IList <AsyncOperationHandle> >()); ProvideHandle handle = new ProvideHandle(m_ResourceManager, op); Assert.DoesNotThrow(() => AssetDatabaseProvider.LoadAssetAtPath("doesnotexist", handle)); }
private ResourceLocationBase AddNewBundle(VirtualAssetBundleRuntimeData data, string bundleName, bool local, int dataSize, int headerSize) { VirtualAssetBundle bundle = new VirtualAssetBundle(bundleName, local, 0, ""); bundle.SetSize(dataSize, headerSize); data.AssetBundles.Add(bundle); ResourceLocationBase bundleLocation = new ResourceLocationBase(bundleName, bundleName, typeof(AssetBundleProvider).FullName, typeof(IAssetBundleResource)); bundle.SetSize(dataSize, headerSize); return(bundleLocation); }
public void WhenProviderThrowsExceptionOnProvide_OperationFails() { ResourceLocationBase loc = new ResourceLocationBase("1", "1", m_Provider.ProviderId, typeof(object)); m_Provider.ProvideCallback = (x) => { throw new Exception("I have failed"); }; var op = m_RM.ProvideResource <Type1>(loc); m_RM.Update(0.0f); Assert.AreEqual(AsyncOperationStatus.Failed, op.Status); op.Release(); }
public void ProvideResource_WhenDependencyFailsToLoad_AndProviderCannotLoadWithFailedDependencies_ProvideNotCalled() { m_Provider.ProvideCallback = (pi) => { throw new Exception("This Should Not Have Been Called"); }; m_RM.ResourceProviders.Add(m_Provider); ResourceLocationBase locDep = new ResourceLocationBase("depasset", "depasset", "unkonwn", typeof(object)); ResourceLocationBase locRoot = new ResourceLocationBase("rootasset", "rootasset", m_Provider.ProviderId, typeof(object), locDep); AsyncOperationHandle <object> op = m_RM.ProvideResource <object>(locRoot); m_RM.Update(0.0f); Assert.AreEqual(AsyncOperationStatus.Failed, op.Status); op.Release(); }
public void WhenDependentOpFails_ProvideIsNotCalled() { ResourceLocationBase depLoc = new ResourceLocationBase("dep", "dep", "unknown provider", typeof(object)); ResourceLocationBase loc = new ResourceLocationBase("1", "1", m_Provider.ProviderId, typeof(object), depLoc); var op = m_RM.ProvideResource <object>(loc); m_RM.Update(0.0f); Assert.AreEqual(AsyncOperationStatus.Failed, op.Status); op.Release(); Assert.AreEqual(0, m_Provider.ProvideLog.Count); Assert.AreEqual(0, m_Provider.ReleaseLog.Count); }