Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,118 @@
/*
* 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.
*
*/
#pragma once
#include <AzCore/EBus/EBus.h>
#include <AzCore/Component/ComponentBus.h>
#include <AzFramework/Entity/BehaviorEntity.h>
#include <AzToolsFramework/PropertyTreeEditor/PropertyTreeEditor.h>
namespace AzToolsFramework
{
//! Exposes the Editor Component CRUD API; it is exposed to Behavior Context for Editor Scripting.
class EditorComponentAPIRequests
: public AZ::EBusTraits
{
public:
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
enum class EntityType
{
Game,
System,
Layer,
Level
};
//! This method requires the filter @entityType because it is possible that two components
//! With different uuids to have the same name. But, the chances of collision is reduced by specifying
//! the entity type.
virtual AZStd::vector<AZ::Uuid> FindComponentTypeIdsByEntityType(const AZStd::vector<AZStd::string>& componentTypeNames, EntityType entityType) = 0;
//! Finds the component names from their type ids
virtual AZStd::vector<AZStd::string> FindComponentTypeNames(const AZ::ComponentTypeList& componentTypeIds) = 0;
//! Returns the full list of names for all components that can be created for the given Entity type (aka type of Menu).
virtual AZStd::vector<AZStd::string> BuildComponentTypeNameListByEntityType(EntityType entityType) = 0;
using AddComponentsOutcome = AZ::Outcome<AZStd::vector<AZ::EntityComponentIdPair>, AZStd::string>;
//! Add Components of the given types to an Entity.
// Returns an Outcome object - it contains the AZ::EntityComponentIdPairs in case of Success, or an error message in case or Failure.
virtual AddComponentsOutcome AddComponentsOfType(AZ::EntityId entityId, const AZ::ComponentTypeList& componentTypeIds) = 0;
//! Add a single component of a given type to an Entity.
// Returns an Outcome object - it contains a AZ::EntityComponentIdPair in case of Success, or an error message in case or Failure.
virtual AddComponentsOutcome AddComponentOfType(AZ::EntityId entityId, const AZ::Uuid& componentTypeId) = 0;
//! Returns true if a Component of type provided can be found on Entity, false otherwise.
virtual bool HasComponentOfType(AZ::EntityId entityId, AZ::Uuid componentTypeId) = 0;
//! Count Components of type provided on the Entity.
virtual size_t CountComponentsOfType(AZ::EntityId entityId, AZ::Uuid componentTypeId) = 0;
using GetComponentOutcome = AZ::Outcome<AZ::EntityComponentIdPair, AZStd::string>;
//! Get Component of type from Entity.
// Only returns first component of type if found (early out).
// Returns an Outcome object - it contains the AZ::EntityComponentIdPair in case of Success, or an error message in case or Failure.
virtual GetComponentOutcome GetComponentOfType(AZ::EntityId entityId, AZ::Uuid componentTypeId) = 0;
using GetComponentsOutcome = AZ::Outcome<AZStd::vector<AZ::EntityComponentIdPair>, AZStd::string>;
//! Get all Components of type from Entity.
// Returns vector of ComponentIds, or an empty vector if components could not be found.
virtual GetComponentsOutcome GetComponentsOfType(AZ::EntityId entityId, AZ::Uuid componentTypeId) = 0;
//! Verify if component instance referenced by AZ::EntityComponentIdPair is valid.
virtual bool IsValid(AZ::EntityComponentIdPair componentInstance) = 0;
//! Enable Components on Entity by AZ::EntityComponentIdPair. Returns true if the operation was successful, false otherwise.
virtual bool EnableComponents(const AZStd::vector<AZ::EntityComponentIdPair>& componentInstances) = 0;
//! Returns true if the Component is active.
virtual bool IsComponentEnabled(const AZ::EntityComponentIdPair& componentInstance) = 0;
//! Disable Components on Entity by AZ::EntityComponentIdPair. Returns true if the operation was successful, false otherwise.
virtual bool DisableComponents(const AZStd::vector<AZ::EntityComponentIdPair>& componentInstances) = 0;
//! Remove Components from Entity by AZ::EntityComponentIdPair. Returns true if the operation was successful, false otherwise.
virtual bool RemoveComponents(const AZStd::vector<AZ::EntityComponentIdPair>& componentInstances) = 0;
using PropertyTreeOutcome = AZ::Outcome<PropertyTreeEditor, AZStd::string>;
//! Get the PropertyTreeEditor for the Component Instance provided.
virtual PropertyTreeOutcome BuildComponentPropertyTreeEditor(const AZ::EntityComponentIdPair& componentInstance) = 0;
using PropertyOutcome = AZ::Outcome<AZStd::any, AZStd::string>;
//! Get Value of Property on Component
virtual PropertyOutcome GetComponentProperty(const AZ::EntityComponentIdPair& componentInstance, const AZStd::string_view propertyPath) = 0;
//! Set Value of Property on Component
//! If @param value is an AZStd::any then the logic will set the property to a default value
virtual PropertyOutcome SetComponentProperty(const AZ::EntityComponentIdPair& componentInstance, const AZStd::string_view propertyPath, const AZStd::any& value) = 0;
//! Compare Value of Property on Component
virtual bool CompareComponentProperty(const AZ::EntityComponentIdPair& componentInstance, const AZStd::string_view propertyPath, const AZStd::any& value) = 0;
//! Get a full list of Component Properties for the Component Entity provided
virtual const AZStd::vector<AZStd::string> BuildComponentPropertyList(const AZ::EntityComponentIdPair& componentInstance) = 0;
//! Toggles the usage of visible enforcement logic (defaults to False)
virtual void SetVisibleEnforcement(bool enforceVisiblity) = 0;
};
using EditorComponentAPIBus = AZ::EBus<EditorComponentAPIRequests>;
}
@@ -0,0 +1,770 @@
/*
* 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 <AzToolsFramework/Component/EditorComponentAPIComponent.h>
#include <AzCore/RTTI/BehaviorContext.h>
#include <AzCore/Serialization/Utils.h>
#include <AzToolsFramework/API/EntityCompositionRequestBus.h>
#include <AzToolsFramework/ToolsComponents/EditorDisabledCompositionBus.h>
#include <AzToolsFramework/ToolsComponents/EditorPendingCompositionBus.h>
#include <AzToolsFramework/Entity/EditorEntityActionComponent.h>
#include <AzToolsFramework/UI/PropertyEditor/InstanceDataHierarchy.h>
#include <AzToolsFramework/UI/PropertyEditor/PropertyEditorAPI.h>
namespace AzToolsFramework
{
namespace Components
{
//! Helper class for scripting.
//! Use it to provide the right enum value when
//! calling EditorComponentAPIRequests::BuildComponentTypeNameListByEntityType or EditorComponentAPIRequests::FindComponentTypeIdsByEntityType
//! example of Python code:
//! #-------------------------------------------------------------------
//! import azlmbr.bus as bus
//! import azlmbr.editor as editor
//! from azlmbr.entity import EntityType
//! levelComponentsList = editor.EditorComponentAPIBus(bus.Broadcast, 'BuildComponentTypeNameListByEntityType', EntityType().Level)
//! gameComponentsList = editor.EditorComponentAPIBus(bus.Broadcast, 'BuildComponentTypeNameListByEntityType', EntityType().Game)
//! #-------------------------------------------------------------------
class EditorEntityType final
{
public:
AZ_CLASS_ALLOCATOR(EditorEntityType, AZ::SystemAllocator, 0);
AZ_RTTI(EditorEntityType, "{9761CD58-D86E-4EA1-AE67-5302AECD54A4}");
EditorEntityType() = default;
~EditorEntityType() = default;
static void ReflectContext(AZ::ReflectContext* context)
{
if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
{
behaviorContext->Class<EditorEntityType>("EntityType")
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
->Attribute(AZ::Script::Attributes::Category, "Components")
->Attribute(AZ::Script::Attributes::Module, "entity")
->Constructor()
->Constant("Game", &EditorEntityType::Game)
->Constant("System", &EditorEntityType::System)
->Constant("Layer", &EditorEntityType::Layer)
->Constant("Level", &EditorEntityType::Level)
;
}
}
EditorComponentAPIRequests::EntityType Game() { return EditorComponentAPIRequests::EntityType::Game; }
EditorComponentAPIRequests::EntityType System() { return EditorComponentAPIRequests::EntityType::System; }
EditorComponentAPIRequests::EntityType Layer() { return EditorComponentAPIRequests::EntityType::Layer; }
EditorComponentAPIRequests::EntityType Level() { return EditorComponentAPIRequests::EntityType::Level; }
};
void EditorComponentAPIComponent::Reflect(AZ::ReflectContext* context)
{
EditorEntityType::ReflectContext(context);
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<EditorComponentAPIComponent, AZ::Component>();
serializeContext->RegisterGenericType<AZStd::vector<AZ::EntityComponentIdPair>>();
}
if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
{
behaviorContext->Class<AZ::EntityComponentIdPair>("EntityComponentIdPair")
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
->Attribute(AZ::Script::Attributes::Category, "Components")
->Attribute(AZ::Script::Attributes::Module, "entity")
->Method("GetEntityId", &AZ::EntityComponentIdPair::GetEntityId)
->Attribute(AZ::Script::Attributes::Alias, "get_entity_id")
->Method("Equal", &AZ::EntityComponentIdPair::operator==)
->Attribute(AZ::Script::Attributes::Operator, AZ::Script::Attributes::OperatorType::Equal)
->Method("ToString", [](const AZ::EntityComponentIdPair* self) {
return AZStd::string::format("[ %s - %s ]", self->GetEntityId().ToString().c_str(), AZStd::to_string(self->GetComponentId()).c_str());
})
->Attribute(AZ::Script::Attributes::Alias, "to_string")
;
behaviorContext->EBus<EditorComponentAPIBus>("EditorComponentAPIBus")
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
->Attribute(AZ::Script::Attributes::Category, "Components")
->Attribute(AZ::Script::Attributes::Module, "editor")
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::All)
->Event("FindComponentTypeIdsByEntityType", &EditorComponentAPIRequests::FindComponentTypeIdsByEntityType)
->Event("FindComponentTypeNames", &EditorComponentAPIRequests::FindComponentTypeNames)
->Event("BuildComponentTypeNameListByEntityType", &EditorComponentAPIRequests::BuildComponentTypeNameListByEntityType)
->Event("AddComponentsOfType", &EditorComponentAPIRequests::AddComponentsOfType)
->Event("AddComponentOfType", &EditorComponentAPIRequests::AddComponentOfType)
->Event("HasComponentOfType", &EditorComponentAPIRequests::HasComponentOfType)
->Event("CountComponentsOfType", &EditorComponentAPIRequests::CountComponentsOfType)
->Event("GetComponentOfType", &EditorComponentAPIRequests::GetComponentOfType)
->Event("GetComponentsOfType", &EditorComponentAPIRequests::GetComponentsOfType)
->Event("IsValid", &EditorComponentAPIRequests::IsValid)
->Event("EnableComponents", &EditorComponentAPIRequests::EnableComponents)
->Event("IsComponentEnabled", &EditorComponentAPIRequests::IsComponentEnabled)
->Event("DisableComponents", &EditorComponentAPIRequests::DisableComponents)
->Event("RemoveComponents", &EditorComponentAPIRequests::RemoveComponents)
->Event("BuildComponentPropertyTreeEditor", &EditorComponentAPIRequests::BuildComponentPropertyTreeEditor)
->Event("GetComponentProperty", &EditorComponentAPIRequests::GetComponentProperty)
->Event("SetComponentProperty", &EditorComponentAPIRequests::SetComponentProperty)
->Event("CompareComponentProperty", &EditorComponentAPIRequests::CompareComponentProperty)
->Event("BuildComponentPropertyList", &EditorComponentAPIRequests::BuildComponentPropertyList)
->Event("SetVisibleEnforcement", &EditorComponentAPIRequests::SetVisibleEnforcement)
;
}
}
void EditorComponentAPIComponent::Activate()
{
EditorComponentAPIBus::Handler::BusConnect();
AZ::ComponentApplicationBus::BroadcastResult(m_serializeContext, &AZ::ComponentApplicationRequests::GetSerializeContext);
AZ_Error("Editor", m_serializeContext, "Serialize context not available");
}
void EditorComponentAPIComponent::Deactivate()
{
EditorComponentAPIBus::Handler::BusDisconnect();
}
void EditorComponentAPIComponent::SetVisibleEnforcement(bool enforceVisiblity)
{
m_usePropertyVisibility = enforceVisiblity;
}
AZStd::vector<AZ::Uuid> EditorComponentAPIComponent::FindComponentTypeIdsByEntityType(const AZStd::vector<AZStd::string>& componentTypeNames, EditorComponentAPIRequests::EntityType entityType)
{
AZStd::vector<AZ::Uuid> foundTypeIds;
size_t typesCount = componentTypeNames.size();
size_t counter = 0;
foundTypeIds.resize(typesCount, AZ::Uuid::CreateNull());
m_serializeContext->EnumerateDerived<AZ::Component>(
[&counter, typesCount, componentTypeNames, &foundTypeIds, entityType](const AZ::SerializeContext::ClassData* componentClass, const AZ::Uuid& knownType) -> bool
{
(void)knownType;
if (componentClass->m_editData)
{
switch (entityType)
{
case EditorComponentAPIRequests::EntityType::Game:
if (!AzToolsFramework::AppearsInGameComponentMenu(*componentClass))
{
return true;
}
break;
case EditorComponentAPIRequests::EntityType::Level:
if (!AzToolsFramework::AppearsInLevelComponentMenu(*componentClass))
{
return true;
}
break;
case EditorComponentAPIRequests::EntityType::Layer:
if (!AzToolsFramework::AppearsInLayerComponentMenu(*componentClass))
{
return true;
}
break;
default:
if (!AzToolsFramework::AppearsInSystemComponentMenu(*componentClass))
{
return true;
}
break;
}
for (int i = 0; i < typesCount; ++i)
{
if (componentClass->m_editData->m_name == componentTypeNames[i])
{
foundTypeIds[i] = componentClass->m_typeId;
++counter;
//Although it is rare, it can happen that two components can have the same name.
//We will capture only the first occurrence.
return true;
}
}
if (counter >= typesCount)
{
return false;
}
}
return true;
});
AZ_Warning("EditorComponentAPI", (counter >= typesCount), "FindComponentTypeIds - Not all Type Names provided could be converted to Type Ids.");
return foundTypeIds;
}
AZStd::vector<AZStd::string> EditorComponentAPIComponent::FindComponentTypeNames(const AZ::ComponentTypeList& componentTypeIds)
{
AZStd::vector<AZStd::string> foundTypeNames;
size_t typesCount = componentTypeIds.size();
size_t counter = 0;
foundTypeNames.resize(typesCount);
m_serializeContext->EnumerateDerived<AZ::Component>(
[&counter, typesCount, componentTypeIds, &foundTypeNames](const AZ::SerializeContext::ClassData* componentClass, const AZ::Uuid& knownType) -> bool
{
(void)knownType;
if (componentClass->m_editData)
{
for (int i = 0; i < typesCount; ++i)
{
if (componentClass->m_typeId == componentTypeIds[i])
{
foundTypeNames[i] = componentClass->m_editData->m_name;
++counter;
}
}
if (counter >= typesCount)
{
return false;
}
}
return true;
});
AZ_Warning("EditorComponentAPI", (counter >= typesCount), "FindComponentTypeNames - Not all Type Ids provided could be converted to Type Names.");
return foundTypeNames;
}
AZStd::vector<AZStd::string> EditorComponentAPIComponent::BuildComponentTypeNameListByEntityType(EditorComponentAPIRequests::EntityType entityType)
{
AZStd::vector<AZStd::string> typeNameList;
m_serializeContext->EnumerateDerived<AZ::Component>(
[&typeNameList, entityType](const AZ::SerializeContext::ClassData* componentClass, const AZ::Uuid& knownType) -> bool
{
AZ_UNUSED(knownType)
if (!componentClass->m_editData)
{
return true;
}
switch (entityType)
{
case EditorComponentAPIRequests::EntityType::Game:
if (AzToolsFramework::AppearsInGameComponentMenu(*componentClass))
{
typeNameList.push_back(componentClass->m_editData->m_name);
}
break;
case EditorComponentAPIRequests::EntityType::Level:
if (AzToolsFramework::AppearsInLevelComponentMenu(*componentClass))
{
typeNameList.push_back(componentClass->m_editData->m_name);
}
break;
case EditorComponentAPIRequests::EntityType::Layer:
if (AzToolsFramework::AppearsInLayerComponentMenu(*componentClass))
{
typeNameList.push_back(componentClass->m_editData->m_name);
}
break;
default:
if (AzToolsFramework::AppearsInSystemComponentMenu(*componentClass))
{
typeNameList.push_back(componentClass->m_editData->m_name);
}
break;
}
return true;
});
return typeNameList;
}
// Returns an Outcome object with the Component Id if successful, and the cause of the failure otherwise
EditorComponentAPIRequests::AddComponentsOutcome EditorComponentAPIComponent::AddComponentsOfType(AZ::EntityId entityId, const AZ::ComponentTypeList& componentTypeIds)
{
EditorEntityActionComponent::AddComponentsOutcome outcome;
EntityCompositionRequestBus::BroadcastResult(outcome, &EntityCompositionRequests::AddComponentsToEntities, EntityIdList{ entityId }, componentTypeIds);
AZ_Warning("EditorComponentAPI", outcome.IsSuccess(), "AddComponentsOfType - AddComponentsToEntities failed (%s).", outcome.GetError().c_str());
if (!outcome.IsSuccess())
{
return AddComponentsOutcome( AZStd::string("AddComponentsOfType - AddComponentsToEntities failed (") + outcome.GetError().c_str() + ")." );
}
auto entityToComponentMap = outcome.GetValue();
if (entityToComponentMap.find(entityId) == entityToComponentMap.end() || entityToComponentMap[entityId].m_componentsAdded.size() == 0)
{
AZ_Warning("EditorComponentAPI", false, "Malformed result from AddComponentsToEntities.");
return AddComponentsOutcome( AZStd::string("Malformed result from AddComponentsToEntities.") );
}
AZStd::vector<AZ::EntityComponentIdPair> componentIds;
for (AZ::Component* component : entityToComponentMap[entityId].m_componentsAdded)
{
if (!component)
{
AZ_Warning("EditorComponentAPI", false, "Invalid component returned in AddComponentsToEntities.");
return AddComponentsOutcome( AZStd::string("Invalid component returned in AddComponentsToEntities.") );
}
else
{
componentIds.push_back(AZ::EntityComponentIdPair(entityId, component->GetId()));
}
}
return AddComponentsOutcome( componentIds );
}
EditorComponentAPIRequests::AddComponentsOutcome EditorComponentAPIComponent::AddComponentOfType(AZ::EntityId entityId, const AZ::Uuid& componentTypeId)
{
return AddComponentsOfType(entityId, { componentTypeId });
}
bool EditorComponentAPIComponent::HasComponentOfType(AZ::EntityId entityId, AZ::Uuid componentTypeId)
{
GetComponentOutcome outcome = GetComponentOfType(entityId, componentTypeId);
return outcome.IsSuccess() && outcome.GetValue().GetComponentId() != AZ::InvalidComponentId;
}
size_t EditorComponentAPIComponent::CountComponentsOfType(AZ::EntityId entityId, AZ::Uuid componentTypeId)
{
AZStd::vector<AZ::Component*> components = FindComponents(entityId, componentTypeId);
return components.size();
}
EditorComponentAPIRequests::GetComponentOutcome EditorComponentAPIComponent::GetComponentOfType(AZ::EntityId entityId, AZ::Uuid componentTypeId)
{
AZ::Component* component = FindComponent(entityId, componentTypeId);
if (component)
{
return GetComponentOutcome( AZ::EntityComponentIdPair(entityId, component->GetId()) );
}
else
{
return GetComponentOutcome( AZStd::string("GetComponentOfType - Component type of id ") + componentTypeId.ToString<AZStd::string>() + " not found on Entity" );
}
}
EditorComponentAPIRequests::GetComponentsOutcome EditorComponentAPIComponent::GetComponentsOfType(AZ::EntityId entityId, AZ::Uuid componentTypeId)
{
AZStd::vector<AZ::Component*> components = FindComponents(entityId, componentTypeId);
if (components.empty())
{
return GetComponentsOutcome( AZStd::string("GetComponentOfType - Component type not found on Entity") );
}
AZStd::vector<AZ::EntityComponentIdPair> componentIds;
componentIds.reserve(components.size());
for (AZ::Component* component : components)
{
componentIds.push_back(AZ::EntityComponentIdPair(entityId, component->GetId()));
}
return {componentIds};
}
bool EditorComponentAPIComponent::IsValid(AZ::EntityComponentIdPair componentInstance)
{
AZ::Component* component = FindComponent(componentInstance.GetEntityId() , componentInstance.GetComponentId());
return component != nullptr;
}
bool EditorComponentAPIComponent::EnableComponents(const AZStd::vector<AZ::EntityComponentIdPair>& componentInstances)
{
AZStd::vector<AZ::Component*> components;
for (const AZ::EntityComponentIdPair& componentInstance : componentInstances)
{
AZ::Component* component = FindComponent(componentInstance.GetEntityId(), componentInstance.GetComponentId());
if (component)
{
components.push_back(component);
}
else
{
AZ_Warning("EditorComponentAPI", false, "EnableComponent failed - could not find Component from the given entityId and componentId.");
return false;
}
}
EntityCompositionRequestBus::Broadcast(&EntityCompositionRequests::EnableComponents, components);
for (const AZ::EntityComponentIdPair& componentInstance : componentInstances)
{
if (!IsComponentEnabled(componentInstance))
{
return false;
}
}
return true;
}
bool EditorComponentAPIComponent::IsComponentEnabled(const AZ::EntityComponentIdPair& componentInstance)
{
// Get AZ::Entity*
AZ::Entity* entityPtr = FindEntity(componentInstance.GetEntityId());
if (!entityPtr)
{
AZ_Warning("EditorComponentAPI", false, "IsComponentEnabled failed - could not find Entity from the given entityId");
return false;
}
// Get Component*
AZ::Component* component = FindComponent(componentInstance.GetEntityId(), componentInstance.GetComponentId());
if (!component)
{
AZ_Warning("EditorComponentAPI", false, "IsComponentEnabled failed - could not find Component from the given entityId and componentId.");
return false;
}
const auto& entityComponents = entityPtr->GetComponents();
if (AZStd::find(entityComponents.begin(), entityComponents.end(), component) != entityComponents.end())
{
return true;
}
return false;
}
bool EditorComponentAPIComponent::DisableComponents(const AZStd::vector<AZ::EntityComponentIdPair>& componentInstances)
{
AZStd::vector<AZ::Component*> components;
for (const AZ::EntityComponentIdPair& componentInstance : componentInstances)
{
AZ::Component* component = FindComponent(componentInstance.GetEntityId(), componentInstance.GetComponentId());
if (component)
{
components.push_back(component);
}
else
{
AZ_Warning("EditorComponentAPI", false, "DisableComponent failed - could not find Component from the given entityId and componentId.");
return false;
}
}
EntityCompositionRequestBus::Broadcast(&EntityCompositionRequests::DisableComponents, components);
for (const AZ::EntityComponentIdPair& componentInstance : componentInstances)
{
if (IsComponentEnabled(componentInstance))
{
return false;
}
}
return true;
}
bool EditorComponentAPIComponent::RemoveComponents(const AZStd::vector<AZ::EntityComponentIdPair>& componentInstances)
{
bool cumulativeSuccess = true;
AZStd::vector<AZ::Component*> components;
for (const AZ::EntityComponentIdPair& componentInstance : componentInstances)
{
AZ::Component* component = FindComponent(componentInstance.GetEntityId(), componentInstance.GetComponentId());
if (component)
{
components.push_back(component);
}
else
{
AZ_Warning("EditorComponentAPI", false, "RemoveComponents - a component could not be found.");
cumulativeSuccess = false;
}
}
EditorEntityActionComponent::RemoveComponentsOutcome outcome;
EntityCompositionRequestBus::BroadcastResult(outcome, &EntityCompositionRequests::RemoveComponents, components);
if (!outcome.IsSuccess())
{
AZ_Warning("EditorComponentAPI", false, "RemoveComponents failed - components could not be removed from entity.");
return false;
}
return cumulativeSuccess;
}
EditorComponentAPIRequests::PropertyTreeOutcome EditorComponentAPIComponent::BuildComponentPropertyTreeEditor(const AZ::EntityComponentIdPair& componentInstance)
{
// Verify the Component Instance still exists
AZ::Component* component = FindComponent(componentInstance.GetEntityId(), componentInstance.GetComponentId());
if (!component)
{
AZ_Error("EditorComponentAPIComponent", false, "BuildComponentPropertyTreeEditor - Component Instance is Invalid.");
return {PropertyTreeOutcome::ErrorType("BuildComponentPropertyTreeEditor - Component Instance is Invalid.")};
}
return {PropertyTreeOutcome::ValueType(reinterpret_cast<void*>(component), component->GetUnderlyingComponentType())};
}
EditorComponentAPIRequests::PropertyOutcome EditorComponentAPIComponent::GetComponentProperty(const AZ::EntityComponentIdPair& componentInstance, const AZStd::string_view propertyPath)
{
// Verify the Component Instance still exists
AZ::Component* component = FindComponent(componentInstance.GetEntityId(), componentInstance.GetComponentId());
if (!component)
{
AZ_Error("EditorComponentAPIComponent", false, "GetComponentProperty - Component Instance is Invalid.");
return { PropertyOutcome::ErrorType("GetComponentProperty - Component Instance is Invalid.") };
}
PropertyTreeEditor pte = PropertyTreeEditor(reinterpret_cast<void*>(component), component->GetUnderlyingComponentType());
if (m_usePropertyVisibility)
{
pte.SetVisibleEnforcement(true);
}
return pte.GetProperty(propertyPath);
}
EditorComponentAPIRequests::PropertyOutcome EditorComponentAPIComponent::SetComponentProperty(const AZ::EntityComponentIdPair& componentInstance, const AZStd::string_view propertyPath, const AZStd::any& value)
{
// Verify the Component Instance still exists
AZ::Component* component = FindComponent(componentInstance.GetEntityId(), componentInstance.GetComponentId());
if (!component)
{
AZ_Error("EditorComponentAPIComponent", false, "SetComponentProperty - Component Instance is Invalid.");
return {PropertyOutcome::ErrorType("SetComponentProperty - Component Instance is Invalid.")};
}
PropertyTreeEditor pte = PropertyTreeEditor(reinterpret_cast<void*>(component), component->GetUnderlyingComponentType());
if (m_usePropertyVisibility)
{
pte.SetVisibleEnforcement(true);
}
PropertyOutcome result = pte.SetProperty(propertyPath, value);
if (result.IsSuccess())
{
PropertyEditorEntityChangeNotificationBus::Event(componentInstance.GetEntityId(), &PropertyEditorEntityChangeNotifications::OnEntityComponentPropertyChanged, componentInstance.GetComponentId());
}
return result;
}
bool EditorComponentAPIComponent::CompareComponentProperty(const AZ::EntityComponentIdPair& componentInstance, const AZStd::string_view propertyPath, const AZStd::any& value)
{
// Verify the Component Instance still exists
AZ::Component* component = FindComponent(componentInstance.GetEntityId(), componentInstance.GetComponentId());
if (!component)
{
AZ_Error("EditorComponentAPIComponent", false, "CompareComponentProperty - Component Instance is Invalid.");
return false;
}
PropertyTreeEditor pte = PropertyTreeEditor(reinterpret_cast<void*>(component), component->GetUnderlyingComponentType());
if (m_usePropertyVisibility)
{
pte.SetVisibleEnforcement(true);
}
return pte.CompareProperty(propertyPath, value);
}
const AZStd::vector<AZStd::string> EditorComponentAPIComponent::BuildComponentPropertyList(const AZ::EntityComponentIdPair& componentInstance)
{
// Verify the Component Instance still exists
AZ::Component* component = FindComponent(componentInstance.GetEntityId(), componentInstance.GetComponentId());
if (!component)
{
AZ_Error("EditorComponentAPIComponent", false, "BuildComponentPropertyList - Component Instance is Invalid.");
return { AZStd::string("BuildComponentPropertyList - Component Instance is Invalid.") };
}
PropertyTreeEditor pte = PropertyTreeEditor(reinterpret_cast<void*>(component), component->GetUnderlyingComponentType());
if (m_usePropertyVisibility)
{
pte.SetVisibleEnforcement(true);
}
return pte.BuildPathsList();
}
AZ::Entity* EditorComponentAPIComponent::FindEntity(AZ::EntityId entityId)
{
AZ_Assert(entityId.IsValid(), "EditorComponentAPIComponent::FindEntity - Invalid EntityId provided.");
if (!entityId.IsValid())
{
return nullptr;
}
AZ::Entity* entity = nullptr;
AZ::ComponentApplicationBus::BroadcastResult(entity, &AZ::ComponentApplicationRequests::FindEntity, entityId);
return entity;
}
AZ::Component* EditorComponentAPIComponent::FindComponent(AZ::EntityId entityId, AZ::ComponentId componentId)
{
// Get AZ::Entity*
AZ::Entity* entityPtr = FindEntity(entityId);
if (!entityPtr)
{
AZ_Warning("EditorComponentAPI", false, "FindComponent failed - could not find entity pointer from entityId provided.");
return nullptr;
}
// See if the component is on the entity proper (Active)
const auto& entityComponents = entityPtr->GetComponents();
for (AZ::Component* component : entityComponents)
{
if (component->GetId() == componentId)
{
return component;
}
}
// Check for pending components
AZStd::vector<AZ::Component*> pendingComponents;
AzToolsFramework::EditorPendingCompositionRequestBus::Event(entityPtr->GetId(), &AzToolsFramework::EditorPendingCompositionRequests::GetPendingComponents, pendingComponents);
for (AZ::Component* component : pendingComponents)
{
if (component->GetId() == componentId)
{
return component;
}
}
// Check for disabled components
AZStd::vector<AZ::Component*> disabledComponents;
AzToolsFramework::EditorDisabledCompositionRequestBus::Event(entityPtr->GetId(), &AzToolsFramework::EditorDisabledCompositionRequests::GetDisabledComponents, disabledComponents);
for (AZ::Component* component : disabledComponents)
{
if (component->GetId() == componentId)
{
return component;
}
}
return nullptr;
}
AZ::Component* EditorComponentAPIComponent::FindComponent(AZ::EntityId entityId, AZ::Uuid componentTypeId)
{
// Get AZ::Entity*
AZ::Entity* entityPtr = FindEntity(entityId);
if (!entityPtr)
{
AZ_Warning("EditorComponentAPI", false, "FindComponent failed - could not find entity pointer from entityId provided.");
return nullptr;
}
// See if the component is on the entity proper (Active)
const auto& entityComponents = entityPtr->GetComponents();
for (AZ::Component* component : entityComponents)
{
if (component->GetUnderlyingComponentType() == componentTypeId)
{
return component;
}
}
// Check for pending components
AZStd::vector<AZ::Component*> pendingComponents;
AzToolsFramework::EditorPendingCompositionRequestBus::Event(entityPtr->GetId(), &AzToolsFramework::EditorPendingCompositionRequests::GetPendingComponents, pendingComponents);
for (AZ::Component* component : pendingComponents)
{
if (component->GetUnderlyingComponentType() == componentTypeId)
{
return component;
}
}
// Check for disabled components
AZStd::vector<AZ::Component*> disabledComponents;
AzToolsFramework::EditorDisabledCompositionRequestBus::Event(entityPtr->GetId(), &AzToolsFramework::EditorDisabledCompositionRequests::GetDisabledComponents, disabledComponents);
for (AZ::Component* component : disabledComponents)
{
if (component->GetUnderlyingComponentType() == componentTypeId)
{
return component;
}
}
return nullptr;
}
AZStd::vector<AZ::Component*> EditorComponentAPIComponent::FindComponents(AZ::EntityId entityId, AZ::Uuid componentTypeId)
{
AZStd::vector<AZ::Component*> components;
// Get AZ::Entity*
AZ::Entity* entityPtr = FindEntity(entityId);
if (!entityPtr)
{
AZ_Warning("EditorComponentAPI", false, "FindComponents failed - could not find entity pointer from entityId provided.");
return components;
}
// See if the component is on the entity proper (Active)
const auto& entityComponents = entityPtr->GetComponents();
for (AZ::Component* component : entityComponents)
{
if (component->GetUnderlyingComponentType() == componentTypeId)
{
components.push_back(component);
}
}
// Check for pending components
AZStd::vector<AZ::Component*> pendingComponents;
AzToolsFramework::EditorPendingCompositionRequestBus::Event(entityId, &AzToolsFramework::EditorPendingCompositionRequests::GetPendingComponents, pendingComponents);
for (AZ::Component* component : pendingComponents)
{
if (component->GetUnderlyingComponentType() == componentTypeId)
{
components.push_back(component);
}
}
// Check for disabled components
AZStd::vector<AZ::Component*> disabledComponents;
AzToolsFramework::EditorDisabledCompositionRequestBus::Event(entityId, &AzToolsFramework::EditorDisabledCompositionRequests::GetDisabledComponents, disabledComponents);
for (AZ::Component* component : disabledComponents)
{
if (component->GetUnderlyingComponentType() == componentTypeId)
{
components.push_back(component);
}
}
return components;
}
} // Components
} // AzToolsFramework
@@ -0,0 +1,75 @@
/*
* 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.
*
*/
#pragma once
#include <AzCore/Component/Component.h>
#include <AzCore/Component/Entity.h>
#include <AzToolsFramework/Component/EditorComponentAPIBus.h>
#include <AzToolsFramework/UI/PropertyEditor/PropertyEditorAPI.h>
namespace AzToolsFramework
{
namespace Components
{
//! A System Component to reflect Editor operations on Components to Behavior Context
class EditorComponentAPIComponent
: public AZ::Component
, public EditorComponentAPIBus::Handler
{
public:
AZ_COMPONENT(EditorComponentAPIComponent, "{AC1A53C9-25BE-47D8-B9B5-60199AC73C2B}");
EditorComponentAPIComponent() = default;
~EditorComponentAPIComponent() = default;
static void Reflect(AZ::ReflectContext* context);
// Component ...
void Activate() override;
void Deactivate() override;
// EditorComponentAPIBus ...
AZStd::vector<AZ::Uuid> FindComponentTypeIdsByEntityType(const AZStd::vector<AZStd::string>& componentTypeNames, EditorComponentAPIRequests::EntityType entityType) override;
AZStd::vector<AZStd::string> FindComponentTypeNames(const AZ::ComponentTypeList& componentTypeIds) override;
AZStd::vector<AZStd::string> BuildComponentTypeNameListByEntityType(EditorComponentAPIRequests::EntityType entityType) override;
AddComponentsOutcome AddComponentsOfType(AZ::EntityId entityId, const AZ::ComponentTypeList& componentTypeIds) override;
AddComponentsOutcome AddComponentOfType(AZ::EntityId entityId, const AZ::Uuid& componentTypeId) override;
bool HasComponentOfType(AZ::EntityId entityId, AZ::Uuid componentTypeId) override;
size_t CountComponentsOfType(AZ::EntityId entityId, AZ::Uuid componentTypeId) override;
GetComponentOutcome GetComponentOfType(AZ::EntityId entityId, AZ::Uuid componentTypeId) override;
GetComponentsOutcome GetComponentsOfType(AZ::EntityId entityId, AZ::Uuid componentTypeId) override;
bool IsValid(AZ::EntityComponentIdPair componentInstance) override;
bool EnableComponents(const AZStd::vector<AZ::EntityComponentIdPair>& componentInstances) override;
bool IsComponentEnabled(const AZ::EntityComponentIdPair& componentInstance) override;
bool DisableComponents(const AZStd::vector<AZ::EntityComponentIdPair>& componentInstances) override;
bool RemoveComponents(const AZStd::vector<AZ::EntityComponentIdPair>& componentInstances) override;
PropertyTreeOutcome BuildComponentPropertyTreeEditor(const AZ::EntityComponentIdPair& componentInstance) override;
PropertyOutcome GetComponentProperty(const AZ::EntityComponentIdPair& componentInstance, const AZStd::string_view propertyPath) override;
PropertyOutcome SetComponentProperty(const AZ::EntityComponentIdPair& componentInstance, const AZStd::string_view propertyPath, const AZStd::any& value) override;
bool CompareComponentProperty(const AZ::EntityComponentIdPair& componentInstance, const AZStd::string_view propertyPath, const AZStd::any& value) override;
const AZStd::vector<AZStd::string> BuildComponentPropertyList(const AZ::EntityComponentIdPair& componentInstance) override;
void SetVisibleEnforcement(bool enforceVisiblity) override;
private:
AZ::Entity* FindEntity(AZ::EntityId entityId);
AZ::Component* FindComponent(AZ::EntityId entityId, AZ::ComponentId componentId);
AZ::Component* FindComponent(AZ::EntityId entityId, AZ::Uuid componentType);
AZStd::vector<AZ::Component*> FindComponents(AZ::EntityId entityId, AZ::Uuid componentType);
bool m_usePropertyVisibility = false;
AZ::SerializeContext* m_serializeContext = nullptr;
};
} // Components
} // AzToolsFramework
@@ -0,0 +1,55 @@
/*
* 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.
*
*/
#pragma once
#include <AzCore/EBus/EBus.h>
#include <AzCore/Component/ComponentBus.h>
#include <AzFramework/Entity/BehaviorEntity.h>
#include <AzToolsFramework/PropertyTreeEditor/PropertyTreeEditor.h>
#include "EditorComponentAPIBus.h"
namespace AzToolsFramework
{
//! Exposes the Editor Component CRUD API for the singleton Entity of the current level;
//! it is exposed to Behavior Context for Editor Scripting.
//! Use EditorComponentAPIBus For methods that require AZ::EntityComponentIDPairs as input.
class EditorLevelComponentAPIRequests
: public AZ::EBusTraits
{
public:
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
//! Add Components of the given types to an Entity.
// Returns an Outcome object - it contains the AZ::EntityComponentIdPairs in case of Success, or an error message in case or Failure.
virtual EditorComponentAPIRequests::AddComponentsOutcome AddComponentsOfType(const AZ::ComponentTypeList& componentTypeIds) = 0;
//! Returns true if a Component of type provided can be found on the Level Entity, false otherwise.
virtual bool HasComponentOfType(AZ::Uuid componentTypeId) = 0;
//! Count Components of type provided on the Level Entity.
virtual size_t CountComponentsOfType(AZ::Uuid componentTypeId) = 0;
//! Gets the first Component of type that is attached to the Level Entity.
// Only returns first component of type if found (early out).
// Returns an Outcome object - it contains the AZ::EntityComponentIdPair in case of Success, or an error message in case or Failure.
virtual EditorComponentAPIRequests::GetComponentOutcome GetComponentOfType(AZ::Uuid componentTypeId) = 0;
//! Get all Components of type that are attached to the Level Entity
// Returns vector of ComponentIds, or an empty vector if components could not be found.
virtual EditorComponentAPIRequests::GetComponentsOutcome GetComponentsOfType(AZ::Uuid componentTypeId) = 0;
};
using EditorLevelComponentAPIBus = AZ::EBus<EditorLevelComponentAPIRequests>;
}
@@ -0,0 +1,141 @@
/*
* 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 <AzToolsFramework/Component/EditorLevelComponentAPIComponent.h>
#include <AzCore/RTTI/BehaviorContext.h>
#include <AzCore/Serialization/Utils.h>
#include <AzToolsFramework/API/ToolsApplicationAPI.h>
#include <AzToolsFramework/API/EntityCompositionRequestBus.h>
#include <AzToolsFramework/ToolsComponents/EditorDisabledCompositionBus.h>
#include <AzToolsFramework/ToolsComponents/EditorPendingCompositionBus.h>
#include <AzToolsFramework/Entity/EditorEntityActionComponent.h>
#include <AzToolsFramework/UI/PropertyEditor/InstanceDataHierarchy.h>
#include <AzToolsFramework/UI/PropertyEditor/PropertyEditorAPI.h>
namespace AzToolsFramework
{
namespace Components
{
void EditorLevelComponentAPIComponent::Reflect(AZ::ReflectContext* context)
{
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<EditorLevelComponentAPIComponent, AZ::Component>();
}
if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
{
behaviorContext->EBus<EditorLevelComponentAPIBus>("EditorLevelComponentAPIBus")
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
->Attribute(AZ::Script::Attributes::Category, "Components")
->Attribute(AZ::Script::Attributes::Module, "editor")
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::All)
->Event("AddComponentsOfType", &EditorLevelComponentAPIRequests::AddComponentsOfType)
->Event("HasComponentOfType", &EditorLevelComponentAPIRequests::HasComponentOfType)
->Event("CountComponentsOfType", &EditorLevelComponentAPIRequests::CountComponentsOfType)
->Event("GetComponentOfType", &EditorLevelComponentAPIRequests::GetComponentOfType)
->Event("GetComponentsOfType", &EditorLevelComponentAPIRequests::GetComponentsOfType)
;
}
}
void EditorLevelComponentAPIComponent::Activate()
{
EditorLevelComponentAPIBus::Handler::BusConnect();
}
void EditorLevelComponentAPIComponent::Deactivate()
{
EditorLevelComponentAPIBus::Handler::BusDisconnect();
}
// Returns an Outcome object with the Component Id if successful, and the cause of the failure otherwise
EditorComponentAPIRequests::AddComponentsOutcome EditorLevelComponentAPIComponent::AddComponentsOfType(const AZ::ComponentTypeList& componentTypeIds)
{
//Always get the EntityId of the Level.
AZ::EntityId levelEntityId;
ToolsApplicationRequestBus::BroadcastResult(levelEntityId, &ToolsApplicationRequests::GetCurrentLevelEntityId);
if (!levelEntityId.IsValid())
{
return EditorComponentAPIRequests::AddComponentsOutcome(AZStd::string("Invalid Level EntityId. Most likely there's no level loaded in the Editor."));
}
EditorComponentAPIRequests::AddComponentsOutcome outcome;
EditorComponentAPIBus::BroadcastResult(outcome, &EditorComponentAPIRequests::AddComponentsOfType, levelEntityId, componentTypeIds);
return outcome;
}
bool EditorLevelComponentAPIComponent::HasComponentOfType(AZ::Uuid componentTypeId)
{
//Always get the EntityId of the Level.
AZ::EntityId levelEntityId;
ToolsApplicationRequestBus::BroadcastResult(levelEntityId, &ToolsApplicationRequests::GetCurrentLevelEntityId);
if (!levelEntityId.IsValid())
{
return false;
}
EditorComponentAPIRequests::GetComponentOutcome outcome;
EditorComponentAPIBus::BroadcastResult(outcome, &EditorComponentAPIRequests::GetComponentOfType, levelEntityId, componentTypeId);
return outcome.IsSuccess() && outcome.GetValue().GetComponentId() != AZ::InvalidComponentId;
}
size_t EditorLevelComponentAPIComponent::CountComponentsOfType(AZ::Uuid componentTypeId)
{
//Always get the EntityId of the Level.
AZ::EntityId levelEntityId;
ToolsApplicationRequestBus::BroadcastResult(levelEntityId, &ToolsApplicationRequests::GetCurrentLevelEntityId);
if (!levelEntityId.IsValid())
{
return 0;
}
size_t count;
EditorComponentAPIBus::BroadcastResult(count, &EditorComponentAPIRequests::CountComponentsOfType, levelEntityId, componentTypeId);
return count;
}
EditorComponentAPIRequests::GetComponentOutcome EditorLevelComponentAPIComponent::GetComponentOfType(AZ::Uuid componentTypeId)
{
//Always get the EntityId of the Level.
AZ::EntityId levelEntityId;
ToolsApplicationRequestBus::BroadcastResult(levelEntityId, &ToolsApplicationRequests::GetCurrentLevelEntityId);
if (!levelEntityId.IsValid())
{
return EditorComponentAPIRequests::GetComponentOutcome(AZStd::string("GetComponentOfType - Component type of id ") + componentTypeId.ToString<AZStd::string>() + " not found on Level Entity");
}
EditorComponentAPIRequests::GetComponentOutcome outcome;
EditorComponentAPIBus::BroadcastResult(outcome, &EditorComponentAPIRequests::GetComponentOfType, levelEntityId, componentTypeId);
return outcome;
}
EditorComponentAPIRequests::GetComponentsOutcome EditorLevelComponentAPIComponent::GetComponentsOfType(AZ::Uuid componentTypeId)
{
//Always get the EntityId of the Level.
AZ::EntityId levelEntityId;
ToolsApplicationRequestBus::BroadcastResult(levelEntityId, &ToolsApplicationRequests::GetCurrentLevelEntityId);
if (!levelEntityId.IsValid())
{
return EditorComponentAPIRequests::GetComponentsOutcome(AZStd::string("GetComponentsOfType - Component type of id ") + componentTypeId.ToString<AZStd::string>() + " not found on Level Entity");
}
EditorComponentAPIRequests::GetComponentsOutcome outcome;
EditorComponentAPIBus::BroadcastResult(outcome, &EditorComponentAPIRequests::GetComponentsOfType, levelEntityId, componentTypeId);
return outcome;
}
} // Components
} // AzToolsFramework
@@ -0,0 +1,49 @@
/*
* 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.
*
*/
#pragma once
#include <AzCore/Component/Component.h>
#include <AzCore/Component/Entity.h>
#include <AzToolsFramework/Component/EditorLevelComponentAPIBus.h>
#include <AzToolsFramework/UI/PropertyEditor/PropertyEditorAPI.h>
namespace AzToolsFramework
{
namespace Components
{
//! A System Component to reflect Editor operations on Components to Behavior Context
class EditorLevelComponentAPIComponent
: public AZ::Component
, public EditorLevelComponentAPIBus::Handler
{
public:
AZ_COMPONENT(EditorLevelComponentAPIComponent, "{F3A07F35-9679-4A88-B123-85474ECFEC21}");
EditorLevelComponentAPIComponent() = default;
~EditorLevelComponentAPIComponent() = default;
static void Reflect(AZ::ReflectContext* context);
// Component ...
void Activate() override;
void Deactivate() override;
// EditorLevelComponentAPIBus ...
EditorComponentAPIRequests::AddComponentsOutcome AddComponentsOfType(const AZ::ComponentTypeList& componentTypeIds) override;
bool HasComponentOfType(AZ::Uuid componentTypeId) override;
size_t CountComponentsOfType(AZ::Uuid componentTypeId) override;
EditorComponentAPIRequests::GetComponentOutcome GetComponentOfType(AZ::Uuid componentTypeId) override;
EditorComponentAPIRequests::GetComponentsOutcome GetComponentsOfType(AZ::Uuid componentTypeId) override;
};
} // Components
} // AzToolsFramework