1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
|
#include "animation_node_state_machine.h"
/////////////////////////////////////////////////
void AnimationNodeStateMachineTransition::set_switch_mode(SwitchMode p_mode) {
switch_mode = p_mode;
}
AnimationNodeStateMachineTransition::SwitchMode AnimationNodeStateMachineTransition::get_switch_mode() const {
return switch_mode;
}
void AnimationNodeStateMachineTransition::set_auto_advance(bool p_enable) {
auto_advance = p_enable;
}
bool AnimationNodeStateMachineTransition::has_auto_advance() const {
return auto_advance;
}
void AnimationNodeStateMachineTransition::set_xfade_time(float p_xfade) {
ERR_FAIL_COND(p_xfade < 0);
xfade = p_xfade;
emit_changed();
}
float AnimationNodeStateMachineTransition::get_xfade_time() const {
return xfade;
}
void AnimationNodeStateMachineTransition::set_disabled(bool p_disabled) {
disabled = p_disabled;
emit_changed();
}
bool AnimationNodeStateMachineTransition::is_disabled() const {
return disabled;
}
void AnimationNodeStateMachineTransition::set_priority(int p_priority) {
priority = p_priority;
emit_changed();
}
int AnimationNodeStateMachineTransition::get_priority() const {
return priority;
}
void AnimationNodeStateMachineTransition::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_switch_mode", "mode"), &AnimationNodeStateMachineTransition::set_switch_mode);
ClassDB::bind_method(D_METHOD("get_switch_mode"), &AnimationNodeStateMachineTransition::get_switch_mode);
ClassDB::bind_method(D_METHOD("set_auto_advance", "auto_advance"), &AnimationNodeStateMachineTransition::set_auto_advance);
ClassDB::bind_method(D_METHOD("has_auto_advance"), &AnimationNodeStateMachineTransition::has_auto_advance);
ClassDB::bind_method(D_METHOD("set_xfade_time", "secs"), &AnimationNodeStateMachineTransition::set_xfade_time);
ClassDB::bind_method(D_METHOD("get_xfade_time"), &AnimationNodeStateMachineTransition::get_xfade_time);
ClassDB::bind_method(D_METHOD("set_disabled", "disabled"), &AnimationNodeStateMachineTransition::set_disabled);
ClassDB::bind_method(D_METHOD("is_disabled"), &AnimationNodeStateMachineTransition::is_disabled);
ClassDB::bind_method(D_METHOD("set_priority", "priority"), &AnimationNodeStateMachineTransition::set_priority);
ClassDB::bind_method(D_METHOD("get_priority"), &AnimationNodeStateMachineTransition::get_priority);
ADD_PROPERTY(PropertyInfo(Variant::INT, "switch_mode", PROPERTY_HINT_ENUM, "Immediate,Sync,AtEnd"), "set_switch_mode", "get_switch_mode");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_advance"), "set_auto_advance", "has_auto_advance");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "xfade_time", PROPERTY_HINT_RANGE, "0,240,0.01"), "set_xfade_time", "get_xfade_time");
ADD_PROPERTY(PropertyInfo(Variant::INT, "priority", PROPERTY_HINT_RANGE, "0,32,1"), "set_priority", "get_priority");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "disabled"), "set_disabled", "is_disabled");
BIND_ENUM_CONSTANT(SWITCH_MODE_IMMEDIATE);
BIND_ENUM_CONSTANT(SWITCH_MODE_SYNC);
BIND_ENUM_CONSTANT(SWITCH_MODE_AT_END);
}
AnimationNodeStateMachineTransition::AnimationNodeStateMachineTransition() {
switch_mode = SWITCH_MODE_IMMEDIATE;
auto_advance = false;
xfade = 0;
disabled = false;
priority = 1;
}
///////////////////////////////////////////////////////
void AnimationNodeStateMachine::add_node(const StringName &p_name, Ref<AnimationNode> p_node) {
ERR_FAIL_COND(states.has(p_name));
ERR_FAIL_COND(p_node.is_null());
ERR_FAIL_COND(p_node->get_parent().is_valid());
ERR_FAIL_COND(p_node->get_tree() != NULL);
ERR_FAIL_COND(String(p_name).find("/") != -1);
states[p_name] = p_node;
p_node->set_parent(this);
p_node->set_tree(get_tree());
emit_changed();
}
Ref<AnimationNode> AnimationNodeStateMachine::get_node(const StringName &p_name) const {
ERR_FAIL_COND_V(!states.has(p_name), Ref<AnimationNode>());
return states[p_name];
}
StringName AnimationNodeStateMachine::get_node_name(const Ref<AnimationNode> &p_node) const {
for (Map<StringName, Ref<AnimationRootNode> >::Element *E = states.front(); E; E = E->next()) {
if (E->get() == p_node) {
return E->key();
}
}
ERR_FAIL_V(StringName());
}
bool AnimationNodeStateMachine::has_node(const StringName &p_name) const {
return states.has(p_name);
}
void AnimationNodeStateMachine::remove_node(const StringName &p_name) {
ERR_FAIL_COND(!states.has(p_name));
{
//erase node connections
Ref<AnimationNode> node = states[p_name];
for (int i = 0; i < node->get_input_count(); i++) {
node->set_input_connection(i, StringName());
}
node->set_parent(NULL);
node->set_tree(NULL);
}
states.erase(p_name);
path.erase(p_name);
for (int i = 0; i < transitions.size(); i++) {
if (transitions[i].from == p_name || transitions[i].to == p_name) {
transitions.remove(i);
i--;
}
}
if (start_node == p_name) {
start_node = StringName();
}
if (end_node == p_name) {
end_node = StringName();
}
if (playing && current == p_name) {
stop();
}
emit_changed();
}
void AnimationNodeStateMachine::rename_node(const StringName &p_name, const StringName &p_new_name) {
ERR_FAIL_COND(!states.has(p_name));
ERR_FAIL_COND(states.has(p_new_name));
states[p_new_name] = states[p_name];
states.erase(p_name);
for (int i = 0; i < transitions.size(); i++) {
if (transitions[i].from == p_name) {
transitions.write[i].from = p_new_name;
}
if (transitions[i].to == p_name) {
transitions.write[i].to = p_new_name;
}
}
if (start_node == p_name) {
start_node = p_new_name;
}
if (end_node == p_name) {
end_node = p_new_name;
}
if (playing && current == p_name) {
current = p_new_name;
}
path.clear(); //clear path
}
void AnimationNodeStateMachine::get_node_list(List<StringName> *r_nodes) const {
List<StringName> nodes;
for (Map<StringName, Ref<AnimationRootNode> >::Element *E = states.front(); E; E = E->next()) {
nodes.push_back(E->key());
}
nodes.sort_custom<StringName::AlphCompare>();
for (List<StringName>::Element *E = nodes.front(); E; E = E->next()) {
r_nodes->push_back(E->get());
}
}
bool AnimationNodeStateMachine::has_transition(const StringName &p_from, const StringName &p_to) const {
for (int i = 0; i < transitions.size(); i++) {
if (transitions[i].from == p_from && transitions[i].to == p_to)
return true;
}
return false;
}
int AnimationNodeStateMachine::find_transition(const StringName &p_from, const StringName &p_to) const {
for (int i = 0; i < transitions.size(); i++) {
if (transitions[i].from == p_from && transitions[i].to == p_to)
return i;
}
return -1;
}
void AnimationNodeStateMachine::add_transition(const StringName &p_from, const StringName &p_to, const Ref<AnimationNodeStateMachineTransition> &p_transition) {
ERR_FAIL_COND(p_from == p_to);
ERR_FAIL_COND(!states.has(p_from));
ERR_FAIL_COND(!states.has(p_to));
ERR_FAIL_COND(p_transition.is_null());
for (int i = 0; i < transitions.size(); i++) {
ERR_FAIL_COND(transitions[i].from == p_from && transitions[i].to == p_to);
}
Transition tr;
tr.from = p_from;
tr.to = p_to;
tr.transition = p_transition;
transitions.push_back(tr);
}
Ref<AnimationNodeStateMachineTransition> AnimationNodeStateMachine::get_transition(int p_transition) const {
ERR_FAIL_INDEX_V(p_transition, transitions.size(), Ref<AnimationNodeStateMachineTransition>());
return transitions[p_transition].transition;
}
StringName AnimationNodeStateMachine::get_transition_from(int p_transition) const {
ERR_FAIL_INDEX_V(p_transition, transitions.size(), StringName());
return transitions[p_transition].from;
}
StringName AnimationNodeStateMachine::get_transition_to(int p_transition) const {
ERR_FAIL_INDEX_V(p_transition, transitions.size(), StringName());
return transitions[p_transition].to;
}
int AnimationNodeStateMachine::get_transition_count() const {
return transitions.size();
}
void AnimationNodeStateMachine::remove_transition(const StringName &p_from, const StringName &p_to) {
for (int i = 0; i < transitions.size(); i++) {
if (transitions[i].from == p_from && transitions[i].to == p_to) {
transitions.remove(i);
return;
}
}
if (playing) {
path.clear();
}
}
void AnimationNodeStateMachine::remove_transition_by_index(int p_transition) {
transitions.remove(p_transition);
if (playing) {
path.clear();
}
}
void AnimationNodeStateMachine::set_start_node(const StringName &p_node) {
ERR_FAIL_COND(p_node != StringName() && !states.has(p_node));
start_node = p_node;
}
String AnimationNodeStateMachine::get_start_node() const {
return start_node;
}
void AnimationNodeStateMachine::set_end_node(const StringName &p_node) {
ERR_FAIL_COND(p_node != StringName() && !states.has(p_node));
end_node = p_node;
}
String AnimationNodeStateMachine::get_end_node() const {
return end_node;
}
void AnimationNodeStateMachine::set_graph_offset(const Vector2 &p_offset) {
graph_offset = p_offset;
}
Vector2 AnimationNodeStateMachine::get_graph_offset() const {
return graph_offset;
}
float AnimationNodeStateMachine::process(float p_time, bool p_seek) {
//if not playing and it can restart, then restart
if (!playing) {
if (start_node) {
start(start_node);
} else {
return 0;
}
}
bool do_start = (p_seek && p_time == 0) || play_start || current == StringName();
if (do_start) {
if (start_node != StringName() && p_seek && p_time == 0) {
current = start_node;
}
len_current = blend_node(states[current], 0, true, 1.0, FILTER_IGNORE, false);
pos_current = 0;
loops_current = 0;
play_start = false;
}
float fade_blend = 1.0;
if (fading_from != StringName()) {
if (!p_seek) {
fading_pos += p_time;
}
fade_blend = MIN(1.0, fading_pos / fading_time);
if (fade_blend >= 1.0) {
fading_from = StringName();
}
}
float rem = blend_node(states[current], p_time, p_seek, fade_blend, FILTER_IGNORE, false);
if (fading_from != StringName()) {
blend_node(states[fading_from], p_time, p_seek, 1.0 - fade_blend, FILTER_IGNORE, false);
}
//guess playback position
if (rem > len_current) { // weird but ok
len_current = rem;
}
{ //advance and loop check
float next_pos = len_current - rem;
if (next_pos < pos_current) {
loops_current++;
}
pos_current = next_pos; //looped
}
//find next
StringName next;
float next_xfade = 0;
AnimationNodeStateMachineTransition::SwitchMode switch_mode = AnimationNodeStateMachineTransition::SWITCH_MODE_IMMEDIATE;
if (path.size()) {
for (int i = 0; i < transitions.size(); i++) {
if (transitions[i].from == current && transitions[i].to == path[0]) {
next_xfade = transitions[i].transition->get_xfade_time();
switch_mode = transitions[i].transition->get_switch_mode();
next = path[0];
}
}
} else {
float priority_best = 1e20;
int auto_advance_to = -1;
for (int i = 0; i < transitions.size(); i++) {
if (transitions[i].from == current && transitions[i].transition->has_auto_advance()) {
if (transitions[i].transition->get_priority() < priority_best) {
auto_advance_to = i;
}
}
}
if (auto_advance_to != -1) {
next = transitions[auto_advance_to].to;
next_xfade = transitions[auto_advance_to].transition->get_xfade_time();
switch_mode = transitions[auto_advance_to].transition->get_switch_mode();
}
}
//if next, see when to transition
if (next != StringName()) {
bool goto_next = false;
if (switch_mode == AnimationNodeStateMachineTransition::SWITCH_MODE_IMMEDIATE) {
goto_next = fading_from == StringName();
} else {
goto_next = next_xfade >= (len_current - pos_current) || loops_current > 0;
if (loops_current > 0) {
next_xfade = 0;
}
}
if (goto_next) { //loops should be used because fade time may be too small or zero and animation may have looped
if (next_xfade) {
//time to fade, baby
fading_from = current;
fading_time = next_xfade;
fading_pos = 0;
} else {
fading_from = StringName();
fading_pos = 0;
}
if (path.size()) { //if it came from path, remove path
path.remove(0);
}
current = next;
if (switch_mode == AnimationNodeStateMachineTransition::SWITCH_MODE_SYNC) {
len_current = blend_node(states[current], 0, true, 0, FILTER_IGNORE, false);
pos_current = MIN(pos_current, len_current);
blend_node(states[current], pos_current, true, 0, FILTER_IGNORE, false);
} else {
len_current = blend_node(states[current], 0, true, 0, FILTER_IGNORE, false);
pos_current = 0;
}
rem = len_current; //so it does not show 0 on transition
loops_current = 0;
}
}
//compute time left for transitions by using the end node
if (end_node != StringName() && end_node != current) {
rem = blend_node(states[end_node], 0, true, 0, FILTER_IGNORE, false);
}
return rem;
}
bool AnimationNodeStateMachine::travel(const StringName &p_state) {
ERR_FAIL_COND_V(!playing, false);
ERR_FAIL_COND_V(!states.has(p_state), false);
ERR_FAIL_COND_V(!states.has(current), false);
path.clear(); //a new one will be needed
if (current == p_state)
return true; //nothing to do
loops_current = 0; // reset loops, so fade does not happen immediately
Vector2 current_pos = states[current]->get_position();
Vector2 target_pos = states[p_state]->get_position();
Map<StringName, AStarCost> cost_map;
List<int> open_list;
//build open list
for (int i = 0; i < transitions.size(); i++) {
if (transitions[i].from == current) {
open_list.push_back(i);
float cost = states[transitions[i].to]->get_position().distance_to(current_pos);
cost *= transitions[i].transition->get_priority();
AStarCost ap;
ap.prev = current;
ap.distance = cost;
cost_map[transitions[i].to] = ap;
if (transitions[i].to == p_state) { //prematurely found it! :D
path.push_back(p_state);
return true;
}
}
}
//begin astar
bool found_route = false;
while (!found_route) {
if (open_list.size() == 0) {
return false; //no path found
}
//find the last cost transition
List<int>::Element *least_cost_transition = NULL;
float least_cost = 1e20;
for (List<int>::Element *E = open_list.front(); E; E = E->next()) {
float cost = cost_map[transitions[E->get()].to].distance;
cost += states[transitions[E->get()].to]->get_position().distance_to(target_pos);
if (cost < least_cost) {
least_cost_transition = E;
}
}
StringName transition_prev = transitions[least_cost_transition->get()].from;
StringName transition = transitions[least_cost_transition->get()].to;
for (int i = 0; i < transitions.size(); i++) {
if (transitions[i].from != transition || transitions[i].to == transition_prev) {
continue; //not interested on those
}
float distance = states[transitions[i].from]->get_position().distance_to(states[transitions[i].to]->get_position());
distance *= transitions[i].transition->get_priority();
distance += cost_map[transitions[i].from].distance;
if (cost_map.has(transitions[i].to)) {
//oh this was visited already, can we win the cost?
if (distance < cost_map[transitions[i].to].distance) {
cost_map[transitions[i].to].distance = distance;
cost_map[transitions[i].to].prev = transitions[i].from;
}
} else {
//add to open list
AStarCost ac;
ac.prev = transitions[i].from;
ac.distance = distance;
cost_map[transitions[i].to] = ac;
open_list.push_back(i);
if (transitions[i].to == p_state) {
found_route = true;
break;
}
}
}
if (found_route) {
break;
}
open_list.erase(least_cost_transition);
}
//make path
StringName at = p_state;
while (at != current) {
path.push_back(at);
at = cost_map[at].prev;
}
path.invert();
return true;
}
void AnimationNodeStateMachine::start(const StringName &p_state) {
ERR_FAIL_COND(!states.has(p_state));
path.clear();
current = p_state;
playing = true;
play_start = true;
}
void AnimationNodeStateMachine::stop() {
playing = false;
play_start = false;
current = StringName();
}
bool AnimationNodeStateMachine::is_playing() const {
return playing;
}
StringName AnimationNodeStateMachine::get_current_node() const {
if (!playing) {
return StringName();
}
return current;
}
StringName AnimationNodeStateMachine::get_blend_from_node() const {
if (!playing) {
return StringName();
}
return fading_from;
}
float AnimationNodeStateMachine::get_current_play_pos() const {
return pos_current;
}
float AnimationNodeStateMachine::get_current_length() const {
return len_current;
}
Vector<StringName> AnimationNodeStateMachine::get_travel_path() const {
return path;
}
String AnimationNodeStateMachine::get_caption() const {
return "StateMachine";
}
void AnimationNodeStateMachine::_notification(int p_what) {
}
void AnimationNodeStateMachine::set_tree(AnimationTree *p_player) {
AnimationNode::set_tree(p_player);
for (Map<StringName, Ref<AnimationRootNode> >::Element *E = states.front(); E; E = E->next()) {
Ref<AnimationRootNode> node = E->get();
node->set_tree(p_player);
}
}
bool AnimationNodeStateMachine::_set(const StringName &p_name, const Variant &p_value) {
String name = p_name;
if (name.begins_with("states/")) {
String node_name = name.get_slicec('/', 1);
String what = name.get_slicec('/', 2);
if (what == "node") {
Ref<AnimationNode> anode = p_value;
if (anode.is_valid()) {
add_node(node_name, p_value);
}
return true;
}
if (what == "position") {
if (states.has(node_name)) {
states[node_name]->set_position(p_value);
}
return true;
}
} else if (name == "transitions") {
Array trans = p_value;
ERR_FAIL_COND_V(trans.size() % 3 != 0, false);
for (int i = 0; i < trans.size(); i += 3) {
add_transition(trans[i], trans[i + 1], trans[i + 2]);
}
return true;
} else if (name == "start_node") {
set_start_node(p_value);
return true;
} else if (name == "end_node") {
set_end_node(p_value);
return true;
} else if (name == "graph_offset") {
set_graph_offset(p_value);
return true;
}
return false;
}
bool AnimationNodeStateMachine::_get(const StringName &p_name, Variant &r_ret) const {
String name = p_name;
if (name.begins_with("states/")) {
String node_name = name.get_slicec('/', 1);
String what = name.get_slicec('/', 2);
if (what == "node") {
if (states.has(node_name)) {
r_ret = states[node_name];
return true;
}
}
if (what == "position") {
if (states.has(node_name)) {
r_ret = states[node_name]->get_position();
return true;
}
}
} else if (name == "transitions") {
Array trans;
trans.resize(transitions.size() * 3);
for (int i = 0; i < transitions.size(); i++) {
trans[i * 3 + 0] = transitions[i].from;
trans[i * 3 + 1] = transitions[i].to;
trans[i * 3 + 2] = transitions[i].transition;
}
r_ret = trans;
return true;
} else if (name == "start_node") {
r_ret = get_start_node();
return true;
} else if (name == "end_node") {
r_ret = get_end_node();
return true;
} else if (name == "graph_offset") {
r_ret = get_graph_offset();
return true;
}
return false;
}
void AnimationNodeStateMachine::_get_property_list(List<PropertyInfo> *p_list) const {
List<StringName> names;
for (Map<StringName, Ref<AnimationRootNode> >::Element *E = states.front(); E; E = E->next()) {
names.push_back(E->key());
}
names.sort_custom<StringName::AlphCompare>();
for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
String name = E->get();
p_list->push_back(PropertyInfo(Variant::OBJECT, "states/" + name + "/node", PROPERTY_HINT_RESOURCE_TYPE, "AnimationNode", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE));
p_list->push_back(PropertyInfo(Variant::VECTOR2, "states/" + name + "/position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
}
p_list->push_back(PropertyInfo(Variant::ARRAY, "transitions", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
p_list->push_back(PropertyInfo(Variant::STRING, "start_node", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
p_list->push_back(PropertyInfo(Variant::STRING, "end_node", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
p_list->push_back(PropertyInfo(Variant::VECTOR2, "graph_offset", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
}
void AnimationNodeStateMachine::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_node", "name", "node"), &AnimationNodeStateMachine::add_node);
ClassDB::bind_method(D_METHOD("get_node", "name"), &AnimationNodeStateMachine::get_node);
ClassDB::bind_method(D_METHOD("remove_node", "name"), &AnimationNodeStateMachine::remove_node);
ClassDB::bind_method(D_METHOD("rename_node", "name", "new_name"), &AnimationNodeStateMachine::rename_node);
ClassDB::bind_method(D_METHOD("has_node", "name"), &AnimationNodeStateMachine::has_node);
ClassDB::bind_method(D_METHOD("get_node_name", "node"), &AnimationNodeStateMachine::get_node_name);
ClassDB::bind_method(D_METHOD("has_transition", "from", "to"), &AnimationNodeStateMachine::add_transition);
ClassDB::bind_method(D_METHOD("add_transition", "from", "to", "transition"), &AnimationNodeStateMachine::add_transition);
ClassDB::bind_method(D_METHOD("get_transition", "idx"), &AnimationNodeStateMachine::get_transition);
ClassDB::bind_method(D_METHOD("get_transition_from", "idx"), &AnimationNodeStateMachine::get_transition_from);
ClassDB::bind_method(D_METHOD("get_transition_to", "idx"), &AnimationNodeStateMachine::get_transition_to);
ClassDB::bind_method(D_METHOD("get_transition_count"), &AnimationNodeStateMachine::get_transition_count);
ClassDB::bind_method(D_METHOD("remove_transition_by_index", "idx"), &AnimationNodeStateMachine::remove_transition_by_index);
ClassDB::bind_method(D_METHOD("remove_transition", "from", "to"), &AnimationNodeStateMachine::remove_transition);
ClassDB::bind_method(D_METHOD("set_start_node", "name"), &AnimationNodeStateMachine::set_start_node);
ClassDB::bind_method(D_METHOD("get_start_node"), &AnimationNodeStateMachine::get_start_node);
ClassDB::bind_method(D_METHOD("set_end_node", "name"), &AnimationNodeStateMachine::set_end_node);
ClassDB::bind_method(D_METHOD("get_end_node"), &AnimationNodeStateMachine::get_end_node);
ClassDB::bind_method(D_METHOD("set_graph_offset", "name"), &AnimationNodeStateMachine::set_graph_offset);
ClassDB::bind_method(D_METHOD("get_graph_offset"), &AnimationNodeStateMachine::get_graph_offset);
ClassDB::bind_method(D_METHOD("travel", "to_node"), &AnimationNodeStateMachine::travel);
ClassDB::bind_method(D_METHOD("start", "node"), &AnimationNodeStateMachine::start);
ClassDB::bind_method(D_METHOD("stop"), &AnimationNodeStateMachine::stop);
ClassDB::bind_method(D_METHOD("is_playing"), &AnimationNodeStateMachine::is_playing);
ClassDB::bind_method(D_METHOD("get_current_node"), &AnimationNodeStateMachine::get_current_node);
ClassDB::bind_method(D_METHOD("get_travel_path"), &AnimationNodeStateMachine::get_travel_path);
}
AnimationNodeStateMachine::AnimationNodeStateMachine() {
play_start = false;
playing = false;
len_current = 0;
fading_time = 0;
}
|