protected override void OnUpdate()
        {
            //BlobAssetStore.TryGet(new Unity.Entities.Hash128(VA_AnimationLibraryUtils.AnimationLibraryAssetStoreName), out BlobAssetReference<VA_AnimationLibraryData> animLib);
            // Static because of multi scene setup.
            BlobAssetReference <VA_AnimationLibraryData> animLib = VA_AnimationLibraryConversionSystem.animLibAssetRef;

            Entities.ForEach((VA_AnimatorComponentAuthoring animator) =>
            {
                Entity entity = GetPrimaryEntity(animator);

                // Add animator to 'parent'.
                VA_AnimatorComponent animatorComponent = new VA_AnimatorComponent
                {
                    animationIndex     = 0,
                    animationIndexNext = -1,
                    animationTime      = 0,
                    animationLibrary   = animLib
                };
                DstEntityManager.AddComponentData(entity, animatorComponent);

                // Add the Material data to the children.
                var children = animator.GetComponentsInChildren <MeshRenderer>();
                for (int i = 0; i < children.Length; i++)
                {
                    Entity ent = GetPrimaryEntity(children[i]);

                    VA_AnimationDataComponent animationData = new VA_AnimationDataComponent();
                    DstEntityManager.AddComponentData(ent, animationData);
                }
            });
        }
示例#2
0
		protected override void OnUpdate()
		{
			var animationData = GetComponentDataFromEntity<VA_AnimationDataComponent>(false);

			Entities.ForEach((ref VA_AnimatorComponent ac, in DynamicBuffer<Child> children) =>
			{
				for (int i = 0; i < children.Length; i++)
				{
					// Get child.
					Entity child = children[i].Value;

					// Get the animation lib data.
					ref VA_AnimationLibraryData animationsRef = ref ac.animationLibrary.Value;

					// Lerp animations.
					// Set animation for lerp.
					int animationIndexNext = ac.animationIndexNext;
					if (ac.animationIndexNext < 0)
					{
						animationIndexNext = ac.animationIndex;
					}

					// Calculate next frame time for lerp.
					float animationTimeNext = ac.animationTime + (1.0f / animationsRef.animations[animationIndexNext].maxFrames);
					if (animationTimeNext > animationsRef.animations[animationIndexNext].duration)
					{
						// Set time. Using the difference to smooth out animations when looping.
						animationTimeNext -= ac.animationTime;
					}

					// Set material data.
					animationData[child] = new VA_AnimationDataComponent
					{
						Value = new float4
						{
							x = ac.animationTime,
							y = VA_AnimationLibraryUtils.GetAnimationMapIndex(ref animationsRef, ac.animationIndex),
							z = animationTimeNext,
							w = VA_AnimationLibraryUtils.GetAnimationMapIndex(ref animationsRef, animationIndexNext)
						}
					};
				}
			})