public IEnumerator Use_OverMaximumNumber_InvalidOperationException() { var pool = new AddressablesPool(TestStrings.TestPrefabAddress); var referenceCounter = new ReferenceCounter(TestStrings.TestPrefabPath); yield return(pool.WarmupAsync(1).AsIEnumerator()); Assert.That(referenceCounter.ReferenceCount, Is.EqualTo(1)); pool.Use(); Assert.Throws <InvalidOperationException>(() => { pool.Use(); }); pool.Dispose(); Assert.That(referenceCounter.ReferenceCount, Is.EqualTo(0)); }
public IEnumerator BindTo_BindToGameObject() { var gameObject = new GameObject(); var referenceCounter = new ReferenceCounter(TestStrings.TestPrefabPath); var handle = Addressables.LoadAssetAsync <GameObject>(TestStrings.TestPrefabAddress).BindTo(gameObject); yield return(handle); Assert.That(referenceCounter.ReferenceCount, Is.EqualTo(1)); Object.Destroy(gameObject); yield return(null); Assert.That(referenceCounter.ReferenceCount, Is.Zero); }
public IEnumerator Use_CanGetInstance() { var pool = new AddressablesPool(TestStrings.TestPrefabAddress); var referenceCounter = new ReferenceCounter(TestStrings.TestPrefabPath); yield return(pool.WarmupAsync(1).AsIEnumerator()); Assert.That(referenceCounter.ReferenceCount, Is.EqualTo(1)); var instance = pool.Use().Object; Assert.That(instance, Is.Not.Null); pool.Dispose(); Assert.That(referenceCounter.ReferenceCount, Is.EqualTo(0)); }
public IEnumerator WarmupAsync_ExpandPoolSize() { var pool = new AddressablesPool(TestStrings.TestPrefabAddress); var referenceCounter = new ReferenceCounter(TestStrings.TestPrefabPath); yield return(pool.WarmupAsync(3).AsIEnumerator()); Assert.That(referenceCounter.ReferenceCount, Is.EqualTo(3)); yield return(pool.WarmupAsync(5).AsIEnumerator()); Assert.That(referenceCounter.ReferenceCount, Is.EqualTo(5)); pool.Dispose(); Assert.That(referenceCounter.ReferenceCount, Is.EqualTo(0)); }
public IEnumerator Use_InstanceIsUnderParent() { var pool = new AddressablesPool(TestStrings.TestPrefabAddress); var referenceCounter = new ReferenceCounter(TestStrings.TestPrefabPath); yield return(pool.WarmupAsync(1).AsIEnumerator()); Assert.That(referenceCounter.ReferenceCount, Is.EqualTo(1)); var instance = pool.Use().Object; Assert.That(instance.transform.parent.gameObject, Is.EqualTo(pool.PoolGameObject)); pool.Dispose(); Assert.That(referenceCounter.ReferenceCount, Is.EqualTo(0)); }
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 DisposeOperation_ObjectReturnsToPool() { var pool = new AddressablesPool(TestStrings.TestPrefabAddress); var referenceCounter = new ReferenceCounter(TestStrings.TestPrefabPath); yield return(pool.WarmupAsync(1).AsIEnumerator()); Assert.That(referenceCounter.ReferenceCount, Is.EqualTo(1)); var operation = pool.Use(); var instance = operation.Object; var tempObj = new GameObject(); instance.transform.SetParent(tempObj.transform); operation.Dispose(); Assert.That(instance.transform.parent.gameObject, Is.EqualTo(pool.PoolGameObject)); pool.Dispose(); 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 DisposeOperation_CanReuse() { var pool = new AddressablesPool(TestStrings.TestPrefabAddress); var referenceCounter = new ReferenceCounter(TestStrings.TestPrefabPath); yield return(pool.WarmupAsync(1).AsIEnumerator()); Assert.That(referenceCounter.ReferenceCount, Is.EqualTo(1)); var operation1 = pool.Use(); var instance1 = operation1.Object; operation1.Dispose(); var operation2 = pool.Use(); var instance2 = operation2.Object; operation2.Dispose(); Assert.That(instance1, Is.EqualTo(instance2)); pool.Dispose(); 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)); }