Add a new auto test for delete prefab workflow (#3143)
* Add a new auto test for delete prefab Signed-off-by: chiyteng <chiyteng@amazon.com>
This commit is contained in:
@@ -61,7 +61,7 @@ namespace AzToolsFramework
|
||||
m_prefabUndoCache.Destroy();
|
||||
}
|
||||
|
||||
PrefabOperationResult PrefabPublicHandler::CreatePrefabInMemory(const AZStd::vector<AZ::EntityId>& entityIds, AZ::IO::PathView filePath)
|
||||
PrefabOperationResult PrefabPublicHandler::CreatePrefabInMemory(const EntityIdList& entityIds, AZ::IO::PathView filePath)
|
||||
{
|
||||
EntityList inputEntityList, topLevelEntities;
|
||||
AZ::EntityId commonRootEntityId;
|
||||
@@ -264,7 +264,7 @@ namespace AzToolsFramework
|
||||
return AZ::Success();
|
||||
}
|
||||
|
||||
PrefabOperationResult PrefabPublicHandler::CreatePrefabInDisk(const AZStd::vector<AZ::EntityId>& entityIds, AZ::IO::PathView filePath)
|
||||
PrefabOperationResult PrefabPublicHandler::CreatePrefabInDisk(const EntityIdList& entityIds, AZ::IO::PathView filePath)
|
||||
{
|
||||
auto result = CreatePrefabInMemory(entityIds, filePath);
|
||||
if (result.IsSuccess())
|
||||
|
||||
@@ -43,9 +43,9 @@ namespace AzToolsFramework
|
||||
|
||||
// PrefabPublicInterface...
|
||||
PrefabOperationResult CreatePrefabInDisk(
|
||||
const AZStd::vector<AZ::EntityId>& entityIds, AZ::IO::PathView filePath) override;
|
||||
const EntityIdList& entityIds, AZ::IO::PathView filePath) override;
|
||||
PrefabOperationResult CreatePrefabInMemory(
|
||||
const AZStd::vector<AZ::EntityId>& entityIds, AZ::IO::PathView filePath) override;
|
||||
const EntityIdList& entityIds, AZ::IO::PathView filePath) override;
|
||||
InstantiatePrefabResult InstantiatePrefab(AZStd::string_view filePath, AZ::EntityId parent, const AZ::Vector3& position) override;
|
||||
PrefabOperationResult SavePrefab(AZ::IO::Path filePath) override;
|
||||
PrefabEntityResult CreateEntity(AZ::EntityId parentId, const AZ::Vector3& position) override;
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace AzToolsFramework
|
||||
* @return An outcome object; on failure, it comes with an error message detailing the cause of the error.
|
||||
*/
|
||||
virtual PrefabOperationResult CreatePrefabInDisk(
|
||||
const AZStd::vector<AZ::EntityId>& entityIds, AZ::IO::PathView filePath) = 0;
|
||||
const EntityIdList& entityIds, AZ::IO::PathView filePath) = 0;
|
||||
|
||||
/**
|
||||
* Create a prefab out of the entities provided, at the path provided, and keep it in memory.
|
||||
@@ -57,7 +57,7 @@ namespace AzToolsFramework
|
||||
* @return An outcome object; on failure, it comes with an error message detailing the cause of the error.
|
||||
*/
|
||||
virtual PrefabOperationResult CreatePrefabInMemory(
|
||||
const AZStd::vector<AZ::EntityId>& entityIds, AZ::IO::PathView filePath) = 0;
|
||||
const EntityIdList& entityIds, AZ::IO::PathView filePath) = 0;
|
||||
|
||||
/**
|
||||
* Instantiate a prefab from a prefab file.
|
||||
|
||||
@@ -11,13 +11,20 @@
|
||||
#include <AzCore/Component/EntityId.h>
|
||||
#include <AzCore/EBus/EBus.h>
|
||||
#include <AzCore/Math/Vector3.h>
|
||||
#include <AzCore/Outcome/Outcome.h>
|
||||
#include <AzCore/std/containers/vector.h>
|
||||
#include <AzCore/std/string/string.h>
|
||||
#include <AzCore/std/string/string_view.h>
|
||||
|
||||
namespace AzToolsFramework
|
||||
{
|
||||
using EntityIdList = AZStd::vector<AZ::EntityId>;
|
||||
|
||||
namespace Prefab
|
||||
{
|
||||
using PrefabOperationResult = AZ::Outcome<void, AZStd::string>;
|
||||
using InstantiatePrefabResult = AZ::Outcome<AZ::EntityId, AZStd::string>;
|
||||
|
||||
/**
|
||||
* The primary purpose of this bus is to facilitate writing automated tests for prefabs.
|
||||
* It calls PrefabPublicInterface internally to talk to the prefab system.
|
||||
@@ -40,14 +47,25 @@ namespace AzToolsFramework
|
||||
/**
|
||||
* Create a prefab out of the entities provided, at the path provided, and keep it in memory.
|
||||
* Automatically detects descendants of entities, and discerns between entities and child instances.
|
||||
* Return whether the creation succeeded or not.
|
||||
*/
|
||||
virtual bool CreatePrefabInMemory(
|
||||
const AZStd::vector<AZ::EntityId>& entityIds, AZStd::string_view filePath) = 0;
|
||||
virtual PrefabOperationResult CreatePrefabInMemory(
|
||||
const EntityIdList& entityIds, AZStd::string_view filePath) = 0;
|
||||
|
||||
/**
|
||||
* Instantiate a prefab from a prefab file.
|
||||
* Return the container entity id of the prefab instantiated if instantiation succeeded.
|
||||
*/
|
||||
virtual AZ::EntityId InstantiatePrefab(AZStd::string_view filePath, AZ::EntityId parent, const AZ::Vector3& position) = 0;
|
||||
virtual InstantiatePrefabResult InstantiatePrefab(
|
||||
AZStd::string_view filePath, AZ::EntityId parent, const AZ::Vector3& position) = 0;
|
||||
|
||||
/**
|
||||
* Deletes all entities and their descendants from the owning instance. Bails if the entities don't
|
||||
* all belong to the same instance.
|
||||
* Return whether the deletion succeeded or not.
|
||||
*/
|
||||
virtual PrefabOperationResult DeleteEntitiesAndAllDescendantsInInstance(const EntityIdList& entityIds) = 0;
|
||||
|
||||
};
|
||||
|
||||
using PrefabPublicRequestBus = AZ::EBus<PrefabPublicRequests>;
|
||||
|
||||
+11
-26
@@ -25,6 +25,7 @@ namespace AzToolsFramework
|
||||
->Attribute(AZ::Script::Attributes::Module, "prefab")
|
||||
->Event("CreatePrefabInMemory", &PrefabPublicRequests::CreatePrefabInMemory)
|
||||
->Event("InstantiatePrefab", &PrefabPublicRequests::InstantiatePrefab)
|
||||
->Event("DeleteEntitiesAndAllDescendantsInInstance", &PrefabPublicRequests::DeleteEntitiesAndAllDescendantsInInstance)
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -44,36 +45,20 @@ namespace AzToolsFramework
|
||||
m_prefabPublicInterface = nullptr;
|
||||
}
|
||||
|
||||
bool PrefabPublicRequestHandler::CreatePrefabInMemory(const AZStd::vector<AZ::EntityId>& entityIds, AZStd::string_view filePath)
|
||||
PrefabOperationResult PrefabPublicRequestHandler::CreatePrefabInMemory(const EntityIdList& entityIds, AZStd::string_view filePath)
|
||||
{
|
||||
auto createPrefabOutcome = m_prefabPublicInterface->CreatePrefabInMemory(entityIds, filePath);
|
||||
if (!createPrefabOutcome.IsSuccess())
|
||||
{
|
||||
AZ_Error("CreatePrefabInMemory", false,
|
||||
"Failed to create Prefab on file path '%.*s'. Error message: %s.",
|
||||
AZ_STRING_ARG(filePath),
|
||||
createPrefabOutcome.GetError().c_str());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return m_prefabPublicInterface->CreatePrefabInMemory(entityIds, filePath);
|
||||
}
|
||||
|
||||
AZ::EntityId PrefabPublicRequestHandler::InstantiatePrefab(AZStd::string_view filePath, AZ::EntityId parent, const AZ::Vector3& position)
|
||||
InstantiatePrefabResult PrefabPublicRequestHandler::InstantiatePrefab(AZStd::string_view filePath, AZ::EntityId parent, const AZ::Vector3& position)
|
||||
{
|
||||
auto instantiatePrefabOutcome = m_prefabPublicInterface->InstantiatePrefab(filePath, parent, position);
|
||||
if (!instantiatePrefabOutcome.IsSuccess())
|
||||
{
|
||||
AZ_Error("InstantiatePrefab", false,
|
||||
"Failed to instantiate Prefab on file path '%.*s'. Error message: %s.",
|
||||
AZ_STRING_ARG(filePath),
|
||||
instantiatePrefabOutcome.GetError().c_str());
|
||||
|
||||
return AZ::EntityId();
|
||||
}
|
||||
|
||||
return instantiatePrefabOutcome.GetValue();
|
||||
return m_prefabPublicInterface->InstantiatePrefab(filePath, parent, position);
|
||||
}
|
||||
|
||||
PrefabOperationResult PrefabPublicRequestHandler::DeleteEntitiesAndAllDescendantsInInstance(const EntityIdList& entityIds)
|
||||
{
|
||||
return m_prefabPublicInterface->DeleteEntitiesAndAllDescendantsInInstance(entityIds);
|
||||
}
|
||||
|
||||
} // namespace Prefab
|
||||
} // namespace AzToolsFramework
|
||||
|
||||
+3
-2
@@ -31,8 +31,9 @@ namespace AzToolsFramework
|
||||
void Connect();
|
||||
void Disconnect();
|
||||
|
||||
bool CreatePrefabInMemory(const AZStd::vector<AZ::EntityId>& entityIds, AZStd::string_view filePath) override;
|
||||
AZ::EntityId InstantiatePrefab(AZStd::string_view filePath, AZ::EntityId parent, const AZ::Vector3& position) override;
|
||||
PrefabOperationResult CreatePrefabInMemory(const EntityIdList& entityIds, AZStd::string_view filePath) override;
|
||||
InstantiatePrefabResult InstantiatePrefab(AZStd::string_view filePath, AZ::EntityId parent, const AZ::Vector3& position) override;
|
||||
PrefabOperationResult DeleteEntitiesAndAllDescendantsInInstance(const EntityIdList& entityIds) override;
|
||||
|
||||
private:
|
||||
PrefabPublicInterface* m_prefabPublicInterface = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user