Beispiel #1
0
        public IEnumerator NotTryToLoadAfterForget()
        {
            var keeper = new AssetPromiseKeeper_GLTF();

            var  promises          = new List <AssetPromise_GLTF>();
            var  forgottenPromises = new Dictionary <int, bool>();
            bool waitMasterPromise = true;

            string url = TestAssetsUtils.GetPath() + "/GLB/Trunk/Trunk.glb";

            AssetPromise_GLTF masterPromise = new AssetPromise_GLTF(scene.contentProvider, url);

            masterPromise.OnPreFinishEvent += promise => waitMasterPromise = false;
            keeper.Keep(masterPromise);

            for (int i = 0; i < 10; i++)
            {
                AssetPromise_GLTF prom = new AssetPromise_GLTF(scene.contentProvider, url);

                promises.Add(prom);

                int promiseHash = prom.GetHashCode();
                forgottenPromises.Add(promiseHash, false);

                prom.OnSuccessEvent += (asset) =>
                {
                    Assert.IsFalse(forgottenPromises[promiseHash], "Success on forgotten promise shouldn't be called");
                };
                prom.OnFailEvent += (asset) =>
                {
                    Assert.IsFalse(forgottenPromises[promiseHash], "Fail on forgotten promise shouldn't be called");
                };
                keeper.Keep(prom);
            }

            keeper.Forget(masterPromise);

            yield return(new WaitWhile(() => waitMasterPromise));

            yield return(null);

            for (int i = 0; i < promises.Count; i++)
            {
                var prom = promises[i];
                forgottenPromises[prom.GetHashCode()] = true;
                keeper.Forget(prom);
            }

            keeper.Cleanup();
        }
Beispiel #2
0
    void Update()
    {
        if (Input.GetKeyUp(KeyCode.Z))
        {
            counter++;
            counter %= 3;
            switch (counter)
            {
            case 0:
                string url = TestAssetsUtils.GetPath() + "/GLB/TrunkSeparatedTextures/Trunk.glb";
                Generate(url);
                break;

            case 1:
                string url2 = TestAssetsUtils.GetPath() + "/GLB/Lantern/Lantern.glb";
                Generate(url2);
                break;

            case 2:
                string url3 = TestAssetsUtils.GetPath() + "/GLB/DamagedHelmet/DamagedHelmet.glb";
                Generate(url3);
                break;
            }
        }
        else if (Input.GetKeyUp(KeyCode.X))
        {
            if (promiseList.Count > 0)
            {
                var promiseToRemove = promiseList[Random.Range(0, promiseList.Count)];
                keeper.Forget(promiseToRemove);
                promiseList.Remove(promiseToRemove);
            }
        }
    }
Beispiel #3
0
        public IEnumerator SucceedWhenMastersParentIsDestroyed()
        {
            var keeper = new AssetPromiseKeeper_GLTF();

            string     url    = TestAssetsUtils.GetPath() + "/GLB/Lantern/Lantern.glb";
            GameObject parent = new GameObject("parent");

            AssetPromise_GLTF prom = new AssetPromise_GLTF(scene.contentProvider, url);

            prom.settings.parent = parent.transform;

            AssetPromise_GLTF prom2 = new AssetPromise_GLTF(scene.contentProvider, url);
            bool failEventCalled2   = false;

            prom2.OnFailEvent += (x) => { failEventCalled2 = true; };

            AssetPromise_GLTF prom3 = new AssetPromise_GLTF(scene.contentProvider, url);
            bool failEventCalled3   = false;

            prom3.OnFailEvent += (x) => { failEventCalled3 = true; };

            keeper.Keep(prom);
            keeper.Keep(prom2);
            keeper.Keep(prom3);

            keeper.Forget(prom);

            Assert.AreEqual(3, keeper.waitingPromisesCount);

            Object.Destroy(parent);

            yield return(prom);

            yield return(prom2);

            yield return(prom3);

            Assert.AreEqual(AssetPromiseState.FINISHED, prom.state);
            Assert.AreEqual(AssetPromiseState.FINISHED, prom2.state);
            Assert.AreEqual(AssetPromiseState.FINISHED, prom3.state);

            Assert.IsFalse(failEventCalled2);
            Assert.IsFalse(failEventCalled3);

            Assert.IsTrue(prom.asset != null);
            Assert.IsTrue(prom2.asset != null);
            Assert.IsTrue(prom3.asset != null);

            Assert.IsTrue(keeper.library.Contains(prom.asset));
            Assert.AreEqual(1, keeper.library.masterAssets.Count);
        }
        public IEnumerator ForceNewInstanceIsOffMultipleTimes()
        {
            var keeper = new AssetPromiseKeeper_GLTF();

            var poolableComponents = new List <PoolableObject>();

            string url = Utils.GetTestsAssetsPath() + "/GLB/Lantern/Lantern.glb";

            for (int i = 0; i < 10; i++)
            {
                AssetPromise_GLTF prom = new AssetPromise_GLTF(scene.contentProvider, url);
                prom.settings.forceNewInstance = false;
                keeper.Keep(prom);
                yield return(prom);

                poolableComponents.Add(PoolManager.i.GetPoolable(prom.asset.container));
                keeper.Forget(prom);
            }

            Assert.IsTrue(poolableComponents.TrueForAll(x => x != null));
        }