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

47 lines
1.5 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class_name SpawnHookComponet extends ComponentBase
##SpawnHookComponent必须绑定一个相关的RayCast2D用来控制射线想要检测的位置。
@export var binded_hook_ray_cast_2d : RayCast2D
##可以通過在這裏添加一個ComponentOwner默認的字段名來讀取輸入方向默認是為空的。
@export var binded_hook_move_input_property_name: StringName
##用於Grapping Hook的基本Instance
const GRAPPING_HOOK = preload("uid://ddwoxlqluxiq5")
##當前的Graphook的實例
var _current_grap_hook_inst: Hook
##钩爪伸长达到动画位置
signal hook_reach_finished(reach_limit: float, anchor: Node2D)
##生成一个Grap Hook
func spawn_grap_hook_inst(dir: Vector2) -> Hook:
var i = GRAPPING_HOOK.instantiate() as Hook
i.init(self,true)
get_tree().current_scene.add_child(i)
i.start_stretching(dir)
_current_grap_hook_inst = i
i.stretching_finished.connect(_on_hook_stretching_end)
return _current_grap_hook_inst
func release_cached_hook() -> void:
_current_grap_hook_inst.release_hook()
##尝试关闭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
##初始化組件
func _init_component() -> void:
pass