Cleanup SerializeContext.h pt.1 (#4264)
* Remove AssetSerializer inclusion from SerializeContext header Moved a few Reflect methods to new cpp files. In addition, some preparations for further header dependency reductions. Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * Fix smoke test lua failures. Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * Windows build fixes. Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * Missing license headers Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * Fix white-space issues. Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * Code review fix for AzToolsFramework/AssetEditor/AssetEditorBus.h Co-authored-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * Fix inheritance list wrapping broken by older clang-format Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> Co-authored-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
This commit is contained in:
+3
-2
@@ -9,6 +9,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/Math/Crc.h>
|
||||
#include <AzCore/RTTI/BehaviorContext.h>
|
||||
#include <AzCore/std/string/string.h>
|
||||
#include <AzCore/std/string/string_view.h>
|
||||
|
||||
@@ -38,8 +39,8 @@ namespace ScriptEvents
|
||||
|
||||
void ReserveArguments(size_t numArguments);
|
||||
|
||||
size_t GetNumArguments() const override { return m_behaviorParameters.size(); }
|
||||
const AZ::BehaviorParameter* GetArgument(size_t index) const override
|
||||
size_t GetNumArguments() const override { return m_behaviorParameters.size(); }
|
||||
const AZ::BehaviorParameter* GetArgument(size_t index) const override
|
||||
{
|
||||
if (index >= m_behaviorParameters.size())
|
||||
{
|
||||
|
||||
+4
-3
@@ -9,6 +9,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/Math/Crc.h>
|
||||
#include <AzCore/RTTI/BehaviorContext.h>
|
||||
#include <AzCore/std/string/string.h>
|
||||
#include <AzCore/std/string/string_view.h>
|
||||
|
||||
@@ -38,8 +39,8 @@ namespace ScriptEvents
|
||||
|
||||
void ReserveArguments(size_t numArguments);
|
||||
|
||||
size_t GetNumArguments() const override { return m_behaviorParameters.size(); }
|
||||
const AZ::BehaviorParameter* GetArgument(size_t index) const override
|
||||
size_t GetNumArguments() const override { return m_behaviorParameters.size(); }
|
||||
const AZ::BehaviorParameter* GetArgument(size_t index) const override
|
||||
{
|
||||
if (index >= m_behaviorParameters.size())
|
||||
{
|
||||
@@ -47,7 +48,7 @@ namespace ScriptEvents
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return &m_behaviorParameters[index];
|
||||
return &m_behaviorParameters[index];
|
||||
}
|
||||
|
||||
const AZStd::string* GetArgumentName(size_t index) const override { return &m_argumentNames[index]; }
|
||||
|
||||
@@ -9,10 +9,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <ScriptEvents/ScriptEventParameter.h>
|
||||
#include <AzCore/RTTI/ReflectContext.h>
|
||||
#include <AzCore/RTTI/BehaviorContext.h>
|
||||
#include <ScriptEvents/ScriptEventTypes.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
class ReflectContext;
|
||||
}
|
||||
namespace ScriptEvents
|
||||
{
|
||||
//! Holds the versioned definition for each of a script events.
|
||||
@@ -21,7 +23,6 @@ namespace ScriptEvents
|
||||
class Method
|
||||
{
|
||||
public:
|
||||
|
||||
AZ_TYPE_INFO(Method, "{E034EA83-C798-413D-ACE8-4923C51CF4F7}");
|
||||
|
||||
Method()
|
||||
@@ -67,29 +68,7 @@ namespace ScriptEvents
|
||||
FromScript(dc);
|
||||
}
|
||||
|
||||
void FromScript(AZ::ScriptDataContext& dc)
|
||||
{
|
||||
if (dc.GetNumArguments() > 0)
|
||||
{
|
||||
AZStd::string name;
|
||||
if (dc.IsString(0) && dc.ReadArg(0, name))
|
||||
{
|
||||
m_name.Set(name.c_str());
|
||||
}
|
||||
|
||||
if (dc.GetNumArguments() > 1)
|
||||
{
|
||||
AZ::Uuid returnType;
|
||||
if (dc.ReadArg(1, returnType))
|
||||
{
|
||||
m_returnType.Set(returnType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//AZ_TracePrintf("Script Events", "Added Script Method: %s (return type: %s)\n", GetName().c_str(), m_returnType.IsEmpty() ? "none" : GetReturnType().ToString<AZStd::string>().c_str());
|
||||
|
||||
}
|
||||
void FromScript(AZ::ScriptDataContext& dc);
|
||||
|
||||
~Method()
|
||||
{
|
||||
@@ -111,150 +90,71 @@ namespace ScriptEvents
|
||||
return m_parameters.back();
|
||||
}
|
||||
|
||||
static void Reflect(AZ::ReflectContext* context)
|
||||
static void Reflect(AZ::ReflectContext* context);
|
||||
|
||||
AZStd::string GetName() const
|
||||
{
|
||||
if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
|
||||
{
|
||||
serializeContext->Class<Method>()
|
||||
->Field("m_name", &Method::m_name)
|
||||
->Field("m_tooltip", &Method::m_tooltip)
|
||||
->Field("m_returnType", &Method::m_returnType)
|
||||
->Field("m_parameters", &Method::m_parameters)
|
||||
;
|
||||
|
||||
if (AZ::EditContext* editContext = serializeContext->GetEditContext())
|
||||
{
|
||||
editContext->Class<Method>("Script Event", "A script event's definition")
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &Method::m_name, "Name", "The specified name for this event, represents a callable function (i.e. MyScriptEvent())")
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &Method::m_tooltip, "Tooltip", "A description of this event")
|
||||
->DataElement(AZ::Edit::UIHandlers::ComboBox, &Method::m_returnType, "Return value type", "the typeid of the return value, ex. AZ::type_info<int>::Uuid foo()")
|
||||
->Attribute(AZ::Edit::Attributes::GenericValueList, &Types::GetValidReturnTypes)
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &Method::m_parameters, "Parameters", "A list of parameters for the EBus event, ex. void foo(Parameter1, Parameter2)")
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
|
||||
{
|
||||
behaviorContext->Class<Method>("Method")
|
||||
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::All)
|
||||
->Method("AddParameter", &Method::AddParameter)
|
||||
->Property("Name", BehaviorValueProperty(&Method::m_name))
|
||||
->Property("ReturnType", BehaviorValueProperty(&Method::m_returnType))
|
||||
->Property("Parameters", BehaviorValueProperty(&Method::m_parameters))
|
||||
;
|
||||
}
|
||||
return m_name.Get<AZStd::string>() ? *m_name.Get<AZStd::string>() : "";
|
||||
}
|
||||
AZStd::string GetTooltip() const
|
||||
{
|
||||
return m_tooltip.Get<AZStd::string>() ? *m_tooltip.Get<AZStd::string>() : "";
|
||||
}
|
||||
|
||||
AZStd::string GetName() const { return m_name.Get<AZStd::string>() ? *m_name.Get<AZStd::string>() : ""; }
|
||||
AZStd::string GetTooltip() const { return m_tooltip.Get<AZStd::string>() ? *m_tooltip.Get<AZStd::string>() : ""; }
|
||||
const AZ::Uuid GetReturnType() const { return m_returnType.Get<AZ::Uuid>() ? *m_returnType.Get<AZ::Uuid>() : AZ::Uuid::CreateNull(); }
|
||||
const AZStd::vector<Parameter>& GetParameters() const { return m_parameters; }
|
||||
const AZ::Uuid GetReturnType() const
|
||||
{
|
||||
return m_returnType.Get<AZ::Uuid>() ? *m_returnType.Get<AZ::Uuid>() : AZ::Uuid::CreateNull();
|
||||
}
|
||||
|
||||
ScriptEventData::VersionedProperty& GetNameProperty() { return m_name; }
|
||||
ScriptEventData::VersionedProperty& GetTooltipProperty() { return m_tooltip; }
|
||||
ScriptEventData::VersionedProperty& GetReturnTypeProperty() { return m_returnType; }
|
||||
const AZStd::vector<Parameter>& GetParameters() const
|
||||
{
|
||||
return m_parameters;
|
||||
}
|
||||
|
||||
const ScriptEventData::VersionedProperty& GetNameProperty() const { return m_name; }
|
||||
const ScriptEventData::VersionedProperty& GetTooltipProperty() const { return m_tooltip; }
|
||||
const ScriptEventData::VersionedProperty& GetReturnTypeProperty() const { return m_returnType; }
|
||||
ScriptEventData::VersionedProperty& GetNameProperty()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
AZ::Crc32 GetEventId() const { return AZ::Crc32(GetNameProperty().GetId().ToString<AZStd::string>().c_str()); }
|
||||
ScriptEventData::VersionedProperty& GetTooltipProperty()
|
||||
{
|
||||
return m_tooltip;
|
||||
}
|
||||
|
||||
ScriptEventData::VersionedProperty& GetReturnTypeProperty()
|
||||
{
|
||||
return m_returnType;
|
||||
}
|
||||
|
||||
const ScriptEventData::VersionedProperty& GetNameProperty() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
const ScriptEventData::VersionedProperty& GetTooltipProperty() const
|
||||
{
|
||||
return m_tooltip;
|
||||
}
|
||||
|
||||
const ScriptEventData::VersionedProperty& GetReturnTypeProperty() const
|
||||
{
|
||||
return m_returnType;
|
||||
}
|
||||
|
||||
AZ::Crc32 GetEventId() const
|
||||
{
|
||||
return AZ::Crc32(GetNameProperty().GetId().ToString<AZStd::string>().c_str());
|
||||
}
|
||||
//! Validates that the asset data being stored is valid and supported.
|
||||
AZ::Outcome<bool, AZStd::string> Validate() const
|
||||
{
|
||||
const AZStd::string name = GetName();
|
||||
const AZ::Uuid returnType = GetReturnType();
|
||||
|
||||
// Validate address type
|
||||
if (!Types::IsValidReturnType(returnType))
|
||||
{
|
||||
return AZ::Failure(AZStd::string::format("The specified type %s is not valid as return type for Script Event: %s", returnType.ToString<AZStd::string>().c_str(), name.c_str()));
|
||||
}
|
||||
|
||||
// Definition name cannot be empty
|
||||
if (name.empty())
|
||||
{
|
||||
return AZ::Failure(AZStd::string("Definition name cannot be empty"));
|
||||
}
|
||||
|
||||
// Name cannot start with a number
|
||||
if (isdigit(name.at(0)))
|
||||
{
|
||||
return AZ::Failure(AZStd::string::format("%s, names cannot start with a number", name.c_str()));
|
||||
}
|
||||
|
||||
// Conform to valid function names
|
||||
AZStd::smatch match;
|
||||
|
||||
// Ascii-only
|
||||
AZStd::regex asciionly_regex("[^\x0A\x0D\x20-\x7E]");
|
||||
AZStd::regex_match(name, match, asciionly_regex);
|
||||
if (!match.empty())
|
||||
{
|
||||
return AZ::Failure(AZStd::string::format("%s, invalid name, names may only contain ASCII characters", name.c_str()));
|
||||
}
|
||||
|
||||
AZStd::regex validate_regex("[_[:alpha:]][_[:alnum:]]*");
|
||||
AZStd::regex_match(name, match, validate_regex);
|
||||
if (match.empty())
|
||||
{
|
||||
return AZ::Failure(AZStd::string::format("%s, invalid name specified", name.c_str()));
|
||||
}
|
||||
|
||||
AZStd::string parameterName;
|
||||
int parameterIndex = 0;
|
||||
for (const Parameter& parameter : m_parameters)
|
||||
{
|
||||
auto outcome = parameter.Validate();
|
||||
if (!outcome.IsSuccess())
|
||||
{
|
||||
return outcome;
|
||||
}
|
||||
|
||||
if (parameter.GetName().compare(parameterName) == 0)
|
||||
{
|
||||
return AZ::Failure(AZStd::string::format("Cannot have duplicate parameter names (%d: %s) make sure each parameter name is unique", parameterIndex, parameterName.c_str()));
|
||||
}
|
||||
|
||||
parameterName = parameter.GetName();
|
||||
++parameterIndex;
|
||||
}
|
||||
|
||||
return AZ::Success(true);
|
||||
}
|
||||
|
||||
void PreSave()
|
||||
{
|
||||
m_name.PreSave();
|
||||
m_tooltip.PreSave();
|
||||
m_returnType.PreSave();
|
||||
|
||||
for (Parameter parameter : m_parameters)
|
||||
{
|
||||
parameter.PreSave();
|
||||
}
|
||||
}
|
||||
|
||||
void Flatten()
|
||||
{
|
||||
m_name.Flatten();
|
||||
m_tooltip.Flatten();
|
||||
m_returnType.Flatten();
|
||||
for (Parameter& parameter : m_parameters)
|
||||
{
|
||||
parameter.Flatten();
|
||||
}
|
||||
}
|
||||
AZ::Outcome<bool, AZStd::string> Validate() const;
|
||||
void PreSave();
|
||||
void Flatten();
|
||||
|
||||
private:
|
||||
|
||||
ScriptEventData::VersionedProperty m_name;
|
||||
ScriptEventData::VersionedProperty m_tooltip;
|
||||
ScriptEventData::VersionedProperty m_returnType;
|
||||
AZStd::vector<Parameter> m_parameters;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace ScriptEvents
|
||||
|
||||
@@ -9,10 +9,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <ScriptEvents/Internal/VersionedProperty.h>
|
||||
#include <AzCore/Serialization/SerializeContext.h>
|
||||
#include <ScriptEvents/ScriptEventTypes.h>
|
||||
#include <AzCore/Serialization/EditContext.h>
|
||||
#include <AzCore/std/string/regex.h>
|
||||
|
||||
namespace ScriptEvents
|
||||
{
|
||||
@@ -45,109 +42,11 @@ namespace ScriptEvents
|
||||
FromScript(dc);
|
||||
}
|
||||
|
||||
void FromScript(AZ::ScriptDataContext& dc)
|
||||
{
|
||||
if (dc.GetNumArguments() > 0)
|
||||
{
|
||||
AZStd::string name;
|
||||
if (dc.ReadArg(0, name))
|
||||
{
|
||||
m_name.Set(name.c_str());
|
||||
}
|
||||
void FromScript(AZ::ScriptDataContext& dc);
|
||||
|
||||
if (dc.GetNumArguments() > 1)
|
||||
{
|
||||
AZ::Uuid parameterType;
|
||||
if (dc.ReadArg(1, parameterType))
|
||||
{
|
||||
m_type.Set(parameterType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//AZ_TracePrintf("Script Events", "Added Parameter: %s (type: %s)\n", GetName().c_str(), GetType().ToString<AZStd::string>() .c_str());
|
||||
|
||||
}
|
||||
|
||||
static void Reflect(AZ::ReflectContext* context)
|
||||
{
|
||||
if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
|
||||
{
|
||||
serializeContext->Class<Parameter>()
|
||||
->Field("m_name", &Parameter::m_name)
|
||||
->Field("m_tooltip", &Parameter::m_tooltip)
|
||||
->Field("m_type", &Parameter::m_type)
|
||||
;
|
||||
|
||||
if (AZ::EditContext* editContext = serializeContext->GetEditContext())
|
||||
{
|
||||
editContext->Class<Parameter>("A Script Event's method parameter", "A parameter to a Script Event's event definition")
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &Parameter::m_name, "Name", "Name of the parameter, ex. void foo(int thisIsTheParameterName)")
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &Parameter::m_tooltip, "Tooltip", "A description of this parameter")
|
||||
->DataElement(AZ::Edit::UIHandlers::ComboBox, &Parameter::m_type, "Type", "The typeid of the parameter, ex. void foo(AZ::type_info<int>::Uuid())")
|
||||
->Attribute(AZ::Edit::Attributes::GenericValueList, &Types::GetValidParameterTypes)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
|
||||
{
|
||||
behaviorContext->Class<Parameter>("Parameter")
|
||||
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::All)
|
||||
->Property("Name", BehaviorValueProperty(&Parameter::m_name))
|
||||
->Property("Type", BehaviorValueProperty(&Parameter::m_type))
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
AZ::Outcome<bool, AZStd::string> Validate() const
|
||||
{
|
||||
const AZStd::string& name = GetName();
|
||||
const AZ::Uuid* parameterType = m_type.Get<const AZ::Uuid>();
|
||||
|
||||
AZ_Assert(parameterType && !parameterType->IsNull(), "The Parameter type should not be null");
|
||||
|
||||
// Validate address type
|
||||
if (!Types::IsValidParameterType(*parameterType))
|
||||
{
|
||||
return AZ::Failure(AZStd::string::format("The specified type %s is not valid as parameter type for Script Event: %s", (*parameterType).ToString<AZStd::string>().c_str(), name.c_str()));
|
||||
}
|
||||
|
||||
// Definition name cannot be empty
|
||||
if (name.empty())
|
||||
{
|
||||
return AZ::Failure(AZStd::string("Definition name cannot be empty"));
|
||||
}
|
||||
|
||||
// Name cannot start with a number
|
||||
if (isdigit(name.at(0)))
|
||||
{
|
||||
return AZ::Failure(AZStd::string::format("%s, names cannot start with a number", name.c_str()));
|
||||
}
|
||||
|
||||
// Conform to valid function names
|
||||
AZStd::smatch match;
|
||||
|
||||
// Ascii-only
|
||||
AZStd::regex asciionly_regex("[^\x0A\x0D\x20-\x7E]");
|
||||
AZStd::regex_match(name, match, asciionly_regex);
|
||||
if (match.size() > 0)
|
||||
{
|
||||
return AZ::Failure(AZStd::string::format("%s, invalid name, names may only contain ASCII characters", name.c_str()));
|
||||
}
|
||||
|
||||
// Function name syntax
|
||||
AZStd::regex validate_regex("[_[:alpha:]][_[:alnum:]]*");
|
||||
AZStd::regex_match(name, match, validate_regex);
|
||||
if (match.size() == 0)
|
||||
{
|
||||
return AZ::Failure(AZStd::string::format("%s, invalid name specified", name.c_str()));
|
||||
}
|
||||
|
||||
return AZ::Success(true);
|
||||
|
||||
}
|
||||
static void Reflect(AZ::ReflectContext* context);
|
||||
|
||||
AZ::Outcome<bool, AZStd::string> Validate() const;
|
||||
AZStd::string GetName() const { return m_name.Get<AZStd::string>() ? *m_name.Get<AZStd::string>() : ""; }
|
||||
AZStd::string GetTooltip() const { return m_tooltip.Get<AZStd::string>() ? *m_tooltip.Get<AZStd::string>() : ""; }
|
||||
AZ::Uuid GetType() const { return m_type.Get<AZ::Uuid>() ? *m_type.Get<AZ::Uuid>() : AZ::Uuid::CreateNull(); }
|
||||
|
||||
@@ -10,6 +10,14 @@
|
||||
|
||||
#include <ScriptEvents/Internal/VersionedProperty.h>
|
||||
|
||||
#include <AzCore/Script/ScriptContextAttributes.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
class BehaviorClass;
|
||||
class BehaviorMethod;
|
||||
}
|
||||
|
||||
namespace ScriptEvents
|
||||
{
|
||||
namespace Types
|
||||
|
||||
@@ -9,12 +9,10 @@
|
||||
|
||||
#include <AzCore/Asset/AssetCommon.h>
|
||||
#include <AzCore/Asset/AssetManager.h>
|
||||
#include <AzCore/RTTI/BehaviorContext.h>
|
||||
#include <AzCore/RTTI/ReflectContext.h>
|
||||
#include <AzCore/Script/ScriptContext.h>
|
||||
#include <AzCore/Serialization/EditContext.h>
|
||||
#include <AzCore/Serialization/ObjectStream.h>
|
||||
#include <AzCore/Serialization/SerializeContext.h>
|
||||
|
||||
#include <AzFramework/Asset/SimpleAsset.h>
|
||||
|
||||
@@ -38,40 +36,7 @@ namespace ScriptEvents
|
||||
|
||||
using AssetChangedCB = AZStd::function<void(const AZ::Data::Asset<ScriptEventsAsset>&, void* userData)>;
|
||||
|
||||
static void Reflect(AZ::ReflectContext* context)
|
||||
{
|
||||
if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
|
||||
{
|
||||
serializeContext->Class<ScriptEventsAssetRef>()
|
||||
->Version(0)
|
||||
->Field("Asset", &ScriptEventsAssetRef::m_asset)
|
||||
;
|
||||
|
||||
if (AZ::EditContext* editContext = serializeContext->GetEditContext())
|
||||
{
|
||||
editContext->Class<ScriptEventsAssetRef>("Script Event Asset", "")
|
||||
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &ScriptEventsAssetRef::m_asset, "Script Event Asset", "")
|
||||
->Attribute(AZ::Edit::Attributes::ChangeNotify, &ScriptEventsAssetRef::OnAssetChanged)
|
||||
//TODO #lsempe: hook up to open Asset Editor when ready
|
||||
//->Attribute("EditButton", "")
|
||||
//->Attribute("EditDescription", "Open in Script Canvas Editor")
|
||||
//->Attribute("EditCallback", &ScriptEventsAssetRef::LaunchScriptCanvasEditor)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
|
||||
{
|
||||
behaviorContext->Class<ScriptEventsAssetRef>()
|
||||
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::All)
|
||||
->Attribute(AZ::Script::Attributes::Storage, AZ::Script::Attributes::StorageType::Value)
|
||||
->Attribute(AZ::Script::Attributes::ConstructibleFromNil, false)
|
||||
->Method("Get", &ScriptEventsAssetRef::GetDefinition)
|
||||
;
|
||||
}
|
||||
}
|
||||
static void Reflect(AZ::ReflectContext* context);
|
||||
|
||||
ScriptEventsAssetRef() = default;
|
||||
|
||||
@@ -100,98 +65,22 @@ namespace ScriptEvents
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void SetAsset(const AZ::Data::Asset<ScriptEventsAsset>& asset)
|
||||
{
|
||||
m_asset = asset;
|
||||
|
||||
if (m_asset.IsReady())
|
||||
{
|
||||
if (ScriptEventsAsset* scriptEventAsset = m_asset.GetAs<ScriptEventsAsset>())
|
||||
{
|
||||
scriptEventAsset->m_definition.RegisterInternal();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (AZ::Data::AssetBus::Handler::BusIsConnectedId(m_asset.GetId()))
|
||||
{
|
||||
AZ::Data::AssetBus::Handler::BusDisconnect(m_asset.GetId());
|
||||
}
|
||||
|
||||
AZ::Data::AssetBus::Handler::BusConnect(m_asset.GetId());
|
||||
}
|
||||
}
|
||||
void SetAsset(const AZ::Data::Asset<ScriptEventsAsset>& asset);
|
||||
|
||||
AZ::Data::Asset<ScriptEvents::ScriptEventsAsset> GetAsset() const
|
||||
{
|
||||
return m_asset;
|
||||
}
|
||||
|
||||
void Load(bool loadBlocking /*= false*/)
|
||||
{
|
||||
if (!m_asset.IsReady())
|
||||
{
|
||||
AZ::Data::AssetInfo assetInfo;
|
||||
AZ::Data::AssetCatalogRequestBus::BroadcastResult(assetInfo, &AZ::Data::AssetCatalogRequests::GetAssetInfoById, m_asset.GetId());
|
||||
if (assetInfo.m_assetId.IsValid())
|
||||
{
|
||||
auto& assetManager = AZ::Data::AssetManager::Instance();
|
||||
m_asset = assetManager.GetAsset(m_asset.GetId(), azrtti_typeid<ScriptEventsAsset>(), m_asset.GetAutoLoadBehavior());
|
||||
|
||||
if(loadBlocking)
|
||||
{
|
||||
m_asset.BlockUntilLoadComplete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AZ::u32 OnAssetChanged()
|
||||
{
|
||||
SetAsset(m_asset);
|
||||
Load(false);
|
||||
|
||||
if (m_assetNotifyCallback)
|
||||
{
|
||||
m_assetNotifyCallback(m_asset, m_userData);
|
||||
}
|
||||
|
||||
return AZ::Edit::PropertyRefreshLevels::None;
|
||||
}
|
||||
void Load(bool loadBlocking /*= false*/);
|
||||
AZ::u32 OnAssetChanged();
|
||||
|
||||
//=====================================================================
|
||||
// AZ::Data::AssetBus
|
||||
|
||||
void OnAssetReady(AZ::Data::Asset<AZ::Data::AssetData> asset) override
|
||||
{
|
||||
if (ScriptEventsAsset* scriptEventAsset = m_asset.GetAs<ScriptEventsAsset>())
|
||||
{
|
||||
scriptEventAsset->m_definition.RegisterInternal();
|
||||
}
|
||||
}
|
||||
|
||||
void OnAssetReloaded(AZ::Data::Asset<AZ::Data::AssetData> asset) override
|
||||
{
|
||||
SetAsset(asset);
|
||||
|
||||
if (m_assetNotifyCallback)
|
||||
{
|
||||
m_assetNotifyCallback(m_asset, m_userData);
|
||||
}
|
||||
}
|
||||
|
||||
void OnAssetUnloaded([[maybe_unused]] const AZ::Data::AssetId assetId, [[maybe_unused]] const AZ::Data::AssetType assetType) override
|
||||
{
|
||||
if (ScriptEventsAsset* ebusAsset = m_asset.GetAs<ScriptEventsAsset>())
|
||||
{
|
||||
bool isRegistered = false;
|
||||
//ScriptEventsLegacy::RegistrationRequestBus::BroadcastResult(isRegistered, &ScriptEventsLegacy::RegistrationRequestBus::Events::IsBusRegistered, ebusAsset->m_scriptEventsDefinition.m_name);
|
||||
if (isRegistered)
|
||||
{
|
||||
//ScriptEventsLegacy::RegistrationRequestBus::Broadcast(&ScriptEventsLegacy::RegistrationRequestBus::Events::Unregister, ebusAsset->m_scriptEventsDefinition.m_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
void OnAssetReady(AZ::Data::Asset<AZ::Data::AssetData> asset) override;
|
||||
void OnAssetReloaded(AZ::Data::Asset<AZ::Data::AssetData> asset) override;
|
||||
void OnAssetUnloaded(const AZ::Data::AssetId assetId, const AZ::Data::AssetType assetType) override;
|
||||
|
||||
void OnAssetSaved(AZ::Data::Asset<AZ::Data::AssetData> asset, [[maybe_unused]] bool isSuccessful) override
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user