예제 #1
0
        public IEnumerator FailCorrectlyWhenGivenWrongURL()
        {
            var keeper = new AssetPromiseKeeper_GLTF();

            //NOTE(Brian): Expect the 404 error
            LogAssert.Expect(LogType.Error, new Regex("^*.?404"));

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

            AssetPromise_GLTF prom  = new AssetPromise_GLTF(scene.contentProvider, url);
            Asset_GLTF        asset = null;
            bool failEventCalled1   = false;

            prom.OnSuccessEvent += (x) => { asset = x; };
            prom.OnFailEvent    += (x) => { failEventCalled1 = true; };

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

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

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

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

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

            Assert.AreEqual(3, keeper.waitingPromisesCount);

            yield return(prom);

            yield return(prom2);

            yield return(prom3);

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

            Assert.IsTrue(failEventCalled1);
            Assert.IsTrue(failEventCalled2);
            Assert.IsTrue(failEventCalled3);

            Assert.IsFalse(asset != null);
            Assert.IsFalse(asset2 != null);
            Assert.IsFalse(asset3 != null);

            Assert.IsFalse(keeper.library.Contains(asset));
            Assert.AreNotEqual(1, keeper.library.masterAssets.Count);
        }
예제 #2
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);
        }
예제 #3
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();
        }
예제 #4
0
    void Generate(string url)
    {
        AssetPromise_GLTF promise = new AssetPromise_GLTF(provider, url);

        Vector3 pos = Vector3.zero;

        pos.x = Random.Range(-10, 10);
        pos.z = Random.Range(-10, 10);
        promise.settings.initialLocalPosition = pos;

        keeper.Keep(promise);
        promiseList.Add(promise);
    }
예제 #5
0
        public IEnumerator ForceNewInstanceIsOff()
        {
            var keeper = new AssetPromiseKeeper_GLTF();

            string            url  = Utils.GetTestsAssetsPath() + "/GLB/Lantern/Lantern.glb";
            AssetPromise_GLTF prom = new AssetPromise_GLTF(scene.contentProvider, url);

            prom.settings.forceNewInstance = false;
            keeper.Keep(prom);
            yield return(prom);

            var poolableObjectComponent = PoolManager.i.GetPoolable(prom.asset.container);

            Assert.IsNotNull(poolableObjectComponent);
        }
예제 #6
0
        public IEnumerator BeSetupCorrectlyAfterLoad()
        {
            var keeper = new AssetPromiseKeeper_GLTF();

            string            url         = Utils.GetTestsAssetsPath() + "/GLB/Lantern/Lantern.glb";
            AssetPromise_GLTF prom        = new AssetPromise_GLTF(scene.contentProvider, url);
            Asset_GLTF        loadedAsset = null;


            prom.OnSuccessEvent +=
                (x) =>
            {
                loadedAsset = x;
            }
            ;

            Vector3    initialPos   = Vector3.one;
            Quaternion initialRot   = Quaternion.LookRotation(Vector3.right, Vector3.up);
            Vector3    initialScale = Vector3.one * 2;

            prom.settings.initialLocalPosition = initialPos;
            prom.settings.initialLocalRotation = initialRot;
            prom.settings.initialLocalScale    = initialScale;

            keeper.Keep(prom);

            yield return(prom);

            Assert.IsTrue(PoolManager.i.ContainsPool(loadedAsset.id), "Not in pool after loaded!");

            Pool pool = PoolManager.i.GetPool(loadedAsset.id);

            Assert.AreEqual(0, pool.unusedObjectsCount, "incorrect inactive objects in pool");
            Assert.AreEqual(1, pool.usedObjectsCount, "incorrect active objects in pool");
            Assert.IsTrue(pool.original != loadedAsset.container, "In pool, the original gameObject must NOT be the loaded asset!");

            //NOTE(Brian): If the following asserts fail, check that ApplySettings_LoadStart() is called from AssetPromise_GLTF.AddToLibrary() when the clone is made.
            Assert.AreEqual(initialPos.ToString(), loadedAsset.container.transform.localPosition.ToString(), "initial position not set correctly!");
            Assert.AreEqual(initialRot.ToString(), loadedAsset.container.transform.localRotation.ToString(), "initial rotation not set correctly!");
            Assert.AreEqual(initialScale.ToString(), loadedAsset.container.transform.localScale.ToString(), "initial scale not set correctly!");

            Assert.IsTrue(loadedAsset != null);
            Assert.IsTrue(keeper.library.Contains(loadedAsset));
            Assert.AreEqual(1, keeper.library.masterAssets.Count);
        }
예제 #7
0
        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));
        }
예제 #8
0
        public IEnumerator ForceNewInstanceIsOn()
        {
            var keeper = new AssetPromiseKeeper_GLTF();

            string            url  = TestAssetsUtils.GetPath() + "/GLB/Lantern/Lantern.glb";
            AssetPromise_GLTF prom = new AssetPromise_GLTF(scene.contentProvider, url);

            prom.settings.forceNewInstance = true;

            keeper.Keep(prom);
            yield return(prom);

            var poolableObjectComponent = PoolManager.i.GetPoolable(prom.asset.container);

            Assert.IsNull(poolableObjectComponent);

            if (prom.asset.container != null)
            {
                Object.Destroy(prom.asset.container);
            }

            keeper.Cleanup();
        }