コード例 #1
0
ファイル: AnimatorTests.cs プロジェクト: yemel/explorer
        public IEnumerator CreateAnimationComponent()
        {
            DecentralandEntity entity = TestHelpers.CreateSceneEntity(scene);

            Assert.IsTrue(entity.gameObject.GetComponentInChildren <UnityGLTF.InstantiatedGLTFObject>() == null,
                          "Since the shape hasn't been updated yet, the 'GLTFScene' child object shouldn't exist");

            TestHelpers.CreateAndSetShape(scene, entity.entityId, DCL.Models.CLASS_ID.GLTF_SHAPE,
                                          JsonConvert.SerializeObject(new
            {
                src = Utils.GetTestsAssetsPath() + "/GLB/CesiumMan/CesiumMan.glb"
            }));

            DCLAnimator.Model animatorModel = new DCLAnimator.Model
            {
                states = new DCLAnimator.Model.DCLAnimationState[]
                {
                    new DCLAnimator.Model.DCLAnimationState
                    {
                        name    = "clip01",
                        clip    = "animation:0",
                        playing = true,
                        weight  = 1,
                        speed   = 1
                    }
                }
            };

            DCLAnimator animator =
                TestHelpers.EntityComponentCreate <DCLAnimator, DCLAnimator.Model>(scene, entity, animatorModel);

            LoadWrapper gltfShape = GLTFShape.GetLoaderForEntity(entity);

            yield return(new WaitUntil(() => gltfShape.alreadyLoaded == true));

            Assert.IsTrue(entity.gameObject.GetComponentInChildren <Animation>() != null,
                          "'GLTFScene' child object with 'Animator' component should exist if the GLTF was loaded correctly.");
            Assert.IsTrue(entity.gameObject.GetComponentInChildren <DCLAnimator>() != null,
                          "'GLTFScene' child object with 'DCLAnimator' component should exist if the GLTF was loaded correctly.");

            yield return(animator.routine);

            animator = entity.gameObject.GetComponentInChildren <DCLAnimator>();

            Assert.IsTrue(animator.GetStateByString("clip01") != null, "dclAnimator.GetStateByString fail!");
            Assert.IsTrue(animator.model.states[0].clip != null, "dclAnimator clipReference is null!");
        }
コード例 #2
0
ファイル: AnimatorTests.cs プロジェクト: yemel/explorer
        public IEnumerator DCLAnimatorResetAnimation()
        {
            GLTFShape gltfShape = TestHelpers.CreateEntityWithGLTFShape(scene, Vector3.zero,
                                                                        new LoadableShape.Model
            {
                src = Utils.GetTestsAssetsPath() + "/GLB/Shark/shark_anim.gltf"
            });
            var entity = gltfShape.attachedEntities.First();

            DCLAnimator.Model animatorModel = new DCLAnimator.Model
            {
                states = new[]
                {
                    new DCLAnimator.Model.DCLAnimationState
                    {
                        name    = "Bite",
                        clip    = "shark_skeleton_bite",
                        playing = true,
                        weight  = 1,
                        speed   = 1
                    },
                    new DCLAnimator.Model.DCLAnimationState
                    {
                        name    = "Swim",
                        clip    = "shark_skeleton_swim",
                        playing = true,
                        weight  = 1,
                        speed   = 1
                    }
                }
            };

            DCLAnimator animator =
                TestHelpers.EntityComponentCreate <DCLAnimator, DCLAnimator.Model>(scene, entity, animatorModel);
            LoadWrapper gltfLoader = GLTFShape.GetLoaderForEntity(entity);

            yield return(new WaitUntil(() => gltfLoader.alreadyLoaded));

            yield return(animator.routine);

            animator.animComponent.cullingType = AnimationCullingType.AlwaysAnimate;

            yield return(new WaitForSeconds(1.5f));

            Animation animation = entity.gameObject.GetComponentInChildren <Animation>();

            foreach (AnimationState animState in animation)
            {
                Assert.AreNotEqual(0f, animState.time);
            }

            animatorModel.states[1].shouldReset = true;

            yield return(TestHelpers.EntityComponentUpdate(animator, animatorModel));

            animator.ResetAnimation(animator.GetStateByString("Swim"));
            foreach (AnimationState animState in animation)
            {
                if (animator.GetStateByString("Swim").clipReference.name == animState.clip.name)
                {
                    Assert.AreEqual(0f, animState.time);
                }
                else
                {
                    Assert.AreNotEqual(0f, animState.time);
                }
            }
        }