challenge-editor/class/ButtonOffsetTrigerResource/button_offset_triger_resource.gd
2024-11-27 20:28:51 +08:00

35 lines
732 B
GDScript

extends Resource
#用于保存在button聚焦或按下时使其他关联节点发生偏移的资源类
class_name ButtonOffsetTrigerResource
@export var button:NodePath
@export var offset_arr:Array[NodeOffsetArrayResource]
var root
func open(root:Node):
self.root=root
var btn:BaseButton=root.get_node(self.button)
if not btn is BaseButton:
return
btn.mouse_entered.connect(use_offset)
btn.mouse_exited.connect(del_offset)
pass
func use_offset():
for i in offset_arr:
var node=root.get_node(i.node)
if not node is Control:
continue
node.position+=i.offset
pass
func del_offset():
for i in offset_arr:
var node=root.get_node(i.node)
if not node is Control:
continue
node.position-=i.offset
pass