Added API for finding components based on required/incompatible services.
Signed-off-by: Chris Galvan <chgalvan@amazon.com>
This commit is contained in:
@@ -271,6 +271,68 @@ namespace AzToolsFramework
|
||||
return editorComponentBaseComponent;
|
||||
}
|
||||
|
||||
bool OffersRequiredServices(
|
||||
const AZ::SerializeContext::ClassData* componentClass,
|
||||
const AZStd::vector<AZ::ComponentServiceType>& serviceFilter,
|
||||
const AZStd::vector<AZ::ComponentServiceType>& incompatibleServiceFilter
|
||||
)
|
||||
{
|
||||
AZ_Assert(componentClass, "Component class must not be null");
|
||||
|
||||
if (!componentClass)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
AZ::ComponentDescriptor* componentDescriptor = nullptr;
|
||||
AZ::ComponentDescriptorBus::EventResult(
|
||||
componentDescriptor, componentClass->m_typeId, &AZ::ComponentDescriptor::GetDescriptor);
|
||||
if (!componentDescriptor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// If no services are provided, this function returns true
|
||||
if (serviceFilter.empty())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
AZ::ComponentDescriptor::DependencyArrayType providedServices;
|
||||
componentDescriptor->GetProvidedServices(providedServices, nullptr);
|
||||
|
||||
//reject this component if it does not offer any of the required services
|
||||
if (AZStd::find_first_of(
|
||||
providedServices.begin(),
|
||||
providedServices.end(),
|
||||
serviceFilter.begin(),
|
||||
serviceFilter.end()) == providedServices.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//reject this component if it does offer any of the incompatible services
|
||||
if (AZStd::find_first_of(
|
||||
providedServices.begin(),
|
||||
providedServices.end(),
|
||||
incompatibleServiceFilter.begin(),
|
||||
incompatibleServiceFilter.end()) != providedServices.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OffersRequiredServices(
|
||||
const AZ::SerializeContext::ClassData* componentClass,
|
||||
const AZStd::vector<AZ::ComponentServiceType>& serviceFilter
|
||||
)
|
||||
{
|
||||
const AZStd::vector<AZ::ComponentServiceType> incompatibleServices;
|
||||
return OffersRequiredServices(componentClass, serviceFilter, incompatibleServices);
|
||||
}
|
||||
|
||||
bool ShouldInspectorShowComponent(const AZ::Component* component)
|
||||
{
|
||||
if (!component)
|
||||
|
||||
@@ -105,6 +105,16 @@ namespace AzToolsFramework
|
||||
AZ::ComponentDescriptor* GetComponentDescriptor(const AZ::Component* component);
|
||||
Components::EditorComponentDescriptor* GetEditorComponentDescriptor(const AZ::Component* component);
|
||||
Components::EditorComponentBase* GetEditorComponent(AZ::Component* component);
|
||||
// Returns true if the given component provides at least one of the services specified or no services are provided
|
||||
bool OffersRequiredServices(
|
||||
const AZ::SerializeContext::ClassData* componentClass,
|
||||
const AZStd::vector<AZ::ComponentServiceType>& serviceFilter,
|
||||
const AZStd::vector<AZ::ComponentServiceType>& incompatibleServiceFilter
|
||||
);
|
||||
bool OffersRequiredServices(
|
||||
const AZ::SerializeContext::ClassData* componentClass,
|
||||
const AZStd::vector<AZ::ComponentServiceType>& serviceFilter
|
||||
);
|
||||
|
||||
/// Return true if the editor should show this component to users,
|
||||
/// false if the component should be hidden from users.
|
||||
|
||||
Reference in New Issue
Block a user