protected override void OnUpdate()
        {
            var dt            = Time.DeltaTime;
            var commandBuffer = m_ECBSystem.CreateCommandBuffer().AsParallelWriter();

            Dependency =
                Entities
                .WithBurst(FloatMode.Fast)
                .WithAll <UpdateAnimationTimeTag>()
                .ForEach(
                    (Entity entity, int entityInQueryIndex, ref TinyAnimationTime time, ref TinyAnimationPlaybackInfo info) =>
            {
                switch (info.WrapMode)
                {
                case WrapMode.Once:
                    {
                        time.Value += dt;
                        if (time.Value >= info.Duration)
                        {
                            commandBuffer.RemoveComponent <UpdateAnimationTimeTag>(entityInQueryIndex, entity);
                            commandBuffer.RemoveComponent <ApplyAnimationResultTag>(entityInQueryIndex, entity);
                            time.Value            = 0.0f;
                            time.InternalWorkTime = 0.0f;
                        }
                        break;
                    }

                case WrapMode.ClampForever:
                    {
                        time.Value = math.min(time.Value + dt, info.Duration);
                        break;
                    }

                case WrapMode.Loop:
                    {
                        time.Value = AnimationMath.Repeat(time.Value + dt, info.Duration);
                        break;
                    }

                case WrapMode.PingPong:
                    {
                        time.InternalWorkTime = AnimationMath.Repeat(time.InternalWorkTime + dt, info.Duration * 2.0f);
                        time.Value            = AnimationMath.PingPong(time.InternalWorkTime, info.Duration);
                        break;
                    }
                }
            })
                .Schedule(Dependency);

            m_ECBSystem.AddJobHandleForProducer(Dependency);
        }
Esempio n. 2
0
        public static void SetTime(World world, Entity entity, float newTime)
        {
            AssertEntityIsValidAnimationPlayer(world, entity);

            var currentClip = world.EntityManager.GetComponentData <TinyAnimationPlayer>(entity).CurrentClip;
            var info        = world.EntityManager.GetComponentData <TinyAnimationPlaybackInfo>(currentClip);

            if (newTime < 0.0f)
            {
                newTime = 0.0f;
            }
            else if (newTime > info.Duration)
            {
                switch (info.WrapMode)
                {
                case WrapMode.Once:
                {
                    newTime = 0.0f;
                    break;
                }

                case WrapMode.ClampForever:
                {
                    newTime = info.Duration;
                    break;
                }

                case WrapMode.Loop:
                {
                    newTime = AnimationMath.Repeat(newTime, info.Duration);
                    break;
                }

                case WrapMode.PingPong:
                {
                    newTime = AnimationMath.PingPong(newTime, info.Duration);
                    break;
                }
                }
            }

            world.EntityManager.SetComponentData(currentClip, new TinyAnimationTime {
                Value = newTime, InternalWorkTime = newTime
            });
        }