Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
GraphEdit
繼承: Control < CanvasItem < Node < Object
圖結構編輯器,使用 GraphNode。
說明
GraphEdit provides tools for creation, manipulation, and display of various graphs. Its main purpose in the engine is to power the visual programming systems, such as visual shaders, but it is also available for use in user projects.
GraphEdit by itself is only an empty container, representing an infinite grid where GraphNodes can be placed. Each GraphNode represents a node in the graph, a single unit of data in the connected scheme. GraphEdit, in turn, helps to control various interactions with nodes and between nodes. When the user attempts to connect, disconnect, or delete a GraphNode, a signal is emitted in the GraphEdit, but no action is taken by default. It is the responsibility of the programmer utilizing this control to implement the necessary logic to determine how each request should be handled.
Performance: It is greatly advised to enable low-processor usage mode (see OS.low_processor_usage_mode) when using GraphEdits.
Note: Keep in mind that Node.get_children() will also return the connection layer node named _connection_layer due to technical limitations. This behavior may change in future releases.
屬性
clip_contents |
|
|
|
||
|
||
|
||
|
||
focus_mode |
|
|
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
方法
_get_connection_line(from_position: Vector2, to_position: Vector2) virtual const |
|
_is_in_input_hotzone(in_node: Object, in_port: int, mouse_position: Vector2) virtual |
|
_is_in_output_hotzone(in_node: Object, in_port: int, mouse_position: Vector2) virtual |
|
_is_node_hover_valid(from_node: StringName, from_port: int, to_node: StringName, to_port: int) virtual |
|
void |
add_valid_connection_type(from_type: int, to_type: int) |
void |
|
void |
|
void |
|
void |
attach_graph_element_to_frame(element: StringName, frame: StringName) |
void |
|
connect_node(from_node: StringName, from_port: int, to_node: StringName, to_port: int, keep_alive: bool = false) |
|
void |
detach_graph_element_from_frame(element: StringName) |
void |
disconnect_node(from_node: StringName, from_port: int, to_node: StringName, to_port: int) |
void |
|
get_closest_connection_at_point(point: Vector2, max_distance: float = 4.0) const |
|
get_connection_count(from_node: StringName, from_port: int) |
|
get_connection_line(from_node: Vector2, to_node: Vector2) const |
|
get_connection_list_from_node(node: StringName) const |
|
get_connections_intersecting_with_rect(rect: Rect2) const |
|
get_element_frame(element: StringName) |
|
is_node_connected(from_node: StringName, from_port: int, to_node: StringName, to_port: int) |
|
is_valid_connection_type(from_type: int, to_type: int) const |
|
void |
remove_valid_connection_type(from_type: int, to_type: int) |
void |
|
void |
|
void |
set_connection_activity(from_node: StringName, from_port: int, to_node: StringName, to_port: int, amount: float) |
void |
set_selected(node: Node) |
主題屬性
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
訊號
begin_node_move() 🔗
Emitted at the beginning of a GraphElement's movement.
connection_drag_ended() 🔗
在連接拖動結束時發出。
connection_drag_started(from_node: StringName, from_port: int, is_output: bool) 🔗
在連接拖動開始時發出。
connection_from_empty(to_node: StringName, to_port: int, release_position: Vector2) 🔗
當使用者將連接從輸入埠拖動到圖形的空白區域時發出。
connection_request(from_node: StringName, from_port: int, to_node: StringName, to_port: int) 🔗
當嘗試建立 from_node GraphNode 的 from_port 和 to_node GraphNode 的 to_port 之間的連接時發出。
connection_to_empty(from_node: StringName, from_port: int, release_position: Vector2) 🔗
當使用者將連接從輸出埠拖動到圖形的空白區域時發出。
copy_nodes_request() 🔗
Emitted when this GraphEdit captures a ui_copy action (Ctrl + C by default). In general, this signal indicates that the selected GraphElements should be copied.
cut_nodes_request() 🔗
Emitted when this GraphEdit captures a ui_cut action (Ctrl + X by default). In general, this signal indicates that the selected GraphElements should be cut.
delete_nodes_request(nodes: Array[StringName]) 🔗
Emitted when this GraphEdit captures a ui_graph_delete action (Delete by default).
nodes is an array of node names that should be removed. These usually include all selected nodes.
disconnection_request(from_node: StringName, from_port: int, to_node: StringName, to_port: int) 🔗
當試圖移除 from_node GraphNode 的 from_port 和 to_node GraphNode 的 to_port 之間的連接時發出。
duplicate_nodes_request() 🔗
Emitted when this GraphEdit captures a ui_graph_duplicate action (Ctrl + D by default). In general, this signal indicates that the selected GraphElements should be duplicated.
end_node_move() 🔗
Emitted at the end of a GraphElement's movement.
frame_rect_changed(frame: GraphFrame, new_rect: Rect2) 🔗
Emitted when the GraphFrame frame is resized to new_rect.
graph_elements_linked_to_frame_request(elements: Array, frame: StringName) 🔗
Emitted when one or more GraphElements are dropped onto the GraphFrame named frame, when they were not previously attached to any other one.
elements is an array of GraphElements to be attached.
Emitted when the given GraphElement node is deselected.
Emitted when the given GraphElement node is selected.
paste_nodes_request() 🔗
Emitted when this GraphEdit captures a ui_paste action (Ctrl + V by default). In general, this signal indicates that previously copied GraphElements should be pasted.
popup_request(at_position: Vector2) 🔗
Emitted when a popup is requested. Happens on right-clicking in the GraphEdit. at_position is the position of the mouse pointer when the signal is sent.
scroll_offset_changed(offset: Vector2) 🔗
當使用者改變滾動偏移量時發出。在程式碼中改變滾動偏移量時,它不會被觸發。
列舉
enum PanningScheme: 🔗
PanningScheme SCROLL_ZOOMS = 0
滑鼠滾輪進行縮放,Ctrl + 滑鼠滾輪進行視圖的移動。
PanningScheme SCROLL_PANS = 1
滑鼠滾輪進行視圖的移動,Ctrl + 滑鼠滾輪進行縮放。
enum GridPattern: 🔗
GridPattern GRID_PATTERN_LINES = 0
Draw the grid using solid lines.
GridPattern GRID_PATTERN_DOTS = 1
Draw the grid using dots.
屬性說明
bool connection_lines_antialiased = true 🔗
如果為 true,節點之間的線將使用抗鋸齒。
float connection_lines_curvature = 0.5 🔗
節點之間連線的曲率。0 得到的是直線。
float connection_lines_thickness = 4.0 🔗
節點之間連線的粗細。
Array[Dictionary] connections = [] 🔗
void set_connections(value: Array[Dictionary])
Array[Dictionary] get_connection_list()
The connections between GraphNodes.
A connection is represented as a Dictionary in the form of:
{
from_node: StringName,
from_port: int,
to_node: StringName,
to_port: int,
keep_alive: bool
}
Connections with keep_alive set to false may be deleted automatically if invalid during a redraw.
GridPattern grid_pattern = 0 🔗
void set_grid_pattern(value: GridPattern)
GridPattern get_grid_pattern()
The pattern used for drawing the grid.
如果為 true,小圖是可見的。
float minimap_opacity = 0.65 🔗
小圖矩形的不透明度。
Vector2 minimap_size = Vector2(240, 160) 🔗
小圖矩形的大小。地圖自身基於網格區域的大小,並被縮放以適應這個矩形。
PanningScheme panning_scheme = 0 🔗
void set_panning_scheme(value: PanningScheme)
PanningScheme get_panning_scheme()
定義使用滑鼠滾輪平移的控制方案。
bool right_disconnects = false 🔗
如果為 true,通過拖動右端,可以斷開 GraphEdit 中現有的連接。
Vector2 scroll_offset = Vector2(0, 0) 🔗
滾動偏移量。
bool show_arrange_button = true 🔗
如果為 true,控制項將自動調整高度以適合其內容。
如果為 true,則該視窗可見。
bool show_grid_buttons = true 🔗
如果為 true,則禁用形狀所有者及其形狀。
如果為 true,小圖是可見的。
bool show_minimap_button = true 🔗
如果為 true,小圖是可見的。
bool show_zoom_buttons = true 🔗
如果為 true,則色板和近期顏色預設可見。
bool show_zoom_label = false 🔗
如果為 true,則使目前縮放級別的標籤可見。縮放值以百分比顯示。
吸附距離,單位為圖元。
bool snapping_enabled = true 🔗
如果為 true,啟用自動吸附。
Dictionary type_names = {} 🔗
void set_type_names(value: Dictionary)
Dictionary get_type_names()
Dictionary of human-readable port type names.
目前縮放值。
縮放上限。
縮放下限。
每個縮放級別的步長。
方法說明
PackedVector2Array _get_connection_line(from_position: Vector2, to_position: Vector2) virtual const 🔗
可以重寫的虛方法,以自訂如何繪製連接。
bool _is_in_input_hotzone(in_node: Object, in_port: int, mouse_position: Vector2) virtual 🔗
Returns whether the mouse_position is in the input hot zone.
By default, a hot zone is a Rect2 positioned such that its center is at in_node.GraphNode.get_input_port_position()(in_port) (For output's case, call GraphNode.get_output_port_position() instead). The hot zone's width is twice the Theme Property port_grab_distance_horizontal, and its height is twice the port_grab_distance_vertical.
Below is a sample code to help get started:
func _is_in_input_hotzone(in_node, in_port, mouse_position):
var port_size = Vector2(get_theme_constant("port_grab_distance_horizontal"), get_theme_constant("port_grab_distance_vertical"))
var port_pos = in_node.get_position() + in_node.get_input_port_position(in_port) - port_size / 2
var rect = Rect2(port_pos, port_size)
return rect.has_point(mouse_position)
bool _is_in_output_hotzone(in_node: Object, in_port: int, mouse_position: Vector2) virtual 🔗
Returns whether the mouse_position is in the output hot zone. For more information on hot zones, see _is_in_input_hotzone().
Below is a sample code to help get started:
func _is_in_output_hotzone(in_node, in_port, mouse_position):
var port_size = Vector2(get_theme_constant("port_grab_distance_horizontal"), get_theme_constant("port_grab_distance_vertical"))
var port_pos = in_node.get_position() + in_node.get_output_port_position(in_port) - port_size / 2
var rect = Rect2(port_pos, port_size)
return rect.has_point(mouse_position)
bool _is_node_hover_valid(from_node: StringName, from_port: int, to_node: StringName, to_port: int) virtual 🔗
當使用者在有效埠上拖動連接時,該虛擬方法可用於插入額外的錯誤偵測。
如果連接確實有效,則返回 true;如果連接不可能,則返回 false。如果連接是不可能的,則不會捕捉到該埠,因此不會發起對該埠的連接請求。
在該範例中,抑制了與同一節點的連接:
func _is_node_hover_valid(from, from_port, to, to_port):
return from != to
public override bool _IsNodeHoverValid(StringName fromNode, int fromPort, StringName toNode, int toPort)
{
return fromNode != toNode;
}
void add_valid_connection_type(from_type: int, to_type: int) 🔗
允許兩種不同埠型別之間的連接。埠型別是使用 GraphNode.set_slot() 方法為每個插槽的左右埠單獨定義的。
另請參閱 is_valid_connection_type() 和 remove_valid_connection_type()。
void add_valid_left_disconnect_type(type: int) 🔗
如果 GraphNode 插槽的左側埠具有指定的型別,則允許在從該埠拖動時斷開節點。另請參閱 remove_valid_left_disconnect_type()。
void add_valid_right_disconnect_type(type: int) 🔗
如果 GraphNode 插槽的右側埠具有指定的型別,則允許在從該埠拖動時斷開節點。另請參閱 remove_valid_right_disconnect_type()。
void arrange_nodes() 🔗
重新排列佈局中的選定節點,使連接之間的交叉最少,節點之間的水平和垂直間隙保持一致。
void attach_graph_element_to_frame(element: StringName, frame: StringName) 🔗
Attaches the element GraphElement to the frame GraphFrame.
void clear_connections() 🔗
移除節點之間的所有連接。
Error connect_node(from_node: StringName, from_port: int, to_node: StringName, to_port: int, keep_alive: bool = false) 🔗
Create a connection between the from_port of the from_node GraphNode and the to_port of the to_node GraphNode. If the connection already exists, no connection is created.
Connections with keep_alive set to false may be deleted automatically if invalid during a redraw.
void detach_graph_element_from_frame(element: StringName) 🔗
Detaches the element GraphElement from the GraphFrame it is currently attached to.
void disconnect_node(from_node: StringName, from_port: int, to_node: StringName, to_port: int) 🔗
移除 from_node GraphNode 的 from_port 和 to_node GraphNode 的 to_port 之間的連接。如果該連接不存在,則不移除任何連接。
void force_connection_drag_end() 🔗
結束目前連接的建立。換句話說,如果正在拖動一個連接,可以使用該方法中止該過程,並移除滑鼠游標後面的線。
這最好與 connection_drag_started 和 connection_drag_ended 一起使用,以新增自訂的行為,如通過快捷方式新增節點。
注意:該方法會抑制除 connection_drag_ended 之外的任何其他連接請求訊號。
Array[StringName] get_attached_nodes_of_frame(frame: StringName) 🔗
Returns an array of node names that are attached to the GraphFrame with the given name.
Dictionary get_closest_connection_at_point(point: Vector2, max_distance: float = 4.0) const 🔗
Returns the closest connection to the given point in screen space. If no connection is found within max_distance pixels, an empty Dictionary is returned.
A connection is represented as a Dictionary in the form of:
{
from_node: StringName,
from_port: int,
to_node: StringName,
to_port: int,
keep_alive: bool
}
For example, getting a connection at a given mouse position can be achieved like this:
var connection = get_closest_connection_at_point(mouse_event.get_position())
int get_connection_count(from_node: StringName, from_port: int) 🔗
Returns the number of connections from from_port of from_node.
PackedVector2Array get_connection_line(from_node: Vector2, to_node: Vector2) const 🔗
返回構成 from_node 和 to_node 之間的連接的點。
Array[Dictionary] get_connection_list_from_node(node: StringName) const 🔗
Returns an Array containing a list of all connections for node.
A connection is represented as a Dictionary in the form of:
{
from_node: StringName,
from_port: int,
to_node: StringName,
to_port: int,
keep_alive: bool
}
Example: Get all connections on a specific port:
func get_connection_list_from_port(node, port):
var connections = get_connection_list_from_node(node)
var result = []
for connection in connections:
var dict = {}
if connection["from_node"] == node and connection["from_port"] == port:
dict["node"] = connection["to_node"]
dict["port"] = connection["to_port"]
dict["type"] = "left"
result.push_back(dict)
elif connection["to_node"] == node and connection["to_port"] == port:
dict["node"] = connection["from_node"]
dict["port"] = connection["from_port"]
dict["type"] = "right"
result.push_back(dict)
return result
Array[Dictionary] get_connections_intersecting_with_rect(rect: Rect2) const 🔗
Returns an Array containing the list of connections that intersect with the given Rect2.
A connection is represented as a Dictionary in the form of:
{
from_node: StringName,
from_port: int,
to_node: StringName,
to_port: int,
keep_alive: bool
}
GraphFrame get_element_frame(element: StringName) 🔗
Returns the GraphFrame that contains the GraphElement with the given name.
獲取包含圖形左上角的縮放和網格捕捉控制項的 HBoxContainer。你可以使用此方法重新定位工具列或向其新增自訂控制項。
警告:這是一個必需的內部節點,刪除和釋放它可能會導致當機。如果你希望隱藏它或其任何子項,請使用它們的 CanvasItem.visible 屬性。
bool is_node_connected(from_node: StringName, from_port: int, to_node: StringName, to_port: int) 🔗
如果 from_node GraphNode 的 from_port 連接到 to_node GraphNode 的 to_port,則返回 true。
bool is_valid_connection_type(from_type: int, to_type: int) const 🔗
返回是否可以在兩種不同的埠型別之間建立連接。埠型別是使用 GraphNode.set_slot() 方法為每個插槽的左右埠單獨定義的。
另請參閱 add_valid_connection_type() 和 remove_valid_connection_type()。
void remove_valid_connection_type(from_type: int, to_type: int) 🔗
不允許先前由 add_valid_connection_type() 允許的兩種不同埠型別之間的連接。埠型別是通過 GraphNode.set_slot() 方法為每個插槽的左右埠單獨定義的。
另請參閱 is_valid_connection_type()。
void remove_valid_left_disconnect_type(type: int) 🔗
Disallows to disconnect nodes when dragging from the left port of the GraphNode's slot if it has the specified type. Use this to disable a disconnection previously allowed with add_valid_left_disconnect_type().
void remove_valid_right_disconnect_type(type: int) 🔗
Disallows to disconnect nodes when dragging from the right port of the GraphNode's slot if it has the specified type. Use this to disable a disconnection previously allowed with add_valid_right_disconnect_type().
void set_connection_activity(from_node: StringName, from_port: int, to_node: StringName, to_port: int, amount: float) 🔗
Sets the coloration of the connection between from_node's from_port and to_node's to_port with the color provided in the activity theme property. The color is linearly interpolated between the connection color and the activity color using amount as weight.
void set_selected(node: Node) 🔗
將指定的 node 節點設定為選中的節點。
主題屬性說明
Color activity = Color(1, 1, 1, 1) 🔗
Color the connection line is interpolated to based on the activity value of a connection (see set_connection_activity()).
Color connection_hover_tint_color = Color(0, 0, 0, 0.3) 🔗
Color which is blended with the connection line when the mouse is hovering over it.
Color connection_rim_color = Color(0.1, 0.1, 0.1, 0.6) 🔗
Color of the rim around each connection line used for making intersecting lines more distinguishable.
Color connection_valid_target_tint_color = Color(1, 1, 1, 0.4) 🔗
Color which is blended with the connection line when the currently dragged connection is hovering over a valid target port.
Color grid_major = Color(1, 1, 1, 0.2) 🔗
Color of major grid lines/dots.
Color grid_minor = Color(1, 1, 1, 0.05) 🔗
Color of minor grid lines/dots.
Color selection_fill = Color(1, 1, 1, 0.3) 🔗
選定的矩形的填充顏色。
Color selection_stroke = Color(1, 1, 1, 0.8) 🔗
選擇的矩形的輪廓顏色。
int connection_hover_thickness = 0 🔗
Widens the line of a connection when the mouse is hovering over it by a percentage factor. A value of 0 disables the highlight. A value of 100 doubles the line width.
int port_hotzone_inner_extent = 22 🔗
能夠抓取埠的(內側)橫向範圍。
int port_hotzone_outer_extent = 26 🔗
能夠抓取埠的(外側)橫向範圍。
吸附動按鈕的圖示。
關閉按鈕被按下時的圖示。
吸附動按鈕的圖示。
吸附動按鈕的圖示。
放大按鈕的圖示。
縮小按鈕的圖示。
縮放重新開機按鈕的圖示。
There is currently no description for this theme property. Please help us by contributing one!
繪製在柵格下方的背景。
StyleBox used when the GraphEdit is focused (when used with assistive apps).