예제 #1
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();
        }
예제 #2
0
        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);
        }