function RegisterActiveObject(obj_name, on_click, multi_use, cursor_name)
    if not game_state.active_objects then
        game_state.active_objects = {}
    end
    
    game_state.active_objects[obj_name] = {}
    game_state.active_objects[obj_name].on_click = on_click
    game_state.active_objects[obj_name].multi_use = multi_use
    game_state.active_objects[obj_name].info_highlight = {}
    AddHighlightActiveObject(obj_name)
        
    if cursor_name then
        custom_cursors[obj_name] = cursor_name
    end
    
    local state_value = game_state.scene_path..'('..obj_name..')'
    if HasGameState('ObjectClicked', state_value) then
        if on_click then
            on_click(true)
        end
        
        if game_state.active_objects[obj_name] and game_state.active_objects[obj_name].multi_use == false then
            play_field:IgnoreOnTestPoint(obj_name)
            game_state.active_objects[obj_name] = nil           
        end
    end
end

function UnregisterActiveObject(obj_name)
    game_state.active_objects[obj_name] = nil
    custom_cursors[obj_name] = ''
end

function ClearSaveActiveObject(obj_name)
    local state_value = game_state.scene_path..'('..obj_name..')'
    if HasGameState('ObjectClicked', state_value) then
        RemoveGameState('ObjectClicked', state_value)
    end
end

function AddHighlightActiveObject(obj_name)
    if not game_state.active_objects[obj_name] then
        return
    end

    local object_name_highlight = 'highlight__' .. obj_name
    if play_field:HasObject(object_name_highlight) then
        return
    end
    
    local anim = CreateAnimation('data/Texture/Effect/ObjectHighlight.png',0,0,47,47,1,0)
    anim:SetHotSpot(23.5,23.5)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	local obj_highlight = play_field:CreateObject(object_name_highlight,anim,512,384,140,0,1,1)
    obj_highlight:SetOpacity(0)
    obj_highlight:SetXY(0, 0)
--  obj_highlight:AttachTo( play_field:GetObject(obj_name) )
    play_field:IgnoreOnTestPoint(object_name_highlight)
    
    local obj_tool_target = play_field:GetObject(obj_name)
    local x_obj_tool_target = obj_tool_target:GetX()
    local y_obj_tool_target = obj_tool_target:GetY()
    local z_obj_tool_target = obj_tool_target:GetZ()
    obj_highlight:SetXY(x_obj_tool_target, y_obj_tool_target)
    obj_highlight:SetZ( z_obj_tool_target + 1)
--  obj_highlight:SetZ( 0.1 )
    
    game_state.active_objects[obj_name].info_highlight.link_object          = tool_target
    game_state.active_objects[obj_name].info_highlight.obj_highlight        = obj_highlight
    game_state.active_objects[obj_name].info_highlight.max_highlight_delay  = 100
    game_state.active_objects[obj_name].info_highlight.highlight_delay      = GetRandomFloat(1, 10)
end

function UpdateActiveObject(dt)
    if game_state.active_objects then
        for i, info_active in pairs(game_state.active_objects) do
            -- Check Object
            local active_obj = play_field:GetObject(i)
            if  active_obj and active_obj:IsVisible() and
                active_obj:GetOpacity() > 0
            then
                local info = info_active.info_highlight
                info.highlight_delay = info.highlight_delay - dt
                if info.highlight_delay < 0 then
                    info.highlight_delay = info.max_highlight_delay
                    HighlightActiveObject(info.obj_highlight)
                end -- if info.highlight_delay < 0 then
            end
        end -- for i, info_active in pairs(game_state.active_objects) do
    end
end

function HighlightActiveObject(obj_highlight)
    local effect_time = 0.9
    
    local af = CreateAnimationEffector()
    af:AttachTo( obj_highlight )
    af:SetMode(_ANIM_NOLOOP)
    af:SetKey(_TRACK_O, effect_time * 0.,   0.)
    af:SetKey(_TRACK_A, effect_time * 0.,   0.)
    af:SetKey(_TRACK_S, effect_time * 0.,   0.3)
    af:SetKey(_TRACK_O, effect_time * 0.05, 1.)
    af:SetKey(_TRACK_S, effect_time * 0.25, 1.)
    af:SetKey(_TRACK_O, effect_time * 0.45, 1.)
    af:SetKey(_TRACK_A, effect_time * 0.45, 35. * M_PI / 180.)
    af:SetKey(_TRACK_S, effect_time * 0.45, 1.4)
    af:SetKey(_TRACK_O, effect_time * 0.70, 1.)
    af:SetKey(_TRACK_A, effect_time * 1.,   50. * M_PI / 180.)
    af:SetKey(_TRACK_S, effect_time * 1.,   1.)
    af:SetKey(_TRACK_O, effect_time * 1.,   0.)
    af:Play()
end
