SpawnableTestFixture.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AzCore/std/containers/vector.h>
  9. #include <AzFramework/Components/TransformComponent.h>
  10. #include <AzToolsFramework/Prefab/PrefabDomTypes.h>
  11. #include <AzToolsFramework/Prefab/Spawnable/SpawnableUtils.h>
  12. #include <Prefab/Spawnable/SpawnableTestFixture.h>
  13. namespace UnitTest
  14. {
  15. AZStd::unique_ptr<AZ::Entity> SpawnableTestFixture::CreateEntity(const char* entityName, AZ::EntityId parentId)
  16. {
  17. auto result = AZStd::make_unique<AZ::Entity>(entityName);
  18. auto transformComponent = result->CreateComponent<AzFramework::TransformComponent>();
  19. transformComponent->SetParent(parentId);
  20. return result;
  21. }
  22. AZ::Data::Asset<AzFramework::Spawnable> SpawnableTestFixture::CreateSpawnableAsset(uint64_t entityCount)
  23. {
  24. // The life cycle of a spawnable is managed through the asset.
  25. AzFramework::Spawnable* spawnable = new AzFramework::Spawnable(
  26. AZ::Data::AssetId::CreateString("{612F2AB1-30DF-44BB-AFBE-17A85199F09E}:0"), AZ::Data::AssetData::AssetStatus::Ready);
  27. AzFramework::Spawnable::EntityList& entities = spawnable->GetEntities();
  28. entities.reserve(entityCount);
  29. for (uint64_t i = 0; i < entityCount; i++)
  30. {
  31. entities.emplace_back(CreateEntity("Entity"));
  32. }
  33. return AZ::Data::Asset<AzFramework::Spawnable>(spawnable, AZ::Data::AssetLoadBehavior::Default);
  34. }
  35. } // namespace UnitTest