foot_steps.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright (c) 2022-2023 the Dviglo project
  2. // Copyright (c) 2008-2023 the Urho3D project
  3. // License: MIT
  4. #include "foot_steps.h"
  5. #include "utilities/spawn.h"
  6. namespace Urho3D
  7. {
  8. void FootSteps::RegisterObject(Context* context)
  9. {
  10. context->RegisterFactory<FootSteps>();
  11. }
  12. FootSteps::FootSteps(Context* context)
  13. : LogicComponent(context)
  14. {
  15. }
  16. void FootSteps::Start()
  17. {
  18. // Subscribe to animation triggers, which are sent by the AnimatedModel's node (same as our node)
  19. SubscribeToEvent(node_, E_ANIMATIONTRIGGER, URHO3D_HANDLER(FootSteps, HandleAnimationTrigger));
  20. }
  21. void FootSteps::HandleAnimationTrigger(StringHash eventType, VariantMap& eventData)
  22. {
  23. using namespace AnimationTrigger;
  24. AnimatedModel* model = node_->GetComponent<AnimatedModel>();
  25. AnimationState* state = model->GetAnimationState(eventData[P_NAME].GetString());
  26. if (!state)
  27. return;
  28. // If the animation is blended with sufficient weight, instantiate a local particle effect for the footstep.
  29. // The trigger data (string) tells the bone scenenode to use. Note: called on both client and server
  30. if (state->GetWeight() > 0.5f)
  31. {
  32. Node* bone = node_->GetChild(eventData[P_DATA].GetString(), true);
  33. if (bone)
  34. SpawnParticleEffect(bone->GetScene(), bone->GetWorldPosition(), "Particle/SnowExplosionFade.xml", 1, LOCAL);
  35. }
  36. }
  37. } // namespace Urho3D