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);
        }
示例#2
0
        public void WhenProviderImplementsIReceiverUpdate_UpdateIsCalledWhileInProviderList()
        {
            MockProvider provider = new MockProvider();

            m_ResourceManager.ResourceProviders.Add(provider);
            m_ResourceManager.Update(0.0f);
            Assert.AreEqual(1, provider.UpdateCount);

            // Update isn't called after removing provider
            m_ResourceManager.ResourceProviders.Remove(provider);
            m_ResourceManager.Update(0.0f);
            Assert.AreEqual(1, provider.UpdateCount);
        }
        public void Setup()
        {
            m_RM = new ResourceManager();
            m_RM.CallbackHooksEnabled = false;

            m_Provider = new MockProvider();
            m_Provider.ProvideCallback = ProvideBasicCallback;
            m_Provider2                 = new MockProvider();
            m_Provider2._ProviderId     = "MockId2";
            m_Provider2.ProvideCallback = ProvideBasicCallback;

            m_RM.ResourceProviders.Add(m_Provider);
            m_RM.ResourceProviders.Add(m_Provider2);
        }
        public IEnumerator WhenResourceManagerCallbackHooksAreEnabled_ResourceManagerUpdatesProvidersAndCleansUp()
        {
            int          beforeGOCount = GameObject.FindObjectsOfType <MonoBehaviourCallbackHooks>().Length;
            MockProvider provider      = new MockProvider();

            m_ResourceManager.CallbackHooksEnabled = true;
            m_ResourceManager.ResourceProviders.Add(provider);
            yield return(null);

            Assert.AreEqual(1, provider.UpdateCount);
            Assert.AreEqual(beforeGOCount + 1, GameObject.FindObjectsOfType <MonoBehaviourCallbackHooks>().Length);
            m_ResourceManager.Dispose();
            yield return(null);

            Assert.AreEqual(beforeGOCount, GameObject.FindObjectsOfType <MonoBehaviourCallbackHooks>().Length);
        }