SoftNameBehavior.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 <Config/SceneProcessingConfigBus.h>
  10. #include <Config/Components/SoftNameBehavior.h>
  11. #include <Config/SettingsObjects/SoftNameSetting.h>
  12. namespace AZ
  13. {
  14. namespace SceneProcessingConfig
  15. {
  16. void SoftNameBehavior::Activate()
  17. {
  18. SceneAPI::Events::GraphMetaInfoBus::Handler::BusConnect();
  19. }
  20. void SoftNameBehavior::Deactivate()
  21. {
  22. SceneAPI::Events::GraphMetaInfoBus::Handler::BusDisconnect();
  23. }
  24. void SoftNameBehavior::GetVirtualTypes(
  25. SceneAPI::Events::GraphMetaInfo::VirtualTypesSet& types,
  26. const SceneAPI::Containers::Scene& scene,
  27. SceneAPI::Containers::SceneGraph::NodeIndex node)
  28. {
  29. const AZStd::vector<AZStd::unique_ptr<SoftNameSetting>>* softNames = nullptr;
  30. SceneProcessingConfigRequestBus::BroadcastResult(softNames, &SceneProcessingConfigRequestBus::Events::GetSoftNames);
  31. if (softNames)
  32. {
  33. for (const AZStd::unique_ptr<SoftNameSetting>& softName : *softNames)
  34. {
  35. if (types.find(softName->GetVirtualTypeHash()) != types.end())
  36. {
  37. // This type has already been added.
  38. continue;
  39. }
  40. if (softName->IsVirtualType(scene, node))
  41. {
  42. types.insert(softName->GetVirtualTypeHash());
  43. }
  44. }
  45. }
  46. }
  47. void SoftNameBehavior::GetVirtualTypeName(AZStd::string& name, Crc32 type)
  48. {
  49. if (type == AZ_CRC_CE("Ignore"))
  50. {
  51. name = "Ignore";
  52. }
  53. }
  54. void SoftNameBehavior::GetAllVirtualTypes(SceneAPI::Events::GraphMetaInfo::VirtualTypesSet& types)
  55. {
  56. // Add types that aren't handled by one specific behavior and have a more global utility.
  57. if (types.find(AZ_CRC_CE("Ignore")) == types.end())
  58. {
  59. types.insert(AZ_CRC_CE("Ignore"));
  60. }
  61. }
  62. void SoftNameBehavior::Reflect(ReflectContext* context)
  63. {
  64. SerializeContext* serializeContext = azrtti_cast<SerializeContext*>(context);
  65. if (serializeContext)
  66. {
  67. serializeContext->Class<SoftNameBehavior, BehaviorComponent>()->Version(1);
  68. }
  69. }
  70. } // namespace SceneProcessingConfig
  71. } // namespace AZ