protected override void Destroy()
        {
            if (m_WrappedOp.IsValid())
            {
                m_WrappedOp.Release();
            }

            if (m_DepOp.IsValid())
            {
                m_DepOp.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 IEnumerator AddressablesImpl_DownloadDependenciesAsync_CantDownloadWhenGetResourceLocFailsObjectList()
        {
            // Setup
            yield return(Init());

            var deps          = new List <object>();
            var provideHandle = new ProvideHandle(m_Addressables.ResourceManager, new ProviderOperation <AssetBundleResource>());

            provideHandle.GetDependencies(deps);

            AsyncOperationHandle op = new AsyncOperationHandle();

            using (new IgnoreFailingLogMessage())
            {
                op = m_Addressables.DownloadDependenciesAsync(deps, Addressables.MergeMode.Intersection, false);
                yield return(op);
            }

            // Test
            Assert.AreEqual(AsyncOperationStatus.Failed, op.Status);
            Assert.IsTrue(op.OperationException.Message.Contains("InvalidKey"));
            Assert.IsNull(op.Result);

            // Cleanup
            op.Release();
        }
        public void AsyncOperationHandle_Release_DecrementsRefCount()
        {
            int expectedCount = 10;
            var op            = new FakeTypedOperation();

            AsyncOperationHandle <GameObject> typedHandle      = new AsyncOperationHandle <GameObject>(op);
            AsyncOperationHandle <GameObject> validationHandle = new AsyncOperationHandle <GameObject>(op);

            IncreaseRefCount(typedHandle, expectedCount - 1);

            typedHandle.Release();
            expectedCount--;
            var actualRefCount = DestructiveGetRefCount(validationHandle);

            Assert.AreEqual(expectedCount, actualRefCount);

            op = new FakeTypedOperation();

            AsyncOperationHandle typelessHandle     = new AsyncOperationHandle(op);
            AsyncOperationHandle typelessValidation = new AsyncOperationHandle(op);

            IncreaseRefCount(typelessHandle, expectedCount - 1);
            typelessHandle.Release();
            expectedCount--;
            actualRefCount = DestructiveGetRefCount(typelessValidation);
            Assert.AreEqual(expectedCount, actualRefCount);
        }
Ejemplo n.º 5
0
        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();
        }
Ejemplo n.º 6
0
        public IEnumerator CanUnloadAssetReference_WithAddressables()
        {
            yield return(Init());

            AsyncOperationHandle handle = m_Addressables.Instantiate(AssetReferenceObjectKey);

            yield return(handle);

            Assert.IsNotNull(handle.Result as GameObject);
            AssetReferenceTestBehavior behavior =
                (handle.Result as GameObject).GetComponent <AssetReferenceTestBehavior>();
            AsyncOperationHandle <GameObject> assetRefHandle = m_Addressables.Instantiate(behavior.Reference);

            yield return(assetRefHandle);

            Assert.IsNotNull(assetRefHandle.Result);

            string name = assetRefHandle.Result.name;

            Assert.IsNotNull(GameObject.Find(name));

            m_Addressables.ReleaseInstance(assetRefHandle.Result);
            yield return(null);

            Assert.IsNull(GameObject.Find(name));

            handle.Release();
        }
        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 IEnumerator AddressablesImpl_DownloadDependenciesAsync_CanDoWithChainKey()
        {
            // Setup
            if (TypeName == "BuildScriptFastMode" || TypeName == "BuildScriptVirtualMode")
            {
                Assert.Ignore($"Skipping test {nameof(AddressablesImpl_DownloadDependenciesAsync_CanDoWithChainKey)} for {TypeName}");
            }

            yield return(Init());

            string label = AddressablesTestUtility.GetPrefabLabel("BASE");

            m_Addressables.hasStartedInitialization = false;
            AsyncOperationHandle op = m_Addressables.DownloadDependenciesAsync(label, false);

            m_Addressables.hasStartedInitialization = true;
            yield return(op);

            // Test
            var wrapOp = op.Convert <IList <IAssetBundleResource> >();

            AssertDownloadDependencyBundlesAreValid(wrapOp);

            // Cleanup
            op.Release();
        }
        public IEnumerator AddressablesImpl_DownloadDependenciesAsync_CanDoWithChainOpHandle()
        {
            // Setup
            yield return(Init());

            if (TypeName == "BuildScriptFastMode" || TypeName == "BuildScriptVirtualMode")
            {
                Assert.Ignore($"Skipping test {nameof(AddressablesImpl_DownloadDependenciesAsync_CanDoWithChainOpHandle)} for {TypeName}");
            }

            IList <IResourceLocation> locations;
            var ret = m_Addressables.GetResourceLocations(new object[] { "prefabs_evenBASE" }, typeof(GameObject), Addressables.MergeMode.Intersection, out locations);

            Assert.IsTrue(ret);
            m_Addressables.hasStartedInitialization = false;
            AsyncOperationHandle op = m_Addressables.DownloadDependenciesAsync(locations, false);

            m_Addressables.hasStartedInitialization = true;
            yield return(op);

            // Test
            var wrapOp = op.Convert <IList <IAssetBundleResource> >();

            AssertDownloadDependencyBundlesAreValid(wrapOp);

            // Cleanup
            op.Release();
        }
        public IEnumerator AddressablesImpl_DownloadDependenciesAsync_CanDownloadDependenciesWithChainFromObjectList()
        {
            // Setup
            yield return(Init());

            if (TypeName == "BuildScriptFastMode" || TypeName == "BuildScriptVirtualMode")
            {
                Assert.Ignore($"Skipping test {nameof(AddressablesImpl_DownloadDependenciesAsync_CanDownloadDependenciesWithChainFromObjectList)} for {TypeName}");
            }

            List <object> deps = new List <object>();

            deps.Add(AddressablesTestUtility.GetPrefabLabel("BASE"));

            m_Addressables.hasStartedInitialization = false;
            AsyncOperationHandle op = m_Addressables.DownloadDependenciesAsync(deps, Addressables.MergeMode.Intersection, false);

            yield return(op);

            m_Addressables.hasStartedInitialization = true;

            // Test
            var wrapOp = op.Convert <IList <IAssetBundleResource> >();

            AssertDownloadDependencyBundlesAreValid(wrapOp);

            // Cleanup
            op.Release();
        }
        public void WhenUWRIsUsed_CompletesSynchronously()
        {
            AsyncOperationHandle <GameObject> h = m_Addressables.LoadAssetAsync <GameObject>(GetForceUWRAddrName(0));

            h.WaitForCompletion();
            h.Release();
        }
Ejemplo n.º 12
0
        public IEnumerator CanGetResourceLocationsWithSingleKey()
        {
            yield return(Init());

            int loadCount   = 0;
            int loadedCount = 0;
            var ops         = new List <AsyncOperationHandle <IList <IResourceLocation> > >();

            foreach (var k in m_KeysHashSet)
            {
                loadCount++;
                AsyncOperationHandle <IList <IResourceLocation> > op = m_Addressables.LoadResourceLocations(k.Key);
                ops.Add(op);
                op.Completed += op2 =>
                {
                    loadedCount++;
                    Assert.IsNotNull(op2.Result);
                    Assert.AreEqual(k.Value, op2.Result.Count);
                };
            }
            foreach (var op in ops)
            {
                yield return(op);

                op.Release();
            }
        }
Ejemplo n.º 13
0
 private void UnloadSceneCompleted(AsyncOperation obj)
 {
     if (m_sceneLoadHandle.IsValid())
     {
         m_sceneLoadHandle.Release();
     }
     Complete(m_Instance, true, "");
 }
Ejemplo n.º 14
0
 protected void ReleaseOp(AsyncOperationHandle handle)
 {
     if (handle.IsValid())
     {
         handle.Release();
     }
     Assert.IsFalse(handle.IsValid());
 }
        public IEnumerator WhenAssetBundleIsLocal_AndForceUWRIsDisabled_UWRIsNotUsed()
        {
            AsyncOperationHandle <GameObject> h = m_Addressables.LoadAssetAsync <GameObject>("testprefab");

            Assert.AreEqual(0, WebRequestQueue.s_ActiveRequests.Count);
            yield return(h);

            h.Release();
        }
        public IEnumerator WhenAssetBundleIsLocal_AndForceUWRIsEnabled_UWRIsUsed()
        {
            AsyncOperationHandle <GameObject> h = m_Addressables.LoadAssetAsync <GameObject>(GetForceUWRAddrName(0));

            Assert.AreEqual(1, WebRequestQueue.s_ActiveRequests.Count);
            yield return(h);

            h.Release();
        }
Ejemplo n.º 17
0
 protected override void Destroy()
 {
     //the scene will be unloaded via the UnloadSceneOp as it waits correctlyf or the unload to complete before releasing the load op
     if (m_DepOp.IsValid())
     {
         m_DepOp.Release();
     }
     base.Destroy();
 }
 protected override void Destroy()
 {
     SceneManager.UnloadSceneAsync(Result.Scene);
     if (m_DepOp.IsValid())
     {
         m_DepOp.Release();
     }
     base.Destroy();
 }
Ejemplo n.º 19
0
        public IEnumerator CanProvideMultipleResources()
        {
            AsyncOperationHandle <IList <GameObject> > op = m_ResourceManager.ProvideResources <GameObject>(m_Locations);

            yield return(op);

            Assert.AreEqual(op.Result.Count, m_Locations.Count);
            op.Release();
        }
        public void AsyncOperationHandle_ConvertToTyped_WithInvalidOpThrows()
        {
            var op = new FakeTypedOperation();
            AsyncOperationHandle handle  = new AsyncOperationHandle(op);
            AsyncOperationHandle handle2 = new AsyncOperationHandle(op);

            handle2.Release();

            Assert.Throws <Exception>(() => { handle.Convert <GameObject>(); });
        }
 protected override void Execute()
 {
     if (m_sceneLoadHandle.IsValid())
     {
         m_sceneLoadHandle.Release();
     }
     else
     {
         Complete(m_Instance, true, "");
     }
 }
Ejemplo n.º 22
0
        public IEnumerator DownloadDependnecies_CanDownloadDependencies()
        {
            yield return(Init());

            string label            = AddressablesTestUtility.GetPrefabLabel("BASE");
            AsyncOperationHandle op = m_Addressables.DownloadDependencies(label);

            yield return(op);

            op.Release();
        }
Ejemplo n.º 23
0
        public IEnumerator LoadAsset_WhenEntryDoesNotExist_OperationFails()
        {
            yield return(Init());

            AsyncOperationHandle <GameObject> op = m_Addressables.LoadAsset <GameObject>("unknownlabel");

            yield return(op);

            Assert.AreEqual(AsyncOperationStatus.Failed, op.Status);
            Assert.IsTrue(op.Result == null);
            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 ProvideResource_ReceiveDiagnosticsCallback_CreateAndComplete()
        {
            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();

            bool created   = false;
            bool completed = false;

            for (int i = 0; i < eventsRecieved.Count; ++i)
            {
                if (eventsRecieved[i].Type == ResourceManager.DiagnosticEventType.AsyncOperationCreate)
                {
                    Assert.NotNull(eventsRecieved[i].Location);
                    Assert.IsTrue(eventsRecieved[i].Location.InternalId == "1");
                    Assert.IsFalse(completed);
                    Assert.IsFalse(created);
                    created = true;
                }
                else if (eventsRecieved[i].Type == ResourceManager.DiagnosticEventType.AsyncOperationComplete)
                {
                    Assert.NotNull(eventsRecieved[i].Location);
                    Assert.True(eventsRecieved[i].Location.InternalId == "1");
                    Assert.IsFalse(completed);
                    Assert.IsTrue(created);
                    completed = true;
                }
                else if (eventsRecieved[i].Type == ResourceManager.DiagnosticEventType.AsyncOperationDestroy)
                {
                    Assert.NotNull(eventsRecieved[i].Location);
                    Assert.True(eventsRecieved[i].Location.InternalId == "1");
                    Assert.IsTrue(completed);
                    Assert.IsTrue(created);
                }
            }

            op.Release();
        }
        public IEnumerator GetResourceLocationsWithCorrectKeyAndWrongTypeReturnsEmptyResult()
        {
            yield return(Init());

            AsyncOperationHandle <IList <IResourceLocation> > op = m_Addressables.LoadResourceLocationsAsync("prefabs_evenBASE", typeof(Texture2D));

            yield return(op);

            Assert.AreEqual(AsyncOperationStatus.Succeeded, op.Status);
            Assert.IsNotNull(op.Result);
            Assert.AreEqual(op.Result.Count, 0);
            op.Release();
        }
        public IEnumerator LoadAssetWithWrongType_WhenEntryExists_Fails()
        {
            yield return(Init());

            string label = AddressablesTestUtility.GetPrefabUniqueLabel("BASE", 0);
            AsyncOperationHandle <Texture> op = m_Addressables.LoadAssetAsync <Texture>(label);

            yield return(op);

            Assert.AreEqual(AsyncOperationStatus.Failed, op.Status);
            Assert.IsNull(op.Result);
            op.Release();
        }
Ejemplo n.º 28
0
        public IEnumerator LoadAsset_WhenEntryExists_ReturnsAsset()
        {
            yield return(Init());

            string label = AddressablesTestUtility.GetPrefabUniqueLabel("BASE", 0);
            AsyncOperationHandle <GameObject> op = m_Addressables.LoadAsset <GameObject>(label);

            yield return(op);

            Assert.AreEqual(AsyncOperationStatus.Succeeded, op.Status);
            Assert.IsTrue(op.Result != null);
            op.Release();
        }
        public IEnumerator LoadAsset_InvalidKeyThrowsInvalidKeyException()
        {
            //Setup
            yield return(Init());

            //Test
            AsyncOperationHandle handle = default(AsyncOperationHandle);

            handle = m_Addressables.LoadAssetAsync <GameObject>("noSuchLabel");
            Assert.AreEqual("Exception of type 'UnityEngine.AddressableAssets.InvalidKeyException' was thrown., Key=noSuchLabel", handle.OperationException.Message);
            yield return(handle);

            //Cleanup
            handle.Release();
        }
        public void ProvideResource_WhenDependencyFailsToLoad_AndProviderCanLoadWithFailedDependencies_ProviderStillProvides()
        {
            m_Provider._BehaviourFlags = ProviderBehaviourFlags.CanProvideWithFailedDependencies;
            m_Provider.ProvideCallback = (pi) =>
            {
                pi.Complete(5, true, null);
            };
            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.Succeeded, op.Status);
            Assert.AreEqual(5, op.Result);
            op.Release();
        }