merge stabilization/2106 into development
Signed-off-by: hultonha <hultonha@amazon.co.uk>
This commit is contained in:
@@ -19,19 +19,30 @@
|
||||
#include <AzFramework/StringFunc/StringFunc.h>
|
||||
#include <AzToolsFramework/API/EditorAssetSystemAPI.h>
|
||||
#include <AzToolsFramework/API/ToolsApplicationAPI.h>
|
||||
|
||||
#include <Core/ScriptCanvasBus.h>
|
||||
#include <Editor/Assets/ScriptCanvasAssetTrackerBus.h>
|
||||
#include <ScriptCanvas/Asset/RuntimeAsset.h>
|
||||
#include <ScriptCanvas/Asset/RuntimeAsset.h>
|
||||
#include <ScriptCanvas/Assets/ScriptCanvasAsset.h>
|
||||
#include <ScriptCanvas/Bus/RequestBus.h>
|
||||
#include <ScriptCanvas/Components/EditorGraph.h>
|
||||
#include <ScriptCanvas/Components/EditorGraphVariableManagerComponent.h>
|
||||
#include <ScriptCanvas/Components/EditorScriptCanvasComponent.h>
|
||||
#include <ScriptCanvas/Core/Node.h>
|
||||
#include <ScriptCanvas/Execution/RuntimeComponent.h>
|
||||
#include <ScriptCanvas/PerformanceStatisticsBus.h>
|
||||
|
||||
|
||||
namespace EditorScriptCanvasComponentCpp
|
||||
{
|
||||
enum Version
|
||||
{
|
||||
PrefabIntegration = 10,
|
||||
|
||||
// add description above
|
||||
Current
|
||||
};
|
||||
}
|
||||
|
||||
namespace ScriptCanvasEditor
|
||||
{
|
||||
static bool EditorScriptCanvasComponentVersionConverter(AZ::SerializeContext& serializeContext, AZ::SerializeContext::DataElementNode& rootElement)
|
||||
@@ -74,6 +85,63 @@ namespace ScriptCanvasEditor
|
||||
rootElement.RemoveElementByName(AZ_CRC("m_variableEntityIdMap", 0xdc6c75a8));
|
||||
}
|
||||
|
||||
if (rootElement.GetVersion() <= EditorScriptCanvasComponentCpp::Version::PrefabIntegration)
|
||||
{
|
||||
auto variableDataElementIndex = rootElement.FindElement(AZ_CRC_CE("m_variableData"));
|
||||
if (variableDataElementIndex == -1)
|
||||
{
|
||||
AZ_Error("ScriptCanvas", false, "EditorScriptCanvasComponent conversion failed: 'm_variableData' index was missing");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto& variableDataElement = rootElement.GetSubElement(variableDataElementIndex);
|
||||
|
||||
ScriptCanvas::EditableVariableData editableData;
|
||||
if (!variableDataElement.GetData(editableData))
|
||||
{
|
||||
AZ_Error("ScriptCanvas", false, "EditorScriptCanvasComponent conversion failed: could not retrieve old 'm_variableData'");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto scriptCanvasAssetHolderElementIndex = rootElement.FindElement(AZ_CRC_CE("m_assetHolder"));
|
||||
if (scriptCanvasAssetHolderElementIndex == -1)
|
||||
{
|
||||
AZ_Error("ScriptCanvas", false, "EditorScriptCanvasComponent conversion failed: 'm_assetHolder' index was missing");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto& scriptCanvasAssetHolderElement = rootElement.GetSubElement(scriptCanvasAssetHolderElementIndex);
|
||||
|
||||
ScriptCanvasAssetHolder assetHolder;
|
||||
if (!scriptCanvasAssetHolderElement.GetData(assetHolder))
|
||||
{
|
||||
AZ_Error("ScriptCanvas", false, "EditorScriptCanvasComponent conversion failed: could not retrieve old 'm_assetHolder'");
|
||||
return false;
|
||||
}
|
||||
|
||||
rootElement.RemoveElement(variableDataElementIndex);
|
||||
|
||||
if (!rootElement.AddElementWithData(serializeContext, "runtimeDataIsValid", true))
|
||||
{
|
||||
AZ_Error("ScriptCanvas", false, "EditorScriptCanvasComponent conversion failed: failed to add 'runtimeDataIsValid'");
|
||||
return false;
|
||||
}
|
||||
|
||||
ScriptCanvasBuilder::BuildVariableOverrides overrides;
|
||||
overrides.m_source = AZ::Data::Asset<ScriptCanvasEditor::ScriptCanvasAsset>(assetHolder.GetAssetId(), assetHolder.GetAssetType(), assetHolder.GetAssetHint());;
|
||||
|
||||
for (auto& variable : editableData.GetVariables())
|
||||
{
|
||||
overrides.m_overrides.push_back(variable.m_graphVariable);
|
||||
}
|
||||
|
||||
if (!rootElement.AddElementWithData(serializeContext, "runtimeDataOverrides", overrides))
|
||||
{
|
||||
AZ_Error("ScriptCanvas", false, "EditorScriptCanvasComponent conversion failed: failed to add 'runtimeDataOverrides'");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -83,10 +151,11 @@ namespace ScriptCanvasEditor
|
||||
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
|
||||
{
|
||||
serializeContext->Class<EditorScriptCanvasComponent, EditorComponentBase>()
|
||||
->Version(8, &EditorScriptCanvasComponentVersionConverter)
|
||||
->Version(EditorScriptCanvasComponentCpp::Version::Current, &EditorScriptCanvasComponentVersionConverter)
|
||||
->Field("m_name", &EditorScriptCanvasComponent::m_name)
|
||||
->Field("m_assetHolder", &EditorScriptCanvasComponent::m_scriptCanvasAssetHolder)
|
||||
->Field("m_variableData", &EditorScriptCanvasComponent::m_editableData)
|
||||
->Field("runtimeDataIsValid", &EditorScriptCanvasComponent::m_runtimeDataIsValid)
|
||||
->Field("runtimeDataOverrides", &EditorScriptCanvasComponent::m_variableOverrides)
|
||||
;
|
||||
|
||||
if (AZ::EditContext* editContext = serializeContext->GetEditContext())
|
||||
@@ -103,9 +172,9 @@ namespace ScriptCanvasEditor
|
||||
->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("Level", 0x9aeacc13))
|
||||
->Attribute(AZ::Edit::Attributes::HelpPageURL, "https://o3de.org/docs/user-guide/components/reference/script-canvas/")
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &EditorScriptCanvasComponent::m_scriptCanvasAssetHolder, "Script Canvas Asset", "Script Canvas asset associated with this component")
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &EditorScriptCanvasComponent::m_editableData, "Properties", "Script Canvas Graph Properties")
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &EditorScriptCanvasComponent::m_variableOverrides, "Properties", "Script Canvas Graph Properties")
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -133,6 +202,11 @@ namespace ScriptCanvasEditor
|
||||
AzFramework::AssetCatalogEventBus::Handler::BusDisconnect();
|
||||
}
|
||||
|
||||
const AZStd::string& EditorScriptCanvasComponent::GetName() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
void EditorScriptCanvasComponent::UpdateName()
|
||||
{
|
||||
AZ::Data::AssetId assetId = m_scriptCanvasAssetHolder.GetAssetId();
|
||||
@@ -208,18 +282,7 @@ namespace ScriptCanvasEditor
|
||||
if (fileAssetId.IsValid())
|
||||
{
|
||||
AssetTrackerNotificationBus::Handler::BusConnect(fileAssetId);
|
||||
|
||||
ScriptCanvasMemoryAsset::pointer memoryAsset;
|
||||
AssetTrackerRequestBus::BroadcastResult(memoryAsset, &AssetTrackerRequests::GetAsset, fileAssetId);
|
||||
|
||||
if (memoryAsset && memoryAsset->GetAsset().GetStatus() == AZ::Data::AssetData::AssetStatus::Ready)
|
||||
{
|
||||
OnScriptCanvasAssetReady(memoryAsset);
|
||||
}
|
||||
else
|
||||
{
|
||||
AssetTrackerRequestBus::Broadcast(&AssetTrackerRequests::Load, m_scriptCanvasAssetHolder.GetAssetId(), m_scriptCanvasAssetHolder.GetAssetType(), nullptr);
|
||||
}
|
||||
AzToolsFramework::ToolsApplicationNotificationBus::Broadcast(&AzToolsFramework::ToolsApplicationEvents::InvalidatePropertyDisplay, AzToolsFramework::Refresh_EntireTree_NewContent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,81 +296,67 @@ namespace ScriptCanvasEditor
|
||||
|
||||
EditorComponentBase::Deactivate();
|
||||
|
||||
//EditorScriptCanvasAssetNotificationBus::Handler::BusDisconnect();
|
||||
EditorScriptCanvasComponentRequestBus::Handler::BusDisconnect();
|
||||
EditorContextMenuRequestBus::Handler::BusDisconnect();
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
void EditorScriptCanvasComponent::BuildGameEntityData()
|
||||
{
|
||||
using namespace ScriptCanvasBuilder;
|
||||
|
||||
m_runtimeDataIsValid = false;
|
||||
|
||||
auto assetTreeOutcome = LoadEditorAssetTree(m_scriptCanvasAssetHolder.GetAssetId(), m_scriptCanvasAssetHolder.GetAssetHint());
|
||||
if (!assetTreeOutcome.IsSuccess())
|
||||
{
|
||||
AZ_Warning("ScriptCanvas", false, "EditorScriptCanvasComponent::BuildGameEntityData failed: %s", assetTreeOutcome.GetError().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
EditorAssetTree& editorAssetTree = assetTreeOutcome.GetValue();
|
||||
|
||||
auto parseOutcome = ParseEditorAssetTree(editorAssetTree);
|
||||
if (!parseOutcome.IsSuccess())
|
||||
{
|
||||
AZ_Warning("ScriptCanvas", false, "EditorScriptCanvasComponent::BuildGameEntityData failed: %s", parseOutcome.GetError().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
auto& variableOverrides = parseOutcome.GetValue();
|
||||
|
||||
if (!m_variableOverrides.IsEmpty())
|
||||
{
|
||||
variableOverrides.CopyPreviousOverriddenValues(m_variableOverrides);
|
||||
}
|
||||
|
||||
m_variableOverrides = parseOutcome.TakeValue();
|
||||
m_runtimeDataIsValid = true;
|
||||
}
|
||||
|
||||
void EditorScriptCanvasComponent::BuildGameEntity(AZ::Entity* gameEntity)
|
||||
{
|
||||
AZ::Data::AssetId editorAssetId = m_scriptCanvasAssetHolder.GetAssetId();
|
||||
|
||||
if (!editorAssetId.IsValid())
|
||||
if (!m_runtimeDataIsValid)
|
||||
{
|
||||
// this is fine, there could have been no graph set, or set to a graph that failed to compile
|
||||
return;
|
||||
}
|
||||
|
||||
AZ::Data::AssetId runtimeAssetId(editorAssetId.m_guid, AZ_CRC("RuntimeData", 0x163310ae));
|
||||
AZ::Data::Asset<ScriptCanvas::RuntimeAsset> runtimeAsset(runtimeAssetId, azrtti_typeid<ScriptCanvas::RuntimeAsset>(), {});
|
||||
// build everything again as a sanity check against dependencies. All of the variable overrides that were valid will be copied over
|
||||
BuildGameEntityData();
|
||||
|
||||
/*
|
||||
|
||||
This defense against creating useless runtime components is pending changes the slice update system.
|
||||
It also would require better abilities to check asset integrity when building assets that depend
|
||||
on ScriptCanvas assets.
|
||||
|
||||
AZ::Data::AssetInfo assetInfo;
|
||||
AZ::Data::AssetCatalogRequestBus::BroadcastResult(assetInfo, &AZ::Data::AssetCatalogRequestBus::Events::GetAssetInfoById, runtimeAssetId);
|
||||
|
||||
if (assetInfo.m_assetType == AZ::Data::s_invalidAssetType)
|
||||
if (!m_runtimeDataIsValid)
|
||||
{
|
||||
AZ_Warning("ScriptCanvas", false, "No ScriptCanvas Runtime Asset information for Entity ('%s' - '%s') Graph ('%s'), asset may be in error or deleted"
|
||||
, gameEntity->GetName().c_str()
|
||||
, GetEntityId().ToString().c_str()
|
||||
, GetName().c_str());
|
||||
AZ_Error("ScriptCanvasBuilder", false, "Runtime information did not build for ScriptCanvas Component using asset: %s", m_scriptCanvasAssetHolder.GetAssetId().ToString<AZStd::string>().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
AzFramework::AssetSystem::AssetStatus statusResult = AzFramework::AssetSystem::AssetStatus_Unknown;
|
||||
AzFramework::AssetSystemRequestBus::BroadcastResult(statusResult, &AzFramework::AssetSystem::AssetSystemRequests::GetAssetStatusById, runtimeAssetId);
|
||||
|
||||
if (statusResult != AzFramework::AssetSystem::AssetStatus_Compiled)
|
||||
{
|
||||
AZ_Warning("ScriptCanvas", false, "No ScriptCanvas Runtime Asset for Entity ('%s' - '%s') Graph ('%s'), compilation may have failed or not completed"
|
||||
, gameEntity->GetName().c_str()
|
||||
, GetEntityId().ToString().c_str()
|
||||
, GetName().c_str());
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
// #functions2 dependency-ctor-args make recursive
|
||||
auto executionComponent = gameEntity->CreateComponent<ScriptCanvas::RuntimeComponent>(runtimeAsset);
|
||||
ScriptCanvas::VariableData varData;
|
||||
|
||||
for (const auto& varConfig : m_editableData.GetVariables())
|
||||
{
|
||||
if (varConfig.m_graphVariable.GetDatum()->Empty())
|
||||
{
|
||||
AZ_Error("ScriptCanvas", false, "Data loss detected for GraphVariable ('%s') on Entity ('%s' - '%s') Graph ('%s')"
|
||||
, varConfig.m_graphVariable.GetVariableName().data()
|
||||
, gameEntity->GetName().c_str()
|
||||
, GetEntityId().ToString().c_str()
|
||||
, GetName().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
varData.AddVariable(varConfig.m_graphVariable.GetVariableName(), varConfig.m_graphVariable);
|
||||
}
|
||||
}
|
||||
|
||||
executionComponent->SetVariableOverrides(varData);
|
||||
auto runtimeComponent = gameEntity->CreateComponent<ScriptCanvas::RuntimeComponent>();
|
||||
auto runtimeOverrides = ConvertToRuntime(m_variableOverrides);
|
||||
runtimeComponent->SetRuntimeDataOverrides(runtimeOverrides);
|
||||
}
|
||||
|
||||
void EditorScriptCanvasComponent::OnCatalogAssetAdded(const AZ::Data::AssetId& assetId)
|
||||
{
|
||||
// If we removed out asset due to the catalog removing. Just set it back.
|
||||
if (m_removedCatalogId == assetId)
|
||||
{
|
||||
if (!m_scriptCanvasAssetHolder.GetAssetId().IsValid())
|
||||
@@ -317,12 +366,9 @@ namespace ScriptCanvasEditor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EditorScriptCanvasComponent::OnCatalogAssetRemoved(const AZ::Data::AssetId& removedAssetId, const AZ::Data::AssetInfo& /*assetInfo*/)
|
||||
{
|
||||
AZ::Data::AssetId assetId = m_scriptCanvasAssetHolder.GetAssetId();
|
||||
|
||||
// If the Asset gets removed from disk while the Editor is loaded clear out the asset reference.
|
||||
if (assetId == removedAssetId)
|
||||
{
|
||||
m_removedCatalogId = assetId;
|
||||
@@ -355,8 +401,6 @@ namespace ScriptCanvasEditor
|
||||
}
|
||||
}
|
||||
|
||||
AzToolsFramework::ScopedUndoBatch undo("Update Entity With New SC Graph");
|
||||
AzToolsFramework::ToolsApplicationRequests::Bus::Broadcast(&AzToolsFramework::ToolsApplicationRequests::Bus::Events::AddDirtyEntity, GetEntityId());
|
||||
AzToolsFramework::ToolsApplicationEvents::Bus::Broadcast(&AzToolsFramework::ToolsApplicationEvents::InvalidatePropertyDisplay, AzToolsFramework::Refresh_AttributesAndValues);
|
||||
}
|
||||
|
||||
@@ -448,7 +492,6 @@ namespace ScriptCanvasEditor
|
||||
{
|
||||
// Invalidate the previously removed catalog id if we are setting a new asset id
|
||||
m_removedCatalogId.SetInvalid();
|
||||
|
||||
SetPrimaryAsset(assetId);
|
||||
}
|
||||
}
|
||||
@@ -469,125 +512,17 @@ namespace ScriptCanvasEditor
|
||||
{
|
||||
if (memoryAsset->GetFileAssetId() == m_scriptCanvasAssetHolder.GetAssetId())
|
||||
{
|
||||
LoadVariables(memoryAsset);
|
||||
auto assetData = memoryAsset->GetAsset();
|
||||
[[maybe_unused]] AZ::Entity* scriptCanvasEntity = assetData->GetScriptCanvasEntity();
|
||||
AZ_Assert(scriptCanvasEntity, "This graph must have a valid entity");
|
||||
BuildGameEntityData();
|
||||
AzToolsFramework::ToolsApplicationNotificationBus::Broadcast(&AzToolsFramework::ToolsApplicationEvents::InvalidatePropertyDisplay, AzToolsFramework::Refresh_EntireTree_NewContent);
|
||||
UpdateName();
|
||||
}
|
||||
}
|
||||
|
||||
/*! Start Variable Block Implementation */
|
||||
void EditorScriptCanvasComponent::AddVariable(AZStd::string_view varName, const ScriptCanvas::GraphVariable& graphVariable)
|
||||
{
|
||||
// We only add component properties to the component
|
||||
if (!graphVariable.IsComponentProperty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& variableId = graphVariable.GetVariableId();
|
||||
ScriptCanvas::EditableVariableConfiguration* originalVarNameValuePair = m_editableData.FindVariable(variableId);
|
||||
if (!originalVarNameValuePair)
|
||||
{
|
||||
m_editableData.AddVariable(varName, graphVariable);
|
||||
originalVarNameValuePair = m_editableData.FindVariable(variableId);
|
||||
}
|
||||
|
||||
if (!originalVarNameValuePair)
|
||||
{
|
||||
AZ_Error("Script Canvas", false, "Unable to find variable with id %s and name %s on the ScriptCanvas Component. There is an issue in AddVariable",
|
||||
variableId.ToString().data(), varName.data());
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the variable name as it may have changed
|
||||
originalVarNameValuePair->m_graphVariable.SetVariableName(varName);
|
||||
originalVarNameValuePair->m_graphVariable.SetExposureCategory(graphVariable.GetExposureCategory());
|
||||
originalVarNameValuePair->m_graphVariable.SetScriptInputControlVisibility(AZ::Edit::PropertyVisibility::Hide);
|
||||
originalVarNameValuePair->m_graphVariable.SetAllowSignalOnChange(false);
|
||||
}
|
||||
|
||||
void EditorScriptCanvasComponent::AddNewVariables(const ScriptCanvas::VariableData& graphVarData)
|
||||
{
|
||||
for (auto&& variablePair : graphVarData.GetVariables())
|
||||
{
|
||||
AddVariable(variablePair.second.GetVariableName(), variablePair.second);
|
||||
}
|
||||
}
|
||||
|
||||
void EditorScriptCanvasComponent::RemoveVariable(const ScriptCanvas::VariableId& varId)
|
||||
{
|
||||
m_editableData.RemoveVariable(varId);
|
||||
}
|
||||
|
||||
void EditorScriptCanvasComponent::RemoveOldVariables(const ScriptCanvas::VariableData& graphVarData)
|
||||
{
|
||||
AZStd::vector<ScriptCanvas::VariableId> oldVariableIds;
|
||||
for (auto varConfig : m_editableData.GetVariables())
|
||||
{
|
||||
const auto& variableId = varConfig.m_graphVariable.GetVariableId();
|
||||
|
||||
// We only add component sourced graph properties to the script canvas component, so if this variable was switched to a graph-only property remove it.
|
||||
// Also be sure to remove this variable if it's been deleted entirely.
|
||||
auto graphVariable = graphVarData.FindVariable(variableId);
|
||||
if (!graphVariable || !graphVariable->IsComponentProperty())
|
||||
{
|
||||
oldVariableIds.push_back(variableId);
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& oldVariableId : oldVariableIds)
|
||||
{
|
||||
RemoveVariable(oldVariableId);
|
||||
}
|
||||
}
|
||||
|
||||
bool EditorScriptCanvasComponent::UpdateVariable(const ScriptCanvas::GraphVariable& graphDatum, ScriptCanvas::GraphVariable& updateDatum, ScriptCanvas::GraphVariable& originalDatum)
|
||||
{
|
||||
// If the editable datum is the different than the original datum, then the "variable value" has been overridden on this component
|
||||
|
||||
// Variable values only propagate from the Script Canvas graph to this component if the original "variable value" has not been overridden
|
||||
// by the editable "variable value" on this component and the "variable value" on the graph is different than the variable value on this component
|
||||
auto isNotOverridden = (*updateDatum.GetDatum()) == (*originalDatum.GetDatum());
|
||||
auto scGraphIsModified = (*originalDatum.GetDatum()) != (*graphDatum.GetDatum());
|
||||
|
||||
if (isNotOverridden && scGraphIsModified)
|
||||
{
|
||||
ScriptCanvas::ModifiableDatumView originalDatumView;
|
||||
originalDatum.ConfigureDatumView(originalDatumView);
|
||||
|
||||
originalDatumView.AssignToDatum((*graphDatum.GetDatum()));
|
||||
|
||||
|
||||
ScriptCanvas::ModifiableDatumView updatedDatumView;
|
||||
updateDatum.ConfigureDatumView(updatedDatumView);
|
||||
|
||||
updatedDatumView.AssignToDatum((*graphDatum.GetDatum()));
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void EditorScriptCanvasComponent::LoadVariables(const ScriptCanvasMemoryAsset::pointer memoryAsset)
|
||||
{
|
||||
auto assetData = memoryAsset->GetAsset();
|
||||
|
||||
AZ::Entity* scriptCanvasEntity = assetData->GetScriptCanvasEntity();
|
||||
AZ_Assert(scriptCanvasEntity, "This graph must have a valid entity");
|
||||
|
||||
auto variableComponent = scriptCanvasEntity ? AZ::EntityUtils::FindFirstDerivedComponent<ScriptCanvas::GraphVariableManagerComponent>(scriptCanvasEntity) : nullptr;
|
||||
if (variableComponent)
|
||||
{
|
||||
// Add properties from the SC Asset to the SC Component if they do not exist on the SC Component
|
||||
AddNewVariables(*variableComponent->GetVariableData());
|
||||
RemoveOldVariables(*variableComponent->GetVariableData());
|
||||
}
|
||||
|
||||
AzToolsFramework::ToolsApplicationNotificationBus::Broadcast(&AzToolsFramework::ToolsApplicationEvents::InvalidatePropertyDisplay, AzToolsFramework::Refresh_EntireTree_NewContent);
|
||||
}
|
||||
|
||||
void EditorScriptCanvasComponent::ClearVariables()
|
||||
{
|
||||
m_editableData.Clear();
|
||||
m_variableOverrides.Clear();
|
||||
}
|
||||
/* End Variable Block Implementation*/
|
||||
}
|
||||
|
||||
@@ -19,8 +19,15 @@ namespace ScriptCanvas
|
||||
|
||||
namespace ScriptCanvasEditor
|
||||
{
|
||||
using LoadedInterpretedDependencies = AZStd::vector<AZStd::pair<AZStd::string, ScriptCanvas::Translation::LuaAssetResult>>;
|
||||
AZ_INLINE LoadedInterpretedDependencies LoadInterpretedDepencies(const ScriptCanvas::DependencySet& dependencySet);
|
||||
struct LoadedInterpretedDependency
|
||||
{
|
||||
AZStd::string path;
|
||||
AZ::Data::Asset<ScriptCanvas::RuntimeAsset> runtimeAsset;
|
||||
ScriptCanvas::Translation::LuaAssetResult luaAssetResult;
|
||||
AZStd::vector<LoadedInterpretedDependency> dependencies;
|
||||
};
|
||||
|
||||
AZ_INLINE AZStd::vector<LoadedInterpretedDependency> LoadInterpretedDepencies(const ScriptCanvas::DependencySet& dependencySet);
|
||||
|
||||
AZ_INLINE LoadTestGraphResult LoadTestGraph(AZStd::string_view path);
|
||||
|
||||
@@ -49,10 +56,11 @@ namespace ScriptCanvasEditor
|
||||
AZ_INLINE void RunGraphImplementation(const RunGraphSpec& runGraphSpec, Reporter& reporter);
|
||||
AZ_INLINE void RunGraphImplementation(const RunGraphSpec& runGraphSpec, LoadTestGraphResult& loadGraphResult, Reporter& reporter);
|
||||
AZ_INLINE void RunGraphImplementation(const RunGraphSpec& runGraphSpec, Reporters& reporters);
|
||||
|
||||
|
||||
AZ_INLINE void Simulate(const DurationSpec& duration);
|
||||
AZ_INLINE void SimulateDuration(const DurationSpec& duration);
|
||||
AZ_INLINE void SimulateSeconds(const DurationSpec& duration);
|
||||
AZ_INLINE void SimulateTicks(const DurationSpec& duration);
|
||||
} // ScriptCanvasEditor
|
||||
|
||||
#include <Editor/Framework/ScriptCanvasGraphUtilities.inl>
|
||||
|
||||
@@ -26,9 +26,25 @@ namespace ScriptCanvasEditor
|
||||
{
|
||||
using namespace ScriptCanvas;
|
||||
|
||||
AZ_INLINE LoadedInterpretedDependencies LoadInterpretedDepencies(const ScriptCanvas::DependencySet& dependencySet)
|
||||
// The runtime context (appropriately) always assumes that EntityIds are overridden, this step copies the values from the runtime data
|
||||
// over to the override data to simulate build step that does this when building prefabs
|
||||
AZ_INLINE void CopyAssetEntityIdsToOverrides(RuntimeDataOverrides& runtimeDataOverrides)
|
||||
{
|
||||
LoadedInterpretedDependencies loadedAssets;
|
||||
runtimeDataOverrides.m_entityIds.reserve(runtimeDataOverrides.m_runtimeAsset->GetData().m_input.m_entityIds.size());
|
||||
for (auto& varEntityPar : runtimeDataOverrides.m_runtimeAsset->GetData().m_input.m_entityIds)
|
||||
{
|
||||
runtimeDataOverrides.m_entityIds.push_back(varEntityPar.second);
|
||||
}
|
||||
|
||||
for (auto& dependency : runtimeDataOverrides.m_dependencies)
|
||||
{
|
||||
CopyAssetEntityIdsToOverrides(dependency);
|
||||
}
|
||||
}
|
||||
|
||||
AZ_INLINE AZStd::vector<LoadedInterpretedDependency> LoadInterpretedDepencies(const ScriptCanvas::DependencySet& dependencySet)
|
||||
{
|
||||
AZStd::vector<LoadedInterpretedDependency> loadedAssets;
|
||||
|
||||
if (!dependencySet.empty())
|
||||
{
|
||||
@@ -41,7 +57,7 @@ namespace ScriptCanvasEditor
|
||||
|
||||
AZ_Assert(namespacePath.size() >= 3, "This functions assumes unit test dependencies are in the ScriptCanvas gem unit test folder");
|
||||
AZStd::string originalPath = namespacePath[2].data();
|
||||
|
||||
|
||||
for (size_t index = 3; index < namespacePath.size(); ++index)
|
||||
{
|
||||
originalPath += "/";
|
||||
@@ -52,11 +68,11 @@ namespace ScriptCanvasEditor
|
||||
{
|
||||
originalPath.resize(originalPath.size() - AZStd::string_view(Grammar::k_internalRuntimeSuffix).size());
|
||||
}
|
||||
|
||||
|
||||
AZStd::string path = AZStd::string::format("%s/%s.scriptcanvas", k_unitTestDirPathRelative, originalPath.data());
|
||||
LoadTestGraphResult loadResult = LoadTestGraph(path);
|
||||
AZ_Assert(loadResult.m_runtimeAsset, "failed to load dependent asset");
|
||||
|
||||
|
||||
AZ::Outcome<ScriptCanvas::Translation::LuaAssetResult, AZStd::string> luaAssetOutcome = AZ::Failure(AZStd::string("lua asset creation for function failed"));
|
||||
ScriptCanvasEditor::EditorAssetConversionBus::BroadcastResult(luaAssetOutcome, &ScriptCanvasEditor::EditorAssetConversionBusTraits::CreateLuaAsset, loadResult.m_editorAsset, loadResult.m_graphPath);
|
||||
AZ_Assert(luaAssetOutcome.IsSuccess(), "failed to create Lua asset");
|
||||
@@ -69,8 +85,9 @@ namespace ScriptCanvasEditor
|
||||
}
|
||||
|
||||
const ScriptCanvas::Translation::LuaAssetResult& luaAssetResult = luaAssetOutcome.GetValue();
|
||||
loadedAssets.push_back({ modulePath, luaAssetResult });
|
||||
}
|
||||
// #functions2_recursive_unit_tests
|
||||
loadedAssets.push_back({ modulePath, loadResult.m_runtimeAsset, luaAssetResult, {} });
|
||||
}
|
||||
}
|
||||
|
||||
return loadedAssets;
|
||||
@@ -182,7 +199,7 @@ namespace ScriptCanvasEditor
|
||||
|
||||
RuntimeData runtimeDataBuffer;
|
||||
AZStd::vector<RuntimeData> dependencyDataBuffer;
|
||||
LoadedInterpretedDependencies dependencies;
|
||||
AZStd::vector<LoadedInterpretedDependency> dependencies;
|
||||
|
||||
if (runGraphSpec.runSpec.execution == ExecutionMode::Interpreted)
|
||||
{
|
||||
@@ -202,9 +219,12 @@ namespace ScriptCanvasEditor
|
||||
{
|
||||
dependencies = LoadInterpretedDepencies(luaAssetResult.m_dependencies.source.userSubgraphs);
|
||||
|
||||
RuntimeDataOverrides runtimeDataOverrides;
|
||||
runtimeDataOverrides.m_runtimeAsset = loadResult.m_runtimeAsset;
|
||||
|
||||
if (!dependencies.empty())
|
||||
{
|
||||
// eventually, this will need to be recursive, or the full asset handling system will need to be integrated into the testing framework
|
||||
// #functions2_recursive_unit_tests eventually, this will need to be recursive, or the full asset handling system will need to be integrated into the testing framework
|
||||
// in order to test functionality with a dependency stack greater than 2
|
||||
|
||||
// load all script assets, and their dependencies, initialize statics on all those dependencies if it is the first time loaded
|
||||
@@ -215,7 +235,7 @@ namespace ScriptCanvasEditor
|
||||
|
||||
for (auto& dependency : dependencies)
|
||||
{
|
||||
inMemoryModules.emplace_back(dependency.first, dependency.second.m_scriptAsset);
|
||||
inMemoryModules.emplace_back(dependency.path, dependency.luaAssetResult.m_scriptAsset);
|
||||
}
|
||||
|
||||
AZ::ScriptSystemRequestBus::Broadcast(&AZ::ScriptSystemRequests::UseInMemoryRequireHook, inMemoryModules, AZ::ScriptContextIds::DefaultScriptContextId);
|
||||
@@ -224,7 +244,11 @@ namespace ScriptCanvasEditor
|
||||
for (size_t index = 0; index < dependencies.size(); ++index)
|
||||
{
|
||||
auto& dependency = dependencies[index];
|
||||
const ScriptCanvas::Translation::LuaAssetResult& depencyAssetResult = dependency.second;
|
||||
const ScriptCanvas::Translation::LuaAssetResult& depencyAssetResult = dependency.luaAssetResult;
|
||||
|
||||
RuntimeDataOverrides dependencyRuntimeDataOverrides;
|
||||
dependencyRuntimeDataOverrides.m_runtimeAsset = dependency.runtimeAsset;
|
||||
runtimeDataOverrides.m_dependencies.push_back(dependencyRuntimeDataOverrides);
|
||||
|
||||
RuntimeData& dependencyData = dependencyDataBuffer[index];
|
||||
dependencyData.m_input = depencyAssetResult.m_runtimeInputs;
|
||||
@@ -239,7 +263,9 @@ namespace ScriptCanvasEditor
|
||||
loadResult.m_runtimeAsset.Get()->GetData().m_script = loadResult.m_scriptAsset;
|
||||
loadResult.m_runtimeAsset.Get()->GetData().m_input = luaAssetResult.m_runtimeInputs;
|
||||
loadResult.m_runtimeAsset.Get()->GetData().m_debugMap = luaAssetResult.m_debugMap;
|
||||
loadResult.m_runtimeComponent = loadResult.m_entity->CreateComponent<ScriptCanvas::RuntimeComponent>(loadResult.m_runtimeAsset);
|
||||
loadResult.m_runtimeComponent = loadResult.m_entity->CreateComponent<ScriptCanvas::RuntimeComponent>();
|
||||
CopyAssetEntityIdsToOverrides(runtimeDataOverrides);
|
||||
loadResult.m_runtimeComponent->SetRuntimeDataOverrides(runtimeDataOverrides);
|
||||
Execution::Context::InitializeActivationData(loadResult.m_runtimeAsset->GetData());
|
||||
Execution::InitializeInterpretedStatics(loadResult.m_runtimeAsset->GetData());
|
||||
}
|
||||
|
||||
+9
-21
@@ -8,14 +8,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <AzFramework/Asset/AssetCatalogBus.h>
|
||||
#include <AzToolsFramework/Entity/EditorEntityContextBus.h>
|
||||
#include <AzToolsFramework/ToolsComponents/EditorComponentBase.h>
|
||||
|
||||
#include <Builder/ScriptCanvasBuilder.h>
|
||||
#include <Editor/Assets/ScriptCanvasAssetHolder.h>
|
||||
#include <ScriptCanvas/Assets/ScriptCanvasAssetHandler.h>
|
||||
#include <ScriptCanvas/Bus/EditorScriptCanvasBus.h>
|
||||
#include <ScriptCanvas/Execution/RuntimeComponent.h>
|
||||
#include <ScriptCanvas/Variable/VariableBus.h>
|
||||
#include <ScriptCanvas/Variable/VariableData.h>
|
||||
#include <AzToolsFramework/Entity/EditorEntityContextBus.h>
|
||||
|
||||
namespace ScriptCanvasEditor
|
||||
{
|
||||
@@ -27,11 +27,10 @@ namespace ScriptCanvasEditor
|
||||
which it uses to maintain the asset data in memory. Therefore removing an open ScriptCanvasAsset from the file system
|
||||
will remove the reference from the EditorScriptCanvasComponent, but not the reference from the MainWindow allowing the
|
||||
ScriptCanvas graph to still be modified while open
|
||||
|
||||
Finally per graph instance variables values are stored on the EditorScriptCanvasComponent and injected into the runtime ScriptCanvas component in BuildGameEntity
|
||||
*/
|
||||
class EditorScriptCanvasComponent
|
||||
: public AzToolsFramework::Components::EditorComponentBase
|
||||
: public AzToolsFramework::Components::EditorComponentBase
|
||||
, private EditorContextMenuRequestBus::Handler
|
||||
, private AzFramework::AssetCatalogEventBus::Handler
|
||||
, private EditorScriptCanvasComponentLoggingBus::Handler
|
||||
@@ -54,7 +53,6 @@ namespace ScriptCanvasEditor
|
||||
void Deactivate() override;
|
||||
//=====================================================================
|
||||
|
||||
|
||||
//=====================================================================
|
||||
// EditorComponentBase
|
||||
void BuildGameEntity(AZ::Entity* gameEntity) override;
|
||||
@@ -71,10 +69,10 @@ namespace ScriptCanvasEditor
|
||||
void CloseGraph();
|
||||
|
||||
void SetName(const AZStd::string& name) { m_name = name; }
|
||||
const AZStd::string& GetName() const { return m_name; };
|
||||
const AZStd::string& GetName() const;
|
||||
AZ::EntityId GetEditorEntityId() const { return GetEntity() ? GetEntityId() : AZ::EntityId(); }
|
||||
AZ::NamedEntityId GetNamedEditorEntityId() const { return GetEntity() ? GetNamedEntityId() : AZ::NamedEntityId(); }
|
||||
|
||||
|
||||
//=====================================================================
|
||||
// EditorScriptCanvasComponentRequestBus
|
||||
void SetAssetId(const AZ::Data::AssetId& assetId) override;
|
||||
@@ -119,12 +117,8 @@ namespace ScriptCanvasEditor
|
||||
(void)incompatible;
|
||||
}
|
||||
|
||||
//=====================================================================
|
||||
// AssetCatalogEventBus
|
||||
void OnCatalogAssetAdded(const AZ::Data::AssetId& assetId) override;
|
||||
void OnCatalogAssetRemoved(const AZ::Data::AssetId& assetId, const AZ::Data::AssetInfo& assetInfo) override;
|
||||
//=====================================================================
|
||||
|
||||
void OnScriptCanvasAssetChanged(AZ::Data::AssetId assetId);
|
||||
|
||||
void UpdateName();
|
||||
@@ -133,21 +127,15 @@ namespace ScriptCanvasEditor
|
||||
void OnScriptCanvasAssetReady(const ScriptCanvasMemoryAsset::pointer asset);
|
||||
//=====================================================================
|
||||
|
||||
void AddVariable(AZStd::string_view varName, const ScriptCanvas::GraphVariable& varDatum);
|
||||
void AddNewVariables(const ScriptCanvas::VariableData& graphVarData);
|
||||
void RemoveVariable(const ScriptCanvas::VariableId& varId);
|
||||
void RemoveOldVariables(const ScriptCanvas::VariableData& graphVarData);
|
||||
bool UpdateVariable(const ScriptCanvas::GraphVariable& graphDatum, ScriptCanvas::GraphVariable& updateDatum, ScriptCanvas::GraphVariable& originalDatum);
|
||||
void LoadVariables(const ScriptCanvasMemoryAsset::pointer memoryAsset);
|
||||
void BuildGameEntityData();
|
||||
void ClearVariables();
|
||||
|
||||
private:
|
||||
AZ::Data::AssetId m_removedCatalogId;
|
||||
AZ::Data::AssetId m_previousAssetId;
|
||||
|
||||
AZStd::string m_name;
|
||||
ScriptCanvasAssetHolder m_scriptCanvasAssetHolder;
|
||||
|
||||
ScriptCanvas::EditableVariableData m_editableData;
|
||||
bool m_runtimeDataIsValid = false;
|
||||
ScriptCanvasBuilder::BuildVariableOverrides m_variableOverrides;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
@@ -289,7 +289,7 @@ namespace ScriptCanvasEditor
|
||||
|
||||
void LoggingDataAggregator::OnRegistrationDisabled(const AZ::NamedEntityId&, const ScriptCanvas::GraphIdentifier&)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
void LoggingDataAggregator::ResetLog()
|
||||
@@ -324,7 +324,7 @@ namespace ScriptCanvasEditor
|
||||
m_hasAnchor = false;
|
||||
m_anchorTimeStamp = ScriptCanvas::Timestamp(0);
|
||||
}
|
||||
|
||||
|
||||
void LoggingDataAggregator::RegisterScriptCanvas(const AZ::NamedEntityId& entityId, const ScriptCanvas::GraphIdentifier& graphIdentifier)
|
||||
{
|
||||
bool foundMatch = false;
|
||||
@@ -335,7 +335,7 @@ namespace ScriptCanvasEditor
|
||||
if (mapIter->second == graphIdentifier)
|
||||
{
|
||||
foundMatch = true;
|
||||
AZ_Error("ScriptCanvas", false, "Received a duplicated registration callback.");
|
||||
AZ_Warning("ScriptCanvas", false, "Received a duplicated registration callback.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -523,7 +523,7 @@ namespace ScriptCanvasEditor
|
||||
// Creation Actions
|
||||
{
|
||||
m_createScriptCanvas = new QToolButton();
|
||||
m_createScriptCanvas->setIcon(QIcon(ScriptCanvas::AssetDescription::GetIconPath<ScriptCanvasAsset>()));
|
||||
m_createScriptCanvas->setIcon(QIcon(":/ScriptCanvasEditorResources/Resources/create_graph.png"));
|
||||
m_createScriptCanvas->setToolTip("Creates a new Script Canvas Graph");
|
||||
|
||||
QObject::connect(m_createScriptCanvas, &QToolButton::clicked, this, &MainWindow::OnFileNew);
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:f920ea2cd388c6db572344e33ccbf96f65ee6d391ae1880cfe16eff58d0da381
|
||||
size 4016
|
||||
@@ -12,6 +12,7 @@
|
||||
<file>Resources/capture_offline.png</file>
|
||||
<file>Resources/create_function_input.png</file>
|
||||
<file>Resources/create_function_output.png</file>
|
||||
<file>Resources/create_graph.png</file>
|
||||
<file>Resources/CollapseAll_Icon.png</file>
|
||||
<file>Resources/edit_icon.png</file>
|
||||
<file>Resources/error_icon.png</file>
|
||||
|
||||
Reference in New Issue
Block a user