Added "IsReadyToSpawn" to help detect when a spawner is ready to start spawning. Also added a small optimization to SetDynamicSliceByAssetId so that it doesn't do anything when setting it to the same value as before.

(cherry picked from commit ff8a93e71f3017e8555012855f3e2155ec74a405)
This commit is contained in:
mbalfour
2021-04-14 16:09:02 -05:00
parent 7139525abf
commit 3e8625b78b
3 changed files with 20 additions and 11 deletions
@@ -148,6 +148,7 @@ namespace LmbrCentral
->Event("GetCurrentEntitiesFromSpawnedSlice", &SpawnerComponentRequestBus::Events::GetCurrentEntitiesFromSpawnedSlice)
->Event("GetAllCurrentlySpawnedEntities", &SpawnerComponentRequestBus::Events::GetAllCurrentlySpawnedEntities)
->Event("SetDynamicSlice", &SpawnerComponentRequestBus::Events::SetDynamicSliceByAssetId)
->Event("IsReadyToSpawn", &SpawnerComponentRequestBus::Events::IsReadyToSpawn)
;
behaviorContext->EBus<SpawnerComponentNotificationBus>("SpawnerComponentNotificationBus")
@@ -250,17 +251,15 @@ namespace LmbrCentral
//=========================================================================
void SpawnerComponent::SetDynamicSliceByAssetId(AZ::Data::AssetId& assetId)
{
auto sliceAsset = AZ::Data::AssetManager::Instance().GetAsset(assetId, AZ::AzTypeInfo<AZ::DynamicSliceAsset>::Uuid(), m_sliceAsset.GetAutoLoadBehavior());
if (m_sliceAsset.GetId() == assetId)
{
return;
}
if (sliceAsset.IsReady())
{
m_sliceAsset = sliceAsset;
}
else
{
AZ::Data::AssetBus::Handler::BusDisconnect();
AZ::Data::AssetBus::Handler::BusConnect(assetId);
}
m_sliceAsset = AZ::Data::AssetManager::Instance().GetAsset(
assetId, AZ::AzTypeInfo<AZ::DynamicSliceAsset>::Uuid(), m_sliceAsset.GetAutoLoadBehavior());
AZ::Data::AssetBus::Handler::BusDisconnect();
AZ::Data::AssetBus::Handler::BusConnect(assetId);
}
//=========================================================================
@@ -444,6 +443,12 @@ namespace LmbrCentral
return entities;
}
//=========================================================================
bool SpawnerComponent::IsReadyToSpawn()
{
return m_sliceAsset.IsReady();
}
//=========================================================================
void SpawnerComponent::OnSlicePreInstantiate(const AZ::Data::AssetId& /*sliceAssetId*/, [[maybe_unused]] const AZ::SliceComponent::SliceInstanceAddress& sliceAddress)
{
@@ -70,7 +70,8 @@ namespace LmbrCentral
AZStd::vector<AzFramework::SliceInstantiationTicket> GetCurrentlySpawnedSlices() override;
bool HasAnyCurrentlySpawnedSlices() override;
AZStd::vector<AZ::EntityId> GetCurrentEntitiesFromSpawnedSlice(const AzFramework::SliceInstantiationTicket& ticket) override;
AZStd::vector<AZ::EntityId> GetAllCurrentlySpawnedEntities();
AZStd::vector<AZ::EntityId> GetAllCurrentlySpawnedEntities() override;
bool IsReadyToSpawn() override;
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
@@ -91,6 +91,9 @@ namespace LmbrCentral
//! Note that spawning is not instant, if a slice hasn't finished spawning then none of its entities are returned.
//! If an entity has been destroyed since it was spawned, its ID is not returned.
virtual AZStd::vector<AZ::EntityId> GetAllCurrentlySpawnedEntities() = 0;
//! Returns whether or not the spawner is in a state that's ready to spawn.
virtual bool IsReadyToSpawn() = 0;
};
using SpawnerComponentRequestBus = AZ::EBus<SpawnerComponentRequests>;