本文整理汇总了C++中AnimationPlayer::has_animation方法的典型用法代码示例。如果您正苦于以下问题:C++ AnimationPlayer::has_animation方法的具体用法?C++ AnimationPlayer::has_animation怎么用?C++ AnimationPlayer::has_animation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnimationPlayer
的用法示例。
在下文中一共展示了AnimationPlayer::has_animation方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _notification
void AnimationNodeBlendTreeEditor::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
goto_parent->set_icon(get_icon("MoveUp", "EditorIcons"));
error_panel->add_style_override("panel", get_stylebox("bg", "Tree"));
error_label->add_color_override("font_color", get_color("error_color", "Editor"));
}
if (p_what == NOTIFICATION_PROCESS) {
String error;
if (!blend_tree->get_tree()) {
error = TTR("BlendTree does not belong to an AnimationTree node.");
} else if (!blend_tree->get_tree()->is_active()) {
error = TTR("AnimationTree is inactive.\nActivate to enable playback, check node warnings if activation fails.");
} else if (blend_tree->get_tree()->is_state_invalid()) {
error = blend_tree->get_tree()->get_invalid_state_reason();
}
if (error != error_label->get_text()) {
error_label->set_text(error);
if (error != String()) {
error_panel->show();
} else {
error_panel->hide();
}
}
List<AnimationNodeBlendTree::NodeConnection> conns;
blend_tree->get_node_connections(&conns);
for (List<AnimationNodeBlendTree::NodeConnection>::Element *E = conns.front(); E; E = E->next()) {
float activity = 0;
if (blend_tree->get_tree() && !blend_tree->get_tree()->is_state_invalid()) {
activity = blend_tree->get_connection_activity(E->get().input_node, E->get().input_index);
}
graph->set_connection_activity(E->get().output_node, 0, E->get().input_node, E->get().input_index, activity);
}
AnimationTree *graph_player = blend_tree->get_tree();
AnimationPlayer *player = NULL;
if (graph_player->has_node(graph_player->get_animation_player())) {
player = Object::cast_to<AnimationPlayer>(graph_player->get_node(graph_player->get_animation_player()));
}
if (player) {
for (Map<StringName, ProgressBar *>::Element *E = animations.front(); E; E = E->next()) {
Ref<AnimationNodeAnimation> an = blend_tree->get_node(E->key());
if (an.is_valid()) {
if (player->has_animation(an->get_animation())) {
Ref<Animation> anim = player->get_animation(an->get_animation());
if (anim.is_valid()) {
E->get()->set_max(anim->get_length());
E->get()->set_value(an->get_playback_time());
}
}
}
}
}
}
}
示例2: _update_graph
//.........这里部分代码省略.........
}
for (int i = 0; i < agnode->get_input_count(); i++) {
Label *in_name = memnew(Label);
node->add_child(in_name);
in_name->set_text(agnode->get_input_name(i));
node->set_slot(base + i, true, 0, get_color("font_color", "Label"), false, 0, Color());
}
node->connect("dragged", this, "_node_dragged", varray(agnode));
if (EditorNode::get_singleton()->item_has_editor(agnode.ptr())) {
node->add_child(memnew(HSeparator));
Button *open_in_editor = memnew(Button);
open_in_editor->set_text(TTR("Open Editor"));
open_in_editor->set_icon(get_icon("Edit", "EditorIcons"));
node->add_child(open_in_editor);
open_in_editor->connect("pressed", this, "_open_in_editor", varray(E->get()), CONNECT_DEFERRED);
open_in_editor->set_h_size_flags(SIZE_SHRINK_CENTER);
}
if (agnode->has_filter()) {
node->add_child(memnew(HSeparator));
Button *edit_filters = memnew(Button);
edit_filters->set_text(TTR("Edit Filters"));
edit_filters->set_icon(get_icon("AnimationFilter", "EditorIcons"));
node->add_child(edit_filters);
edit_filters->connect("pressed", this, "_edit_filters", varray(E->get()), CONNECT_DEFERRED);
edit_filters->set_h_size_flags(SIZE_SHRINK_CENTER);
}
Ref<AnimationNodeAnimation> anim = agnode;
if (anim.is_valid()) {
MenuButton *mb = memnew(MenuButton);
mb->set_text(anim->get_animation());
mb->set_icon(get_icon("Animation", "EditorIcons"));
Array options;
node->add_child(memnew(HSeparator));
node->add_child(mb);
ProgressBar *pb = memnew(ProgressBar);
AnimationTree *player = anim->get_tree();
if (player->has_node(player->get_animation_player())) {
AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(player->get_node(player->get_animation_player()));
if (ap) {
List<StringName> anims;
ap->get_animation_list(&anims);
for (List<StringName>::Element *F = anims.front(); F; F = F->next()) {
mb->get_popup()->add_item(F->get());
options.push_back(F->get());
}
if (ap->has_animation(anim->get_animation())) {
pb->set_max(ap->get_animation(anim->get_animation())->get_length());
}
}
}
pb->set_percent_visible(false);
animations[E->get()] = pb;
node->add_child(pb);
mb->get_popup()->connect("index_pressed", this, "_anim_selected", varray(options, E->get()), CONNECT_DEFERRED);
}
Ref<AnimationNodeOneShot> oneshot = agnode;
if (oneshot.is_valid()) {
HBoxContainer *play_stop = memnew(HBoxContainer);
play_stop->add_spacer();
Button *play = memnew(Button);
play->set_icon(get_icon("Play", "EditorIcons"));
play->connect("pressed", this, "_oneshot_start", varray(E->get()), CONNECT_DEFERRED);
play_stop->add_child(play);
Button *stop = memnew(Button);
stop->set_icon(get_icon("Stop", "EditorIcons"));
stop->connect("pressed", this, "_oneshot_stop", varray(E->get()), CONNECT_DEFERRED);
play_stop->add_child(stop);
play_stop->add_spacer();
node->add_child(play_stop);
}
}
List<AnimationNodeBlendTree::NodeConnection> connections;
blend_tree->get_node_connections(&connections);
for (List<AnimationNodeBlendTree::NodeConnection>::Element *E = connections.front(); E; E = E->next()) {
StringName from = E->get().output_node;
StringName to = E->get().input_node;
int to_idx = E->get().input_index;
graph->connect_node(from, 0, to, to_idx);
}
}
示例3: _process_graph
//.........这里部分代码省略.........
//time to stop
t->object->call("stop");
t->playing = false;
playing_caches.erase(t);
}
}
}
float db = Math::linear2db(MAX(blend, 0.00001));
if (t->object->has_method("set_unit_db")) {
t->object->call("set_unit_db", db);
} else {
t->object->call("set_volume_db", db);
}
} break;
case Animation::TYPE_ANIMATION: {
TrackCacheAnimation *t = static_cast<TrackCacheAnimation *>(track);
AnimationPlayer *player = Object::cast_to<AnimationPlayer>(t->object);
if (!player)
continue;
if (delta == 0 || seeked) {
//seek
int idx = a->track_find_key(i, time);
if (idx < 0)
continue;
float pos = a->track_get_key_time(i, idx);
StringName anim_name = a->animation_track_get_key_animation(i, idx);
if (String(anim_name) == "[stop]" || !player->has_animation(anim_name))
continue;
Ref<Animation> anim = player->get_animation(anim_name);
float at_anim_pos;
if (anim->has_loop()) {
at_anim_pos = Math::fposmod(time - pos, anim->get_length()); //seek to loop
} else {
at_anim_pos = MAX(anim->get_length(), time - pos); //seek to end
}
if (player->is_playing() || seeked) {
player->play(anim_name);
player->seek(at_anim_pos);
t->playing = true;
playing_caches.insert(t);
} else {
player->set_assigned_animation(anim_name);
player->seek(at_anim_pos, true);
}
} else {
//find stuff to play
List<int> to_play;
a->track_get_key_indices_in_range(i, time, delta, &to_play);
if (to_play.size()) {
int idx = to_play.back()->get();
StringName anim_name = a->animation_track_get_key_animation(i, idx);
if (String(anim_name) == "[stop]" || !player->has_animation(anim_name)) {
if (playing_caches.has(t)) {