Split editor entity activation from PrefabSystemComponent (#6787)
* Split editor entity activation from PrefabSystemComponent Signed-off-by: srikappa-amzn <82230713+srikappa-amzn@users.noreply.github.com> * Fixed a small typo Signed-off-by: srikappa-amzn <82230713+srikappa-amzn@users.noreply.github.com> * Pass entity activation callback during prefab instantiation for failing tests Signed-off-by: srikappa-amzn <82230713+srikappa-amzn@users.noreply.github.com>
This commit is contained in:
@@ -277,7 +277,7 @@ namespace AzToolsFramework
|
||||
}
|
||||
|
||||
AZStd::unique_ptr<Instance> PrefabSystemComponent::InstantiatePrefab(
|
||||
AZ::IO::PathView filePath, InstanceOptionalReference parent)
|
||||
AZ::IO::PathView filePath, InstanceOptionalReference parent, const InstantiatedEntitiesCallback& instantiatedEntitiesCallback)
|
||||
{
|
||||
// Retrieve the template id for the source prefab filepath
|
||||
Prefab::TemplateId templateId = GetTemplateIdFromFilePath(filePath);
|
||||
@@ -297,11 +297,11 @@ namespace AzToolsFramework
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return InstantiatePrefab(templateId, parent);
|
||||
return InstantiatePrefab(templateId, parent, instantiatedEntitiesCallback);
|
||||
}
|
||||
|
||||
AZStd::unique_ptr<Instance> PrefabSystemComponent::InstantiatePrefab(
|
||||
TemplateId templateId, InstanceOptionalReference parent)
|
||||
TemplateId templateId, InstanceOptionalReference parent, const InstantiatedEntitiesCallback& instantiatedEntitiesCallback)
|
||||
{
|
||||
TemplateReference instantiatingTemplate = FindTemplate(templateId);
|
||||
|
||||
@@ -324,8 +324,10 @@ namespace AzToolsFramework
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AzToolsFramework::EditorEntityContextRequestBus::Broadcast(
|
||||
&AzToolsFramework::EditorEntityContextRequests::HandleEntitiesAdded, newEntities);
|
||||
if (instantiatedEntitiesCallback)
|
||||
{
|
||||
instantiatedEntitiesCallback(newEntities);
|
||||
}
|
||||
|
||||
return newInstance;
|
||||
}
|
||||
|
||||
@@ -124,19 +124,25 @@ namespace AzToolsFramework
|
||||
* Generates a new Prefab Instance based on the Template whose source is stored in filepath.
|
||||
* @param filePath The path to the prefab source file containing the template being instantiated.
|
||||
* @param parent Reference of the target instance the instantiated instance will be placed under.
|
||||
* @param instantiatedEntitiesCallback An optional callback that can be used to modify the instantiated entities.
|
||||
* @return A unique_ptr to the newly instantiated instance. Null if operation failed.
|
||||
*/
|
||||
AZStd::unique_ptr<Instance> InstantiatePrefab(
|
||||
AZ::IO::PathView filePath, InstanceOptionalReference parent = AZStd::nullopt) override;
|
||||
AZ::IO::PathView filePath,
|
||||
InstanceOptionalReference parent = AZStd::nullopt,
|
||||
const InstantiatedEntitiesCallback& instantiatedEntitiesCallback = {}) override;
|
||||
|
||||
/**
|
||||
* Generates a new Prefab Instance based on the Template referenced by templateId.
|
||||
* @param templateId The id of the template being instantiated.
|
||||
* @param parent Reference of the target instance the instantiated instance will be placed under.
|
||||
* @param instantiatedEntitiesCallback An optional callback that can be used to modify the instantiated entities.
|
||||
* @return A unique_ptr to the newly instantiated instance. Null if operation failed.
|
||||
*/
|
||||
AZStd::unique_ptr<Instance> InstantiatePrefab(
|
||||
TemplateId templateId, InstanceOptionalReference parent = AZStd::nullopt) override;
|
||||
TemplateId templateId,
|
||||
InstanceOptionalReference parent = AZStd::nullopt,
|
||||
const InstantiatedEntitiesCallback& instantiatedEntitiesCallback = {}) override;
|
||||
|
||||
/**
|
||||
* Add a new Link into Prefab System Component and create a unique id for it.
|
||||
|
||||
+9
-2
@@ -27,6 +27,9 @@ namespace AzToolsFramework
|
||||
class PrefabSystemComponentInterface
|
||||
{
|
||||
public:
|
||||
|
||||
using InstantiatedEntitiesCallback = AZStd::function<void(AZStd::vector<AZ::Entity*>&)>;
|
||||
|
||||
AZ_RTTI(PrefabSystemComponentInterface, "{8E95A029-67F9-4F74-895F-DDBFE29516A0}");
|
||||
|
||||
virtual TemplateReference FindTemplate(TemplateId id) = 0;
|
||||
@@ -70,9 +73,13 @@ namespace AzToolsFramework
|
||||
virtual void PropagateTemplateChanges(TemplateId templateId, InstanceOptionalConstReference instanceToExclude = AZStd::nullopt) = 0;
|
||||
|
||||
virtual AZStd::unique_ptr<Instance> InstantiatePrefab(
|
||||
AZ::IO::PathView filePath, InstanceOptionalReference parent = AZStd::nullopt) = 0;
|
||||
AZ::IO::PathView filePath,
|
||||
InstanceOptionalReference parent = AZStd::nullopt,
|
||||
const InstantiatedEntitiesCallback& instantiatedEntitiesCallback = {}) = 0;
|
||||
virtual AZStd::unique_ptr<Instance> InstantiatePrefab(
|
||||
TemplateId templateId, InstanceOptionalReference parent = AZStd::nullopt) = 0;
|
||||
TemplateId templateId,
|
||||
InstanceOptionalReference parent = AZStd::nullopt,
|
||||
const InstantiatedEntitiesCallback& instantiatedEntitiesCallback = {}) = 0;
|
||||
virtual AZStd::unique_ptr<Instance> CreatePrefab(const AZStd::vector<AZ::Entity*>& entities,
|
||||
AZStd::vector<AZStd::unique_ptr<Instance>>&& instancesToConsume, AZ::IO::PathView filePath,
|
||||
AZStd::unique_ptr<AZ::Entity> containerEntity = nullptr, InstanceOptionalReference parent = AZStd::nullopt,
|
||||
|
||||
Reference in New Issue
Block a user