123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- /*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
- #include "EditorComponentBase.h"
- #include "TransformComponent.h"
- #include <AzCore/Math/Vector2.h>
- #include <AzCore/Serialization/SerializeContext.h>
- #include <AzToolsFramework/API/ToolsApplicationAPI.h>
- #include <AzToolsFramework/Entity/EditorEntityHelpers.h>
- DECLARE_EBUS_INSTANTIATION_WITH_TRAITS(AzToolsFramework::Components::EditorComponentDescriptor, AZ::ComponentDescriptorBusTraits);
- namespace AzToolsFramework
- {
- namespace Components
- {
- void EditorComponentBase::Reflect(AZ::ReflectContext* context)
- {
- AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
- if (serializeContext)
- {
- serializeContext->Class<EditorComponentBase, AZ::Component>()
- ->Version(1)
- ;
- }
- }
- EditorComponentBase::EditorComponentBase()
- {
- m_transform = nullptr;
- }
- void EditorComponentBase::Init()
- {
- }
- void EditorComponentBase::Activate()
- {
- m_transform = GetEntity()->FindComponent<TransformComponent>();
- }
- void EditorComponentBase::Deactivate()
- {
- m_transform = nullptr;
- }
- void EditorComponentBase::SetDirty()
- {
- if (GetEntity())
- {
- AzToolsFramework::ToolsApplicationRequests::Bus::Broadcast(
- &AzToolsFramework::ToolsApplicationRequests::Bus::Events::AddDirtyEntity, GetEntity()->GetId());
- }
- else
- {
- AZ_Warning("Editor", false, "EditorComponentBase::SetDirty() failed. Couldn't add dirty entity because the pointer to the entity is NULL. Make sure the entity is Init()'d properly.");
- }
- }
- AZ::TransformInterface* EditorComponentBase::GetTransform() const
- {
- AZ_Assert(m_transform, "Attempt to GetTransformComponent when the entity is inactive or does not have one.");
- return m_transform;
- }
- AZ::Transform EditorComponentBase::GetWorldTM() const
- {
- if (m_transform)
- {
- return m_transform->GetWorldTM();
- }
- else
- {
- return AZ::Transform::Identity();
- }
- }
- AZ::Transform EditorComponentBase::GetLocalTM() const
- {
- if (m_transform)
- {
- return m_transform->GetLocalTM();
- }
- else
- {
- return AZ::Transform::Identity();
- }
- }
- bool EditorComponentBase::IsSelected() const
- {
- return AzToolsFramework::IsSelected(GetEntityId());
- }
- void EditorComponentBase::SetSerializedIdentifier(AZStd::string alias)
- {
- m_alias = alias;
- }
- AZStd::string EditorComponentBase::GetSerializedIdentifier() const
- {
- return m_alias;
- }
- }
- } // namespace AzToolsFramework
|