Add inputs and logic to handle spawn transforms
This commit is contained in:
+8
-1
@@ -11,8 +11,15 @@
|
||||
Namespace="ScriptCanvas"
|
||||
Description="Spawn">
|
||||
|
||||
<Input Name="Spawn" Description="">
|
||||
<Input Name="Request Spawn" OutputName="Spawn Requested">
|
||||
<Parameter Name="Translation" Type="Data::Vector3Type" Description="Position to spawn"/>
|
||||
<Parameter Name="Rotation " Type="Data::Vector3Type" Description="Rotation of spawn (in degrees)"/>
|
||||
<Parameter Name="Scale " Type="Data::NumberType" DefaultValue="1" Description="Scale of spawn"/>
|
||||
</Input>
|
||||
|
||||
<Output Name="On Spawn">
|
||||
<Parameter Name="SpawnedEntitiesList" Type="AZStd::vector<Data::EntityIDType>" Description="List of spawned entities sorted by hiearchy with the root being first"/>
|
||||
</Output>/>
|
||||
|
||||
</Class>
|
||||
</ScriptCanvas>
|
||||
|
||||
@@ -10,8 +10,11 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma optimize("", off)
|
||||
#include <ScriptCanvas/Libraries/Spawning/SpawnNodeable.h>
|
||||
|
||||
#include <AzFramework/Components/TransformComponent.h>
|
||||
|
||||
namespace ScriptCanvas
|
||||
{
|
||||
namespace Nodeables
|
||||
@@ -23,19 +26,73 @@ namespace ScriptCanvas
|
||||
AZ::Data::AssetId cubeAssetId("{90552CB9-2F29-5A2E-976C-61BF7ADACB81}", 272062881);
|
||||
m_spawnableAsset = AZ::Data::AssetManager::Instance().GetAsset<AzFramework::Spawnable>(cubeAssetId, AZ::Data::AssetLoadBehavior::PreLoad);
|
||||
AZ::Data::AssetManager::Instance().BlockUntilLoadComplete(m_spawnableAsset);
|
||||
|
||||
m_spawnTicket = AzFramework::EntitySpawnTicket(m_spawnableAsset);
|
||||
}
|
||||
|
||||
SpawnNodeable::SpawnNodeable(const SpawnNodeable& rhs)
|
||||
{
|
||||
m_spawnableAsset = rhs.m_spawnableAsset;
|
||||
m_spawnTicket = AzFramework::EntitySpawnTicket(rhs.m_spawnableAsset);
|
||||
}
|
||||
|
||||
void SpawnNodeable::Spawn()
|
||||
void SpawnNodeable::OnInitializeExecutionState()
|
||||
{
|
||||
AzFramework::SpawnableEntitiesInterface::Get()->SpawnAllEntities(m_spawnTicket);
|
||||
m_spawnTicket = AzFramework::EntitySpawnTicket(m_spawnableAsset);
|
||||
}
|
||||
|
||||
void SpawnNodeable::OnDeactivate()
|
||||
{
|
||||
m_spawnTicket = AzFramework::EntitySpawnTicket();
|
||||
}
|
||||
|
||||
//void SpawnNodeable::Translation(Data::Vector3Type translation)
|
||||
//{
|
||||
// m_translation = translation;
|
||||
//}
|
||||
|
||||
//void SpawnNodeable::Rotation(Data::Vector3Type rotation)
|
||||
//{
|
||||
// m_rotation = rotation;
|
||||
//}
|
||||
|
||||
//void SpawnNodeable::Scale(Data::Vector3Type scale)
|
||||
//{
|
||||
// m_scale = scale;
|
||||
//}
|
||||
|
||||
void SpawnNodeable::RequestSpawn(Data::Vector3Type translation, Data::Vector3Type rotation, Data::NumberType scale)
|
||||
{
|
||||
auto preSpawnCB = [this, translation, rotation, scale]([[maybe_unused]] AzFramework::EntitySpawnTicket& ticket,
|
||||
AzFramework::SpawnableEntityContainerView view)
|
||||
{
|
||||
|
||||
AZ::Entity* rootEntity = *view.begin();
|
||||
|
||||
AzFramework::TransformComponent* entityTransform =
|
||||
rootEntity->FindComponent<AzFramework::TransformComponent>();
|
||||
|
||||
if (entityTransform)
|
||||
{
|
||||
AZ::Vector3 rotationCopy = rotation;
|
||||
AZ::Quaternion rotationQuat = AZ::Quaternion::CreateFromEulerAnglesDegrees(rotationCopy);
|
||||
|
||||
entityTransform->SetWorldTM(AZ::Transform(translation, rotationQuat, AZ::Vector3(scale, scale, scale)));
|
||||
}
|
||||
};
|
||||
|
||||
auto spawnCompleteCB = [this]([[maybe_unused]] AzFramework::EntitySpawnTicket& ticket,
|
||||
AzFramework::SpawnableConstEntityContainerView view)
|
||||
{
|
||||
AZStd::vector<Data::EntityIDType> spawnedEntities;
|
||||
spawnedEntities.resize(view.size());
|
||||
|
||||
for (const AZ::Entity* entity : view)
|
||||
{
|
||||
spawnedEntities.emplace_back(entity->GetId());
|
||||
}
|
||||
|
||||
CallOnSpawn(spawnedEntities);
|
||||
};
|
||||
|
||||
AzFramework::SpawnableEntitiesInterface::Get()->SpawnAllEntities(m_spawnTicket, preSpawnCB, spawnCompleteCB);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,10 @@ namespace ScriptCanvas
|
||||
|
||||
SpawnNodeable(const SpawnNodeable& rhs);
|
||||
|
||||
void OnInitializeExecutionState() override;
|
||||
|
||||
void OnDeactivate() override;
|
||||
|
||||
private:
|
||||
AZ::Data::Asset<AzFramework::Spawnable> m_spawnableAsset;
|
||||
AzFramework::EntitySpawnTicket m_spawnTicket;
|
||||
|
||||
Reference in New Issue
Block a user