EventNode.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 <ISystem.h>
  13. //////////////////////////////////////////////////////////////////////////
  14. CUiAnimEventNode::CUiAnimEventNode()
  15. : CUiAnimEventNode(0)
  16. {
  17. }
  18. //////////////////////////////////////////////////////////////////////////
  19. CUiAnimEventNode::CUiAnimEventNode(const int id)
  20. : CUiAnimNode(id, eUiAnimNodeType_Event)
  21. {
  22. SetFlags(GetFlags() | eUiAnimNodeFlags_CanChangeName);
  23. m_lastEventKey = -1;
  24. }
  25. //////////////////////////////////////////////////////////////////////////
  26. void CUiAnimEventNode::CreateDefaultTracks()
  27. {
  28. CreateTrack(eUiAnimParamType_TrackEvent);
  29. }
  30. //////////////////////////////////////////////////////////////////////////
  31. unsigned int CUiAnimEventNode::GetParamCount() const
  32. {
  33. return 1;
  34. }
  35. //////////////////////////////////////////////////////////////////////////
  36. CUiAnimParamType CUiAnimEventNode::GetParamType(unsigned int nIndex) const
  37. {
  38. if (nIndex == 0)
  39. {
  40. return eUiAnimParamType_TrackEvent;
  41. }
  42. return eUiAnimParamType_Invalid;
  43. }
  44. //////////////////////////////////////////////////////////////////////////
  45. bool CUiAnimEventNode::GetParamInfoFromType(const CUiAnimParamType& animParamType, SParamInfo& info) const
  46. {
  47. if (animParamType.GetType() == eUiAnimParamType_TrackEvent)
  48. {
  49. info.flags = IUiAnimNode::ESupportedParamFlags(0);
  50. info.name = "Track Event";
  51. info.paramType = eUiAnimParamType_TrackEvent;
  52. info.valueType = eUiAnimValue_Unknown;
  53. return true;
  54. }
  55. return false;
  56. }
  57. //////////////////////////////////////////////////////////////////////////
  58. void CUiAnimEventNode::Animate(SUiAnimContext& ec)
  59. {
  60. // Get track event
  61. int trackCount = NumTracks();
  62. for (int paramIndex = 0; paramIndex < trackCount; paramIndex++)
  63. {
  64. IUiAnimTrack* track = m_tracks[paramIndex].get();
  65. if (track && track->GetFlags() & IUiAnimTrack::eUiAnimTrackFlags_Disabled)
  66. {
  67. continue;
  68. }
  69. // Check for fire
  70. if (CUiTrackEventTrack* pEventTrack = (CUiTrackEventTrack*)track)
  71. {
  72. IEventKey key;
  73. int nEventKey = pEventTrack->GetActiveKey(ec.time, &key);
  74. if (nEventKey != m_lastEventKey && nEventKey >= 0)
  75. {
  76. bool bKeyAfterStartTime = key.time >= ec.startTime;
  77. if (bKeyAfterStartTime)
  78. {
  79. ec.pSequence->TriggerTrackEvent(key.event.c_str(), key.eventValue.c_str());
  80. }
  81. }
  82. m_lastEventKey = nEventKey;
  83. }
  84. }
  85. }
  86. void CUiAnimEventNode::OnReset()
  87. {
  88. m_lastEventKey = -1;
  89. }
  90. //////////////////////////////////////////////////////////////////////////
  91. void CUiAnimEventNode::Reflect(AZ::SerializeContext* serializeContext)
  92. {
  93. serializeContext->Class<CUiAnimEventNode, CUiAnimNode>()
  94. ->Version(1);
  95. }