First version of spawning Script Canvas node

This commit is contained in:
sconel
2021-05-21 17:53:45 -07:00
parent 7b525f6a60
commit 68a5216122
8 changed files with 192 additions and 0 deletions
@@ -16,6 +16,7 @@
#include <Libraries/Logic/Logic.h>
#include <Libraries/Math/Math.h>
#include <Libraries/Comparison/Comparison.h>
#include <Libraries/Spawning/Spawning.h>
#include <Libraries/UnitTesting/UnitTestingLibrary.h>
#include <AzCore/std/containers/vector.h>
@@ -33,6 +34,7 @@ namespace ScriptCanvas
Entity::InitNodeRegistry(*g_nodeRegistry);
Comparison::InitNodeRegistry(*g_nodeRegistry);
Time::InitNodeRegistry(*g_nodeRegistry);
Spawning::InitNodeRegistry(*g_nodeRegistry);
String::InitNodeRegistry(*g_nodeRegistry);
Operators::InitNodeRegistry(*g_nodeRegistry);
@@ -61,6 +63,7 @@ namespace ScriptCanvas
Entity::Reflect(reflectContext);
Comparison::Reflect(reflectContext);
Time::Reflect(reflectContext);
Spawning::Reflect(reflectContext);
String::Reflect(reflectContext);
Operators::Reflect(reflectContext);
@@ -90,6 +93,9 @@ namespace ScriptCanvas
componentDescriptors = Time::GetComponentDescriptors();
libraryDescriptors.insert(libraryDescriptors.end(), componentDescriptors.begin(), componentDescriptors.end());
componentDescriptors = Spawning::GetComponentDescriptors();
libraryDescriptors.insert(libraryDescriptors.end(), componentDescriptors.begin(), componentDescriptors.end());
componentDescriptors = String::GetComponentDescriptors();
libraryDescriptors.insert(libraryDescriptors.end(), componentDescriptors.begin(), componentDescriptors.end());
@@ -143,6 +143,17 @@ namespace ScriptCanvas
};
struct Spawning : public LibraryDefinition
{
AZ_RTTI(Spawning, "{41E910AE-FBD2-41AD-9173-5105141F0466}", LibraryDefinition);
static void Reflect(AZ::ReflectContext*);
static void InitNodeRegistry(NodeRegistry& nodeRegistry);
static AZStd::vector<AZ::ComponentDescriptor*> GetComponentDescriptors();
~Spawning() override = default;
};
struct String : public LibraryDefinition
{
AZ_RTTI(String, "{5B700838-21A2-4579-9303-F4A4822AFEF4}", LibraryDefinition);
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<ScriptCanvas Include="Include/ScriptCanvas/Libraries/Spawning/SpawnNodeable.h" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Class Name="SpawnNodeable"
QualifiedName="Nodeables::Spawning::SpawnNodeable"
PreferredClassName="Spawn"
Base="ScriptCanvas::Nodeable"
Icon="Icons/ScriptCanvas/Placeholder.png"
Category="Spawning"
GeneratePropertyFriend="True"
Namespace="ScriptCanvas"
Description="Spawn">
<Input Name="Spawn" Description="">
</Input>
</Class>
</ScriptCanvas>
@@ -0,0 +1,42 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <ScriptCanvas/Libraries/Spawning/SpawnNodeable.h>
namespace ScriptCanvas
{
namespace Nodeables
{
namespace Spawning
{
SpawnNodeable::SpawnNodeable()
{
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()
{
AzFramework::SpawnableEntitiesInterface::Get()->SpawnAllEntities(m_spawnTicket);
}
}
}
}
@@ -0,0 +1,43 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <Include/ScriptCanvas/Libraries/Spawning/SpawnNodeable.generated.h>
#include <AzFramework/Spawnable/SpawnableEntitiesInterface.h>
#include <ScriptCanvas/CodeGen/NodeableCodegen.h>
#include <ScriptCanvas/Core/Node.h>
#include <ScriptCanvas/Core/Nodeable.h>
namespace ScriptCanvas
{
namespace Nodeables
{
namespace Spawning
{
class SpawnNodeable
: public ScriptCanvas::Nodeable
{
SCRIPTCANVAS_NODE(SpawnNodeable);
public:
SpawnNodeable();
SpawnNodeable(const SpawnNodeable& rhs);
private:
AZ::Data::Asset<AzFramework::Spawnable> m_spawnableAsset;
AzFramework::EntitySpawnTicket m_spawnTicket;
};
}
}
}
@@ -0,0 +1,50 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <ScriptCanvas/Libraries/Libraries.h>
#include <ScriptCanvas/Libraries/Spawning/Spawning.h>
namespace ScriptCanvas
{
namespace Library
{
void Spawning::Reflect(AZ::ReflectContext* reflection)
{
if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflection))
{
serializeContext->Class<Spawning, LibraryDefinition>()
->Version(1)
;
AZ::EditContext* editContext = serializeContext->GetEditContext();
if (editContext)
{
editContext->Class<Spawning>("Spawning", "")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::Icon, "Icons/ScriptCanvas/Libraries/Entity.png");
}
}
}
void Spawning::InitNodeRegistry(NodeRegistry& nodeRegistry)
{
AddNodeToRegistry<Spawning, ScriptCanvas::Nodes::SpawnNodeableNode>(nodeRegistry);
}
AZStd::vector<AZ::ComponentDescriptor*> Spawning::GetComponentDescriptors()
{
return AZStd::vector<AZ::ComponentDescriptor*>({
ScriptCanvas::Nodes::SpawnNodeableNode::CreateDescriptor(),
});
}
}
}
@@ -0,0 +1,17 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
// This header is only meant to include the nodes and should not contain
// shared code
#include <ScriptCanvas/Libraries/Spawning/SpawnNodeable.h>
@@ -454,6 +454,11 @@ set(FILES
Include/ScriptCanvas/Libraries/Time/TimerNodeable.h
Include/ScriptCanvas/Libraries/Time/TimerNodeable.cpp
Include/ScriptCanvas/Libraries/Time/TimerNodeable.ScriptCanvasNodeable.xml
Include/ScriptCanvas/Libraries/Spawning/Spawning.cpp
Include/ScriptCanvas/Libraries/Spawning/Spawning.h
Include/ScriptCanvas/Libraries/Spawning/SpawnNodeable.cpp
Include/ScriptCanvas/Libraries/Spawning/SpawnNodeable.h
Include/ScriptCanvas/Libraries/Spawning/SpawnNodeable.ScriptCanvasNodeable.xml
Include/ScriptCanvas/Libraries/String/Contains.cpp
Include/ScriptCanvas/Libraries/String/Contains.h
Include/ScriptCanvas/Libraries/String/Contains.ScriptCanvasGrammar.xml