Godot 遊戲引擎指南/底部面板
外觀
底部面板 是螢幕底部的一個按鈕,單擊時會顯示一個碼頭。例如 Output、Debugger 和 Audio。
首先,要建立一個底部面板,您需要為它製作一個 UI
- 建立一個場景並選擇
User Interface,並將根節點 Control 重新命名為bottom_panel。 - 將其儲存到您的外掛資料夾中,與外掛指令碼位於同一位置,名稱為“bottom_panel.tscn”。
- 選擇您的 Control,按螢幕頂部的
Layout,然後從出現的下拉選單中按Full Rect。 - 在 Control 仍然選擇的情況下,在 Inspector 中展開
Rect並將min_size.y更改為 50(或更大的值)以確保您的 UI 出現時具有非零大小。 - 將一個 VBoxContainer 新增為底部面板的子節點。將其佈局設定為
Full Rect。 - 新增一個 Label,併為其提供適合 UI 功能的文字。
- 將一個 Panel 新增為 VBoxContainer 的子節點。
- 確保選中 Panel,然後轉到 Inspector 上的
Size Flags,併為水平和垂直方向都選中expand。 - 將主 UI 建立為 VBoxContainer 的子節點。
如果您還想在頂部新增按鈕,則可能希望將頂部的 Label 放入一個 HBoxContainer(位於 VBoxContainer 中)。
您可能還想使用比遊戲更多容器。您可能經常希望拉伸或縮小底部面板,使其比預設的小尺寸更大或更小。將 min_size.x 設定為 200-250 也會阻止您將其縮小太多,並在面板開啟時使主螢幕不可見。
現在,開啟您的外掛的主指令碼,並鍵入以下程式碼
expands Control var bp: Control var bp_button: ToolButton func _enter_tree(): # Put any load logic here, including adding new project settings bp = preload("bottom_panel.tscn").instance() bp_button = add_control_to_bottom_panel(bp, "Dock name") func _exit_tree(): # Put exit tree logic here, including any saving remove_control_from_bottom_panel(bp) bp.queue_free()
您也可以在需要時透過使用 bp_button 來隱藏或顯示按鈕。
