EventNode.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AzCore/Serialization/SerializeContext.h>
  9. #include "EventNode.h"
  10. #include "AnimTrack.h"
  11. #include "TrackEventTrack.h"
  12. #include "Maestro/Types/AnimNodeType.h"
  13. #include "Maestro/Types/AnimValueType.h"
  14. #include "Maestro/Types/AnimParamType.h"
  15. #include <ISystem.h>
  16. //////////////////////////////////////////////////////////////////////////
  17. CAnimEventNode::CAnimEventNode()
  18. : CAnimEventNode(0)
  19. {
  20. }
  21. //////////////////////////////////////////////////////////////////////////
  22. CAnimEventNode::CAnimEventNode(const int id)
  23. : CAnimNode(id, AnimNodeType::Event)
  24. {
  25. SetFlags(GetFlags() | eAnimNodeFlags_CanChangeName);
  26. m_lastEventKey = -1;
  27. }
  28. //////////////////////////////////////////////////////////////////////////
  29. void CAnimEventNode::CreateDefaultTracks()
  30. {
  31. CreateTrack(AnimParamType::TrackEvent);
  32. }
  33. //////////////////////////////////////////////////////////////////////////
  34. unsigned int CAnimEventNode::GetParamCount() const
  35. {
  36. return 1;
  37. }
  38. //////////////////////////////////////////////////////////////////////////
  39. CAnimParamType CAnimEventNode::GetParamType(unsigned int nIndex) const
  40. {
  41. if (nIndex == 0)
  42. {
  43. return AnimParamType::TrackEvent;
  44. }
  45. return AnimParamType::Invalid;
  46. }
  47. //////////////////////////////////////////////////////////////////////////
  48. bool CAnimEventNode::GetParamInfoFromType(const CAnimParamType& animParamType, SParamInfo& info) const
  49. {
  50. if (animParamType.GetType() == AnimParamType::TrackEvent)
  51. {
  52. info.flags = IAnimNode::ESupportedParamFlags(0);
  53. info.name = "Track Event";
  54. info.paramType = AnimParamType::TrackEvent;
  55. info.valueType = AnimValueType::Unknown;
  56. return true;
  57. }
  58. return false;
  59. }
  60. //////////////////////////////////////////////////////////////////////////
  61. void CAnimEventNode::Animate(SAnimContext& ec)
  62. {
  63. // Get track event
  64. int trackCount = NumTracks();
  65. for (int paramIndex = 0; paramIndex < trackCount; paramIndex++)
  66. {
  67. CAnimParamType trackType = m_tracks[paramIndex]->GetParameterType();
  68. IAnimTrack* pTrack = m_tracks[paramIndex].get();
  69. if (pTrack && pTrack->GetFlags() & IAnimTrack::eAnimTrackFlags_Disabled)
  70. {
  71. continue;
  72. }
  73. // Check for fire
  74. if (CTrackEventTrack* pEventTrack = (CTrackEventTrack*)pTrack)
  75. {
  76. IEventKey key;
  77. int nEventKey = pEventTrack->GetActiveKey(ec.time, &key);
  78. if (nEventKey != m_lastEventKey && nEventKey >= 0)
  79. {
  80. bool bKeyAfterStartTime = key.time >= ec.startTime;
  81. if (bKeyAfterStartTime)
  82. {
  83. ec.sequence->TriggerTrackEvent(key.event.c_str(), key.eventValue.c_str());
  84. }
  85. }
  86. m_lastEventKey = nEventKey;
  87. }
  88. }
  89. }
  90. void CAnimEventNode::OnReset()
  91. {
  92. m_lastEventKey = -1;
  93. }
  94. //////////////////////////////////////////////////////////////////////////
  95. void CAnimEventNode::Reflect(AZ::ReflectContext* context)
  96. {
  97. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  98. {
  99. serializeContext->Class<CAnimEventNode, CAnimNode>()
  100. ->Version(1);
  101. }
  102. }