SoftNameBehavior.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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(AZStd::set<Crc32>& types, const SceneAPI::Containers::Scene& scene,
  25. SceneAPI::Containers::SceneGraph::NodeIndex node)
  26. {
  27. const AZStd::vector<AZStd::unique_ptr<SoftNameSetting>>* softNames = nullptr;
  28. SceneProcessingConfigRequestBus::BroadcastResult(softNames, &SceneProcessingConfigRequestBus::Events::GetSoftNames);
  29. if (softNames)
  30. {
  31. for (const AZStd::unique_ptr<SoftNameSetting>& softName : *softNames)
  32. {
  33. if (types.find(softName->GetVirtualTypeHash()) != types.end())
  34. {
  35. // This type has already been added.
  36. continue;
  37. }
  38. if (softName->IsVirtualType(scene, node))
  39. {
  40. types.insert(softName->GetVirtualTypeHash());
  41. }
  42. }
  43. }
  44. }
  45. void SoftNameBehavior::GetVirtualTypeName(AZStd::string& name, Crc32 type)
  46. {
  47. if (type == AZ_CRC("Ignore", 0x0d88d6e2))
  48. {
  49. name = "Ignore";
  50. }
  51. }
  52. void SoftNameBehavior::GetAllVirtualTypes(AZStd::set<Crc32>& types)
  53. {
  54. // Add types that aren't handled by one specific behavior and have a more global utility.
  55. if (types.find(AZ_CRC("Ignore", 0x0d88d6e2)) == types.end())
  56. {
  57. types.insert(AZ_CRC("Ignore", 0x0d88d6e2));
  58. }
  59. }
  60. void SoftNameBehavior::Reflect(ReflectContext* context)
  61. {
  62. SerializeContext* serializeContext = azrtti_cast<SerializeContext*>(context);
  63. if (serializeContext)
  64. {
  65. serializeContext->Class<SoftNameBehavior, BehaviorComponent>()->Version(1);
  66. }
  67. }
  68. } // namespace SceneProcessingConfig
  69. } // namespace AZ