🎬 bounce rect

Простая луа, созданная для тестов анимаций, отлично подойдет, что бы наглядно посмотреть, как работает наш модуль анимаций.

local gizmos = eh_singleton(eh_runtime_gizmos)

local text_style = GUIStyle()
local style_state = GUIStyleState()
style_state.textColor = Color.white
text_style.normal = style_state
text_style.alignment = TextAnchor.MiddleCenter
text_style.fontSize = 15

local animations = {
    {
        name = "Linear",
        y_pos = 100,
        animator = animator_factory.create_linear(300, 0.1, true)
    },
    {
        name = "Ease In",
        y_pos = 200,
        animator = animator_factory.create_ease_in(300, 0.1, true)
    },
    {
        name = "Ease Out",
        y_pos = 300,
        animator = animator_factory.create_ease_out(300, 0.1, true)
    },
    {
        name = "Ease In Out",
        y_pos = 400,
        animator = animator_factory.create_ease_in_out(300, 0.1, true)
    },
    {
        name = "Custom Bounce",
        y_pos = 500,
        context = animator_factory.create_custom(
            function(t: float) : float
                local b = cast(float, 4) 
                return cast(float, math.abs(math.sin(t * b * math.pi)))
            end,
        300, 0.1, true)
    }
}

local cube_size = 30
local start_x = 0

local function draw_cube(x, y, color)
    local rect = Rect(x, y, cube_size, cube_size)
    gizmos.push_image(-1, rect, Texture2D.whiteTexture, color, 0, 1)
end

local function draw_info(name, value, y_pos)
    local text_rect = Rect(10, y_pos - 25, 300, 20)
    local text = string.format("%s, value=%.2f", name, value)
    gizmos.push_text(-2, text_rect, text, Color.white, Color.black, 1, text_outline.shadow, text_style)
end

events.add("OnGUI", function()
    if Event.current.type == EventType.Repaint then
        for i, anim in ipairs(animations) do
            anim.animator:animate(Time.deltaTime)
            
            draw_info(anim.name, anim.animator.value, anim.y_pos)
            
            local cube_x = start_x + value
            local cube_color = Color32(
                i == 1 and 255 or (i == 2 and 200 or 0),
                i == 3 and 255 or (i == 4 and 200 or 0),
                i == 5 and 255 or 0,
                255
            )
            draw_cube(cube_x, anim.y_pos, cube_color)
        end
    end
end)

Last updated