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/Blast/Code/Source/Editor/EditorBlastFamilyComponent.cpp

136 lines
6.0 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 "StdAfx.h"
#include <Editor/EditorBlastFamilyComponent.h>
#include <AzCore/Serialization/EditContext.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzFramework/Physics/PhysicsSystem.h>
#include <Blast/BlastSystemBus.h>
#include <Components/BlastFamilyComponent.h>
namespace Blast
{
void EditorBlastFamilyComponent::Reflect(AZ::ReflectContext* context)
{
if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
{
serialize->Class<EditorBlastFamilyComponent, EditorComponentBase>()
->Version(1)
->Field("BlastAsset", &EditorBlastFamilyComponent::m_blastAsset)
->Field("BlastMaterial", &EditorBlastFamilyComponent::m_materialId)
->Field("PhysicsMaterial", &EditorBlastFamilyComponent::m_physicsMaterialId)
->Field("ActorConfiguration", &EditorBlastFamilyComponent::m_actorConfiguration);
if (AZ::EditContext* ec = serialize->GetEditContext())
{
ec->Class<EditorBlastFamilyComponent>(
"Blast Family", "Used to add a Blast family for destruction that will spawn Blast actors")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::Category, "Destruction")
->Attribute(AZ::Edit::Attributes::Icon, "Icons/Components/Box.png")
->Attribute(AZ::Edit::Attributes::ViewportIcon, "Icons/Components/Viewport/Box.png")
->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("Game", 0x232b318c))
->Attribute(
AZ::Edit::Attributes::HelpPageURL,
"https://docs.aws.amazon.com/lumberyard/latest/userguide/component-blast-actor.html")
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
->DataElement(
AZ::Edit::UIHandlers::Default, &EditorBlastFamilyComponent::m_blastAsset, "Blast asset",
"Assigned blast asset")
->DataElement(
AZ::Edit::UIHandlers::Default, &EditorBlastFamilyComponent::m_materialId, "Blast Material",
"Assigned blast material from current material library")
->ElementAttribute(
Attributes::BlastMaterialLibraryAssetId, &EditorBlastFamilyComponent::GetMaterialLibraryAssetId)
->DataElement(
AZ::Edit::UIHandlers::Default, &EditorBlastFamilyComponent::m_physicsMaterialId,
"Physics Material", "Assigned physics material from current physics material library")
->ElementAttribute(
Physics::Attributes::MaterialLibraryAssetId,
&EditorBlastFamilyComponent::GetPhysicsMaterialLibraryAssetId)
->DataElement(
AZ::Edit::UIHandlers::Default, &EditorBlastFamilyComponent::m_actorConfiguration,
"Actor configuration", "Configurations for actors in this family");
}
}
}
void EditorBlastFamilyComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
{
provided.push_back(AZ_CRC_CE("BlastFamilyService"));
}
void EditorBlastFamilyComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
{
required.push_back(AZ_CRC_CE("TransformService"));
}
void EditorBlastFamilyComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
{
dependent.push_back(AZ_CRC_CE("EditorVisibilityService"));
}
void EditorBlastFamilyComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
{
incompatible.push_back(AZ_CRC_CE("BlastFamilyService"));
}
void EditorBlastFamilyComponent::OnAssetReady(AZ::Data::Asset<AZ::Data::AssetData> asset)
{
AZ_Assert(asset.GetId() == m_blastAsset.GetId(), "Got OnAssetReady for something other than our blast asset.");
// Fill in our missing m_assetData on our reference
m_blastAsset = asset;
}
void EditorBlastFamilyComponent::OnAssetReloaded(AZ::Data::Asset<AZ::Data::AssetData> asset)
{
OnAssetReady(asset);
}
void EditorBlastFamilyComponent::Activate()
{
AZ_PROFILE_FUNCTION(AZ::Debug::ProfileCategory::System);
if (m_blastAsset.GetId().IsValid())
{
AZ::Data::AssetBus::MultiHandler::BusConnect(m_blastAsset.GetId());
m_blastAsset.QueueLoad();
}
}
void EditorBlastFamilyComponent::Deactivate()
{
AZ_PROFILE_FUNCTION(AZ::Debug::ProfileCategory::System);
AZ::Data::AssetBus::MultiHandler::BusDisconnect();
}
void EditorBlastFamilyComponent::BuildGameEntity(AZ::Entity* gameEntity)
{
gameEntity->CreateComponent<BlastFamilyComponent>(
m_blastAsset, m_materialId, m_physicsMaterialId, m_actorConfiguration);
}
AZ::Data::AssetId EditorBlastFamilyComponent::GetMaterialLibraryAssetId() const
{
return AZ::Interface<BlastSystemRequests>::Get()->GetGlobalConfiguration().m_materialLibrary.GetId();
}
AZ::Data::AssetId EditorBlastFamilyComponent::GetPhysicsMaterialLibraryAssetId() const
{
return AZ::Interface<AzPhysics::SystemInterface>::Get()->GetDefaultMaterialLibrary()->GetId();
}
} // namespace Blast