Beispiel #1
0
        public unsafe void Execute <TCtx>(TCtx ctx, InputTriggerPort port) where TCtx : IGraphInstance
        {
            var entity = ctx.ReadEntity(Entity);

            if (entity == Unity.Entities.Entity.Null)
            {
                return;
            }

            if (!ctx.EntityManager.HasComponent <PhysicsMass>(entity) || !ctx.EntityManager.HasComponent <PhysicsVelocity>(entity))
            {
                return;
            }

            PhysicsMass     physicsMass     = ctx.EntityManager.GetComponentData <PhysicsMass>(entity);
            PhysicsVelocity physicsVelocity = ctx.EntityManager.GetComponentData <PhysicsVelocity>(entity);

            if (LinearOnly)
            {
                physicsVelocity.ApplyLinearImpulse(physicsMass, ctx.ReadFloat3(Value));
            }
            else
            {
                Translation t = ctx.EntityManager.GetComponentData <Translation>(entity);
                Rotation    r = ctx.EntityManager.GetComponentData <Rotation>(entity);

                ComponentExtensions.ApplyImpulse(ref physicsVelocity, physicsMass, t, r, ctx.ReadFloat3(Value), ctx.ReadFloat3(Point));
            }

            ctx.EntityManager.SetComponentData(entity, physicsVelocity);
        }