EditorEntityModelComponent.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 "EditorEntityModelComponent.h"
  9. #include <AzToolsFramework/Entity/EditorEntityModel.h>
  10. #include <AzCore/RTTI/BehaviorContext.h>
  11. namespace AzToolsFramework
  12. {
  13. namespace Components
  14. {
  15. EditorEntityModelComponent::EditorEntityModelComponent() = default;
  16. EditorEntityModelComponent::~EditorEntityModelComponent() = default;
  17. void EditorEntityModelComponent::Reflect(AZ::ReflectContext* context)
  18. {
  19. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  20. {
  21. serializeContext->Class<EditorEntityModelComponent, AZ::Component>(); // Empty class
  22. }
  23. if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  24. {
  25. behaviorContext->EBus<EditorEntityInfoRequestBus>("EditorEntityInfoRequestBus")
  26. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
  27. ->Attribute(AZ::Script::Attributes::Category, "Entity")
  28. ->Attribute(AZ::Script::Attributes::Module, "editor")
  29. ->Event("GetParent", &EditorEntityInfoRequests::GetParent)
  30. ->Event("GetChildren", &EditorEntityInfoRequests::GetChildren)
  31. ->Event("GetChild", &EditorEntityInfoRequests::GetChild)
  32. ->Event("GetChildCount", &EditorEntityInfoRequests::GetChildCount)
  33. ->Event("GetChildIndex", &EditorEntityInfoRequests::GetChildIndex)
  34. ->Event("GetName", &EditorEntityInfoRequests::GetName)
  35. ->Event("IsLocked", &EditorEntityInfoRequests::IsLocked)
  36. ->Event("IsVisible", &EditorEntityInfoRequests::IsVisible)
  37. ->Event("IsHidden", &EditorEntityInfoRequests::IsHidden)
  38. ->Event("GetStartStatus", &EditorEntityInfoRequests::GetStartStatus)
  39. ;
  40. behaviorContext->EBus<EditorEntityAPIBus>("EditorEntityAPIBus")
  41. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
  42. ->Attribute(AZ::Script::Attributes::Category, "Entity")
  43. ->Attribute(AZ::Script::Attributes::Module, "editor")
  44. ->Event("SetName", &EditorEntityAPIRequests::SetName)
  45. ->Event("SetParent", &EditorEntityAPIRequests::SetParent)
  46. ->Event("SetLockState", &EditorEntityAPIRequests::SetLockState)
  47. ->Event("SetVisibilityState", &EditorEntityAPIRequests::SetVisibilityState)
  48. ->Event("SetStartStatus", &EditorEntityAPIRequests::SetStartStatus)
  49. ;
  50. behaviorContext->EnumProperty<static_cast<int>(EditorEntityStartStatus::StartActive)>("EditorEntityStartStatus_StartActive")
  51. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation);
  52. behaviorContext->EnumProperty<static_cast<int>(EditorEntityStartStatus::StartInactive)>("EditorEntityStartStatus_StartInactive")
  53. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation);
  54. behaviorContext->EnumProperty<static_cast<int>(EditorEntityStartStatus::EditorOnly)>("EditorEntityStartStatus_EditorOnly")
  55. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation);
  56. }
  57. }
  58. void EditorEntityModelComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& services)
  59. {
  60. services.push_back(AZ_CRC_CE("EditorEntityModelService"));
  61. }
  62. void EditorEntityModelComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& services)
  63. {
  64. services.push_back(AZ_CRC_CE("EditorEntityModelService"));
  65. }
  66. void EditorEntityModelComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& services)
  67. {
  68. services.push_back(AZ_CRC_CE("EditorEntityContextService"));
  69. }
  70. void EditorEntityModelComponent::Activate()
  71. {
  72. m_entityModel = AZStd::make_unique<EditorEntityModel>();
  73. }
  74. void EditorEntityModelComponent::Deactivate()
  75. {
  76. m_entityModel.reset();
  77. }
  78. } // namespace Components
  79. } // namespace AzToolsFramework