49 lines
1.2 KiB
GDScript
49 lines
1.2 KiB
GDScript
class_name InteractionRay
|
|
extends RayCast3D
|
|
|
|
signal focused_gained(interaction_area: InteractionArea)
|
|
signal focus_lost(interaction_area: InteractionArea)
|
|
|
|
var is_interacting: bool = false
|
|
var focused_area: InteractionArea
|
|
var had_focus: bool = false
|
|
|
|
|
|
func _physics_process(_delta: float) -> void:
|
|
var collider: Object = get_collider()
|
|
|
|
#if is_colliding() and collider is InteractionArea and focused_area != collider:
|
|
#focused_area = collider
|
|
#focused_gained.emit(focused_area)
|
|
#elif not collider is InteractionArea and is_instance_valid(focused_area):
|
|
#focused_area = null
|
|
#focused_gained.emit(null)
|
|
|
|
|
|
if collider == focused_area:
|
|
if not is_instance_valid(focused_area) and had_focus:
|
|
had_focus = false
|
|
focus_lost.emit(null)
|
|
|
|
return
|
|
|
|
if is_instance_valid(focused_area):
|
|
focused_area.set_area_focused(false)
|
|
had_focus = false
|
|
focus_lost.emit(focused_area)
|
|
|
|
focused_area = collider if collider is InteractionArea else null
|
|
focused_gained.emit(focused_area)
|
|
|
|
if is_instance_valid(focused_area):
|
|
had_focus = true
|
|
focused_area.set_area_focused(true)
|
|
|
|
|
|
func get_interaction() -> InteractionArea:
|
|
var collider: Object = get_collider()
|
|
if collider is InteractionArea:
|
|
return collider
|
|
|
|
return null
|