AnimationNodeStateMachine
繼承: AnimationRootNode < AnimationNode < Resource < RefCounted < Object
含多個 AnimationRootNode 的狀態機,供 AnimationTree 使用。
說明
包含多個代表動畫狀態的 AnimationRootNode,並以圖形方式互相連接。可使用最短路徑演算法,將狀態轉換設定為自動或透過程式碼觸發。若要以程式方式控制,請從 AnimationTree 取得 AnimationNodeStateMachinePlayback 物件。
var state_machine = $AnimationTree.get("parameters/playback")
state_machine.travel("some_state")
var stateMachine = GetNode<AnimationTree>("AnimationTree").Get("parameters/playback") as AnimationNodeStateMachinePlayback;
stateMachine.Travel("some_state");
教學
屬性
|
||
|
||
|
方法
void |
add_node(name: StringName, node: AnimationNode, position: Vector2 = Vector2(0, 0)) |
void |
add_transition(from: StringName, to: StringName, transition: AnimationNodeStateMachineTransition) |
get_graph_offset() const |
|
get_node(name: StringName) const |
|
get_node_list() const |
|
get_node_name(node: AnimationNode) const |
|
get_node_position(name: StringName) const |
|
get_transition(idx: int) const |
|
get_transition_count() const |
|
get_transition_from(idx: int) const |
|
get_transition_to(idx: int) const |
|
has_node(name: StringName) const |
|
has_transition(from: StringName, to: StringName) const |
|
void |
remove_node(name: StringName) |
void |
remove_transition(from: StringName, to: StringName) |
void |
|
void |
rename_node(name: StringName, new_name: StringName) |
void |
replace_node(name: StringName, node: AnimationNode) |
void |
set_graph_offset(offset: Vector2) |
void |
set_node_position(name: StringName, position: Vector2) |
列舉
enum StateMachineType: 🔗
StateMachineType STATE_MACHINE_TYPE_ROOT = 0
將尋道至開頭視為從起始狀態播放;轉場至結束狀態則視為離開狀態機。
StateMachineType STATE_MACHINE_TYPE_NESTED = 1
將尋道至開頭視為在目前狀態中尋道至動畫開頭;若轉場至結束狀態或各狀態皆無轉場,則視為離開狀態機。
StateMachineType STATE_MACHINE_TYPE_GROUPED = 2
這是可由父狀態機控制的分組狀態機,本身不會獨立運作。父層或更高層必須存在 state_machine_type 為 STATE_MACHINE_TYPE_ROOT 或 STATE_MACHINE_TYPE_NESTED 的狀態機。
屬性說明
bool allow_transition_to_self = false 🔗
若為 true,則可使用 AnimationNodeStateMachinePlayback.travel() 傳送回目前狀態;若在該方法中啟用重設選項,動畫將重新播放。若為 false,傳送到自身狀態時不會發生任何事。
若為 true,則將與起始與結束節點的交叉淡入淡出視為與 RESET 動畫的混合。
多數情況下,若在狀態機的父 AnimationNode 進行額外淡入淡出,建議將此屬性設為 false,並使父節點與狀態機的起始/結束節點之淡入淡出時間一致,以取得較佳效果。
StateMachineType state_machine_type = 0 🔗
void set_state_machine_type(value: StateMachineType)
StateMachineType get_state_machine_type()
此屬性可根據不同情境定義轉場流程。另見 StateMachineType。
方法說明
void add_node(name: StringName, node: AnimationNode, position: Vector2 = Vector2(0, 0)) 🔗
向圖形中新增新的動畫節點。position 僅用於編輯器中的顯示位置。
void add_transition(from: StringName, to: StringName, transition: AnimationNodeStateMachineTransition) 🔗
在指定的動畫節點之間新增轉場。
Vector2 get_graph_offset() const 🔗
返回圖形的繪製偏移量,僅供編輯器顯示使用。
AnimationNode get_node(name: StringName) const 🔗
返回指定名稱的動畫節點。
Array[StringName] get_node_list() const 🔗
返回一個列表,內含此狀態機中的所有動畫節點名稱。
StringName get_node_name(node: AnimationNode) const 🔗
返回指定動畫節點的名稱。
Vector2 get_node_position(name: StringName) const 🔗
返回指定動畫節點的座標,僅供編輯器顯示使用。
AnimationNodeStateMachineTransition get_transition(idx: int) const 🔗
返回指定的轉場。
int get_transition_count() const 🔗
返回圖形中的連線數量。
StringName get_transition_from(idx: int) const 🔗
返回指定轉場的起始節點。
StringName get_transition_to(idx: int) const 🔗
返回指定轉場的結束節點。
bool has_node(name: StringName) const 🔗
若圖形中包含指定的動畫節點,則返回 true。
bool has_transition(from: StringName, to: StringName) const 🔗
若指定的兩個動畫節點之間存在轉場,則返回 true。
void remove_node(name: StringName) 🔗
從圖形中刪除指定的動畫節點。
void remove_transition(from: StringName, to: StringName) 🔗
刪除兩個指定動畫節點之間的轉場。
void remove_transition_by_index(idx: int) 🔗
依索引刪除指定的轉場。
void rename_node(name: StringName, new_name: StringName) 🔗
重新命名指定的動畫節點。
void replace_node(name: StringName, node: AnimationNode) 🔗
以新的動畫節點取代指定的動畫節點。
void set_graph_offset(offset: Vector2) 🔗
設定圖形的繪製偏移量,僅供編輯器顯示使用。
void set_node_position(name: StringName, position: Vector2) 🔗
設定動畫節點的座標,僅供編輯器顯示使用。