| 560 | } |
| 561 | |
| 562 | void Model::setupCallback() { |
| 563 | for (const auto& animationGroup : _animationGroups) { |
| 564 | if (animationGroup->animations.empty()) { |
| 565 | continue; |
| 566 | } |
| 567 | float duration = 0.0f; |
| 568 | for (const auto& animation : animationGroup->animations) { |
| 569 | float d = animation->getDuration(); |
| 570 | if (duration < d) { |
| 571 | duration = d; |
| 572 | } |
| 573 | } |
| 574 | Action* action = animationGroup->animations[0]->getAction(); |
| 575 | float d = action->getDuration(); |
| 576 | if (d < duration) { |
| 577 | action = Sequence::create( |
| 578 | std::move(action->getAction()), |
| 579 | Delay::alloc(duration - d)); |
| 580 | } |
| 581 | Node* node = animationGroup->animations[0]->getNode(); |
| 582 | node->slot("ActionEnd"_slice, [this, action](Event* event) { |
| 583 | Action* eventAction = nullptr; |
| 584 | Node* target = nullptr; |
| 585 | if (event->get(eventAction, target) && action == eventAction) { |
| 586 | onActionEnd(); |
| 587 | } |
| 588 | }); |
| 589 | animationGroup->duration = action->getDuration(); |
| 590 | animationGroup->animations[0]->setAction(action); |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | NS_DORA_END |