3
0

Editor${Name}Component.cpp 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 <Tools/Components/Editor${Name}Component.h>
  9. #include <AzFramework/StringFunc/StringFunc.h>
  10. #include <AzToolsFramework/API/ToolsApplicationAPI.h>
  11. #include <AzToolsFramework/Entity/EditorEntityInfoBus.h>
  12. #include <AzToolsFramework/API/EditorAssetSystemAPI.h>
  13. #include <AzCore/Component/Entity.h>
  14. #include <AzCore/IO/SystemFile.h>
  15. namespace ${Name}
  16. {
  17. void Editor${Name}Component::Reflect(AZ::ReflectContext* context)
  18. {
  19. BaseClass::Reflect(context);
  20. if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  21. {
  22. serializeContext->Class<Editor${Name}Component, BaseClass>()
  23. ;
  24. if (AZ::EditContext* editContext = serializeContext->GetEditContext())
  25. {
  26. editContext->Class<Editor${Name}Component>(
  27. "${Name}", "The ${Name} component")
  28. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  29. ->Attribute(AZ::Edit::Attributes::Category, "Graphics")
  30. ->Attribute(AZ::Edit::Attributes::Icon, "Icons/Components/Component_Placeholder.svg")
  31. ->Attribute(AZ::Edit::Attributes::ViewportIcon, "Icons/Components/Viewport/Component_Placeholder.svg")
  32. ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("Game"))
  33. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  34. ->Attribute(AZ::Edit::Attributes::HelpPageURL, "")
  35. ;
  36. }
  37. }
  38. if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  39. {
  40. behaviorContext->ConstantProperty(${Name}EditorSystemComponentTypeId, BehaviorConstant(AZ::Uuid(${Name}EditorSystemComponentTypeId)))
  41. ->Attribute(AZ::Script::Attributes::Module, "render")
  42. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation);
  43. }
  44. }
  45. Editor${Name}Component::Editor${Name}Component()
  46. {
  47. }
  48. Editor${Name}Component::Editor${Name}Component(const ${Name}ComponentConfig& config)
  49. : BaseClass(config)
  50. {
  51. }
  52. void Editor${Name}Component::Activate()
  53. {
  54. BaseClass::Activate();
  55. AzFramework::EntityDebugDisplayEventBus::Handler::BusConnect(GetEntityId());
  56. AzToolsFramework::EditorComponentSelectionRequestsBus::Handler::BusConnect(GetEntityId());
  57. AZ::TickBus::Handler::BusConnect();
  58. AzToolsFramework::EditorEntityInfoNotificationBus::Handler::BusConnect();
  59. AZ::u64 entityId = (AZ::u64)GetEntityId();
  60. m_controller.m_configuration.m_entityId = entityId;
  61. }
  62. void Editor${Name}Component::Deactivate()
  63. {
  64. AzToolsFramework::EditorEntityInfoNotificationBus::Handler::BusDisconnect();
  65. AZ::TickBus::Handler::BusDisconnect();
  66. AzToolsFramework::EditorComponentSelectionRequestsBus::Handler::BusDisconnect();
  67. AzFramework::EntityDebugDisplayEventBus::Handler::BusDisconnect();
  68. BaseClass::Deactivate();
  69. }
  70. void Editor${Name}Component::OnTick([[maybe_unused]] float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time)
  71. {
  72. if (!m_controller.m_featureProcessor)
  73. {
  74. return;
  75. }
  76. }
  77. }