godot-plateformer/addons/reedcomponent/grap_hook/spawn_hook_component.gd

53 lines
1.6 KiB
GDScript3
Raw Normal View History

2025-12-29 11:54:31 +08:00
class_name SpawnHookComponet extends ComponentBase
##可以通過在這裏添加一個ComponentOwner默認的字段名來讀取輸入方向默認是為空的。
@export var binded_hook_move_input_property_name: StringName
##用於Grapping Hook的基本Instance
2025-12-31 13:07:31 +08:00
const GRAPPING_HOOK = preload("uid://ddwoxlqluxiq5")
2025-12-29 11:54:31 +08:00
##當前的Graphook的實例
2025-12-31 13:07:31 +08:00
var _current_grap_hook_inst: Hook
2025-12-29 11:54:31 +08:00
##钩爪伸长达到动画位置
2025-12-31 13:07:31 +08:00
signal hook_reach_finished(reach_limit: float, anchor: Node2D)
2025-12-29 11:54:31 +08:00
##生成一个Grap Hook
2025-12-31 13:07:31 +08:00
func spawn_grap_hook_inst(dir: Vector2) -> Hook:
2025-12-29 11:54:31 +08:00
2025-12-31 13:07:31 +08:00
var i = GRAPPING_HOOK.instantiate() as Hook
i.init(self,true)
2025-12-29 11:54:31 +08:00
get_tree().current_scene.add_child(i)
2025-12-31 13:07:31 +08:00
i.start_stretching(dir)
2025-12-29 11:54:31 +08:00
_current_grap_hook_inst = i
2025-12-31 13:07:31 +08:00
i.stretching_finished.connect(_on_hook_stretching_end)
return _current_grap_hook_inst
2025-12-29 11:54:31 +08:00
2025-12-31 16:24:11 +08:00
func release_cached_hook() -> void:
2026-01-05 15:28:43 +08:00
if _current_grap_hook_inst:
_current_grap_hook_inst.release_hook()
2025-12-31 16:24:11 +08:00
2026-01-06 23:18:36 +08:00
func get_current_hook_inst() -> Hook:
return _current_grap_hook_inst
2025-12-31 13:07:31 +08:00
##尝试关闭hook的延长
func suspend_hook_stretching(force_suspend: bool = false) -> bool:
if not _current_grap_hook_inst: return false
return _current_grap_hook_inst.end_stretching(force_suspend)
##当Hook stretching 关闭的时候,触发。
func _on_hook_stretching_end(reach_limit,anchor:Node2D) -> void:
hook_reach_finished.emit(reach_limit,anchor)
##从当前的hook获取到hook的anchor
func get_current_hook_anchor() -> Node2D:
return _current_grap_hook_inst._anchor
2026-01-05 15:28:43 +08:00
##是否存在anchor
func has_hook_anchor() -> bool:
return _current_grap_hook_inst and _current_grap_hook_inst._anchor
2025-12-31 16:24:11 +08:00
##初始化組件
2025-12-29 11:54:31 +08:00
func _init_component() -> void:
2025-12-31 13:07:31 +08:00
pass