ScriptVarNode.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 "ScriptVarNode.h"
  10. #include "AnimTrack.h"
  11. #include "Maestro/Types/AnimNodeType.h"
  12. #include "Maestro/Types/AnimValueType.h"
  13. #include "Maestro/Types/AnimParamType.h"
  14. #include <ISystem.h>
  15. //////////////////////////////////////////////////////////////////////////
  16. CAnimScriptVarNode::CAnimScriptVarNode(const int id)
  17. : CAnimNode(id, AnimNodeType::ScriptVar)
  18. {
  19. SetFlags(GetFlags() | eAnimNodeFlags_CanChangeName);
  20. m_value = -1e-20f;
  21. }
  22. //////////////////////////////////////////////////////////////////////////
  23. CAnimScriptVarNode::CAnimScriptVarNode()
  24. : CAnimScriptVarNode(0)
  25. {
  26. }
  27. void CAnimScriptVarNode::OnReset()
  28. {
  29. m_value = -1e-20f;
  30. }
  31. void CAnimScriptVarNode::OnResume()
  32. {
  33. OnReset();
  34. }
  35. //////////////////////////////////////////////////////////////////////////
  36. void CAnimScriptVarNode::CreateDefaultTracks()
  37. {
  38. CreateTrack(AnimParamType::Float);
  39. };
  40. //////////////////////////////////////////////////////////////////////////
  41. unsigned int CAnimScriptVarNode::GetParamCount() const
  42. {
  43. return 1;
  44. }
  45. //////////////////////////////////////////////////////////////////////////
  46. CAnimParamType CAnimScriptVarNode::GetParamType(unsigned int nIndex) const
  47. {
  48. if (nIndex == 0)
  49. {
  50. return AnimParamType::Float;
  51. }
  52. return AnimParamType::Invalid;
  53. }
  54. //////////////////////////////////////////////////////////////////////////
  55. bool CAnimScriptVarNode::GetParamInfoFromType(const CAnimParamType& paramId, SParamInfo& info) const
  56. {
  57. if (paramId.GetType() == AnimParamType::Float)
  58. {
  59. info.flags = IAnimNode::ESupportedParamFlags(0);
  60. info.name = "Value";
  61. info.paramType = AnimParamType::Float;
  62. info.valueType = AnimValueType::Float;
  63. return true;
  64. }
  65. return false;
  66. }
  67. //////////////////////////////////////////////////////////////////////////
  68. void CAnimScriptVarNode::Animate(SAnimContext& ec)
  69. {
  70. float value = m_value;
  71. IAnimTrack* pValueTrack = GetTrackForParameter(AnimParamType::Float);
  72. if (pValueTrack)
  73. {
  74. if (pValueTrack->GetFlags() & IAnimTrack::eAnimTrackFlags_Disabled)
  75. {
  76. return;
  77. }
  78. pValueTrack->GetValue(ec.time, value);
  79. }
  80. if (value != m_value)
  81. {
  82. m_value = value;
  83. }
  84. }
  85. void CAnimScriptVarNode::Reflect(AZ::ReflectContext* context)
  86. {
  87. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  88. {
  89. serializeContext->Class<CAnimScriptVarNode, CAnimNode>()
  90. ->Version(1);
  91. }
  92. }