public IEnumerator Get_Disposed_ObjectDisposedException() { var preloader = new AddressablesPreloader(); var referenceCounter = new ReferenceCounter(TestStrings.TestPrefabPath); yield return(preloader.PreloadAsync(TestStrings.TestPrefabAddress).AsIEnumerator()); Assert.That(referenceCounter.ReferenceCount, Is.EqualTo(1)); preloader.Dispose(); Assert.Throws <ObjectDisposedException>(() => { preloader.Get <GameObject>(TestStrings.TestPrefabAddress); }); // The handle is completely discarded in the next frame so wait a frame. yield return(null); Assert.That(referenceCounter.ReferenceCount, Is.EqualTo(0)); }
public IEnumerator PreloadAsync_CanPreload() { var preloader = new AddressablesPreloader(); var referenceCounter = new ReferenceCounter(TestStrings.TestPrefabPath); yield return(preloader.PreloadAsync(TestStrings.TestPrefabAddress).AsIEnumerator()); Assert.That(referenceCounter.ReferenceCount, Is.EqualTo(1)); var prefab = preloader.Get <GameObject>(TestStrings.TestPrefabAddress); Assert.That(prefab, Is.EqualTo(AssetDatabase.LoadAssetAtPath <GameObject>(TestStrings.TestPrefabPath))); preloader.Dispose(); // The handle is completely discarded in the next frame so wait a frame. yield return(null); Assert.That(referenceCounter.ReferenceCount, Is.EqualTo(0)); }
public IEnumerator Get_NotPreloaded_InvalidOperationException() { var preloader = new AddressablesPreloader(); var referenceCounter = new ReferenceCounter(TestStrings.TestPrefabPath); Assert.Throws <InvalidOperationException>(() => { try { preloader.Get <GameObject>(TestStrings.TestPrefabAddress); } finally { preloader.Dispose(); } }); // The handle is completely discarded in the next frame so wait a frame. yield return(null); Assert.That(referenceCounter.ReferenceCount, Is.EqualTo(0)); }