godot 4.0 tool_button
Old Version
ปุ่มแก้ไขด้วย หนึ่งบรรทัดของรหัส: เป็นศูนย์บรรทัดของรหัส@tool
เพียงติดตั้งและเลือกโหนดใด ๆ :
สำหรับคุณสมบัติขั้นสูงเพิ่มเติมอ่านด้านล่าง

@tool ไปด้านบนของสคริปต์ของคุณ_get_tool_buttons() -> Array"my_method"my_methodmethod.bind(true, "ok" 1.0)func(): print("Hey!")func press_me(): print("You pressed me!")"my_signal"my_signal["my_signal", [true, "ok"]]{call=method.bind(true), text="My Method", tint=Color.RED}["my_method", method2.bind(1.0), "a_signal", {text="X", call=reset}] 
ในการระบุปุ่มที่แสดงด้านบนผู้ตรวจสอบให้เพิ่ม _get_tool_buttons func

กับ Strings :
@tool
extends Node
func _get_tool_buttons() :
return [ boost_score, remove_player ]
func boost_score() :
Player.score += 100
func remove_player() :
Player.queue_free() และ/หรือ Callable s
# WARNING, some stuff won't work: If you get *"Cannot access member without instance"*: https://github.com/godotengine/godot/issues/56780
@tool
extends Node
func _get_tool_buttons() :
return [
func add_score() : score += 10 ,
func reset_health() : health = 0
] และ/หรือ Dictionarys
@tool
extends Node
signal reset()
func _get_tool_buttons() : return [
" boost_score " ,
{ call = " boost_score " , args = [ 100 ] , tint = Color.DEEP_SKY_BLUE } ,
{ call = " emit_signal " , args = [ " reset " ] , text = " Reset " , tint = Color.TOMATO } ,
{
call = func() : print( " My Health: " , health),
text = " Print Health " ,
tint = func() : return Color(health * . 1 , 0.0 , 0.0 )
lock = func() : return health == 100
}
]
func boost_score(x = 10 ) :
Player.score += x call เป็นสิ่งจำเป็น อื่น ๆ เป็นทางเลือก
| สำคัญ | แยกออกจากกัน | ค่าเริ่มต้น |
|---|---|---|
| เรียก | วิธีการโทร | - |
| อาร์กอน | อาร์เรย์ของอาร์กิวเมนต์ที่จะผ่าน (ปุ่มเมาส์มากกว่าเพื่อดู args) | - |
| ข้อความ | ป้ายปุ่ม | - |
| สี | สีปุ่ม | สีขาว |
| ไอคอน | ไอคอนปุ่ม | - |
| แบน | ปุ่มเป็นสไตล์แบน | เท็จ |
| คำใบ้ | ข้อความคำใบ้สำหรับเมาส์มากกว่า | - |
| พิมพ์ | พิมพ์เอาต์พุตของวิธีการโทร? | จริง |
| จัดแนว | การจัดตำแหน่งปุ่ม | BoxContainer.Alignment_center |
| ล็อค | ปิดการใช้งานปุ่ม? | เท็จ |
| update_filesystem | บอก Godot Editor ถึงระบบไฟล์ Rescan | เท็จ |
เพื่อให้ _get_tool_buttons ทำงานกับ Resource ที่จำเป็นต้องคงที่
@tool
extends Resource
class_name MyResource
# STATIC
static func _get_tool_buttons() :
return [ " my_button " ]
# LOCAL
export(String) var my_name : String = " "
func my_button() :
print(my_name)signal my_signal()
signal my_arg_signal(x, y)
func _get_tool_buttons() :
return [
my_signal,
[ my_arg_signal, [ true , " okay " ]]
] คุณสามารถมีหลายปุ่มในบรรทัดเดียวกัน
พวกเขาทั้งหมดสามารถถูกเรียกได้ในครั้งเดียว (ค่าเริ่มต้น) หรือแยกตามสลับ
func _get_tool_buttons():
return [
[msg, msg.bind("yes"), msg.bind("no")],
]
func msg(msg := "Default Message"):
print("Got: ", msg)
func doit():
pass
@SELECT_AND_EDIT::file_path , @EDIT_RESOURCE::file_path , @SELECT_FILE::file_path 4.0.alpha2icon text รองรับการ call Callable โทร lock tint { text="Callable", call=func(): print("From Callable with love") }disabled เป็น lock