You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
o3de/Gems/PhysX/Code/Source/EditorFixedJointComponent.cpp

100 lines
4.4 KiB
C++

/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <PhysX_precompiled.h>
#include <AzCore/Component/TransformBus.h>
#include <AzCore/Math/IntersectSegment.h>
#include <AzCore/Serialization/EditContext.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzToolsFramework/ViewportSelection/EditorSelectionUtil.h>
#include <Source/EditorFixedJointComponent.h>
#include <Editor/EditorJointComponentMode.h>
#include <Source/FixedJointComponent.h>
namespace PhysX
{
void EditorFixedJointComponent::Reflect(AZ::ReflectContext* context)
{
if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<EditorFixedJointComponent, EditorJointComponent>()
->Version(2)
->Field("Component Mode", &EditorFixedJointComponent::m_componentModeDelegate)
;
if (auto* editContext = serializeContext->GetEditContext())
{
editContext->Class<EditorFixedJointComponent>(
"PhysX Fixed Joint", "The fixed joint constraints the position and orientation of a body to another.")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::Category, "PhysX")
->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("Game", 0x232b318c))
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
->DataElement(AZ::Edit::UIHandlers::Default, &EditorFixedJointComponent::m_componentModeDelegate, "Component Mode", "Fixed Joint Component Mode")
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
;
}
}
}
void EditorFixedJointComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
{
provided.push_back(AZ_CRC("PhysXJointService", 0x0d2f906f));
}
void EditorFixedJointComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
{
required.push_back(AZ_CRC("TransformService", 0x8ee22c50));
required.push_back(AZ_CRC("PhysXColliderService", 0x4ff43f7c));
required.push_back(AZ_CRC("PhysXRigidBodyService", 0x1d4c64a8));
}
void EditorFixedJointComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
{
incompatible.push_back(AZ_CRC_CE("NonUniformScaleService"));
}
void EditorFixedJointComponent::Activate()
{
EditorJointComponent::Activate();
const AZ::EntityId entityId = GetEntityId();
AzToolsFramework::EditorComponentSelectionRequestsBus::Handler::BusConnect(entityId);
AzToolsFramework::EditorComponentSelectionNotificationsBus::Handler::BusConnect(entityId);
AzToolsFramework::EditorComponentSelectionRequestsBus::Handler* selection = this;
m_componentModeDelegate.ConnectWithSingleComponentMode <
EditorFixedJointComponent, EditorFixedJointComponentMode>(
AZ::EntityComponentIdPair(entityId, GetId()), selection);
PhysX::EditorJointRequestBus::Handler::BusConnect(AZ::EntityComponentIdPair(entityId, GetId()));
}
void EditorFixedJointComponent::Deactivate()
{
PhysX::EditorJointRequestBus::Handler::BusDisconnect();
m_componentModeDelegate.Disconnect();
AzToolsFramework::EditorComponentSelectionNotificationsBus::Handler::BusDisconnect();
AzToolsFramework::EditorComponentSelectionRequestsBus::Handler::BusDisconnect();
EditorJointComponent::Deactivate();
}
void EditorFixedJointComponent::BuildGameEntity(AZ::Entity* gameEntity)
{
m_config.m_followerEntity = GetEntityId(); // joint is always in the same entity as the follower body.
gameEntity->CreateComponent<FixedJointComponent>(m_config.ToGameTimeConfig());
}
}