Added C# Assets System and Serialization of Script Enabled State #247
|
@ -259,6 +259,14 @@ namespace SHADE
|
|||
: OnGizmosDrawOverriden { false }
|
||||
{}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Manipulation Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
void Script::SetEnabledWithoutEvents(bool enable)
|
||||
{
|
||||
enabled = enable;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Virtual "All-Time" Lifecycle Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
|
|
@ -326,6 +326,15 @@ namespace SHADE
|
|||
/// <param name="collision">Information on the collision event.</param>
|
||||
void OnTriggerExit(CollisionInfo collision);
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Manipulation Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Function to set the enabled state of this script without triggering events.
|
||||
/// </summary>
|
||||
/// <param name="enable">Whether to enable or disable the script.</param>
|
||||
void SetEnabledWithoutEvents(bool enable);
|
||||
|
||||
protected:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Constructors */
|
||||
|
|
|
@ -744,7 +744,7 @@ namespace SHADE
|
|||
for (YAML::Node& node : *yamlNode)
|
||||
{
|
||||
// Get the name of the script
|
||||
if (!node["Type"])
|
||||
if (!node["Type"].IsDefined())
|
||||
{
|
||||
Debug::LogWarning("[ScriptStore] Script with no type detected, skipping.");
|
||||
continue;
|
||||
|
|
|
@ -21,11 +21,13 @@ of DigiPen Institute of Technology is prohibited.
|
|||
#include "Assets/FontAsset.hxx"
|
||||
#include "Assets/MaterialAsset.hxx"
|
||||
#include "Assets/MeshAsset.hxx"
|
||||
#include "Scripts/Script.hxx"
|
||||
|
||||
/*-------------------------------------------------------------------------------------*/
|
||||
/* File-Level Constants */
|
||||
/*-------------------------------------------------------------------------------------*/
|
||||
static const std::string_view SCRIPT_TYPE_YAMLTAG = "Type";
|
||||
static const std::string_view SCRIPT_ENABLED_YAMLTAG = "Enabled";
|
||||
|
||||
/*-------------------------------------------------------------------------------------*/
|
||||
/* Function Definitions */
|
||||
|
@ -39,10 +41,19 @@ namespace SHADE
|
|||
{
|
||||
using namespace System::Reflection;
|
||||
|
||||
// Obtain script
|
||||
Script^ script = safe_cast<Script^>(object);
|
||||
if (script == nullptr)
|
||||
{
|
||||
Debug::LogWarning("[SerialisationUtilities] Attempted to serialise an object that is not a script!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Create YAML object
|
||||
YAML::Node scriptNode;
|
||||
scriptNode.SetStyle(YAML::EmitterStyle::Block);
|
||||
scriptNode[SCRIPT_TYPE_YAMLTAG.data()] = Convert::ToNative(object->GetType()->FullName);
|
||||
scriptNode[SCRIPT_ENABLED_YAMLTAG.data()] = script->Enabled;
|
||||
|
||||
// Get all fields
|
||||
System::Collections::Generic::IEnumerable<FieldInfo^>^ fields = ReflectionUtilities::GetInstanceFields(object);
|
||||
|
@ -72,7 +83,7 @@ namespace SHADE
|
|||
{
|
||||
using namespace System::Reflection;
|
||||
|
||||
// Load the YAML
|
||||
// Error Checking
|
||||
if (!yamlNode.IsMap())
|
||||
{
|
||||
// Invalid
|
||||
|
@ -83,6 +94,21 @@ namespace SHADE
|
|||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the script
|
||||
Script^ script = safe_cast<Script^>(object);
|
||||
if (script == nullptr)
|
||||
{
|
||||
Debug::LogWarning("[SerialisationUtilities] Attempted to deserialise an object that is not a script!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Set enabled state
|
||||
if (yamlNode[SCRIPT_ENABLED_YAMLTAG.data()].IsDefined())
|
||||
{
|
||||
script->SetEnabledWithoutEvents(yamlNode[SCRIPT_ENABLED_YAMLTAG.data()].as<bool>());
|
||||
}
|
||||
|
||||
// Get all fields
|
||||
System::Collections::Generic::IEnumerable<FieldInfo^>^ fields = ReflectionUtilities::GetInstanceFields(object);
|
||||
for each (FieldInfo^ field in fields)
|
||||
|
@ -95,7 +121,7 @@ namespace SHADE
|
|||
|
||||
// Deserialise
|
||||
const std::string FIELD_NAME = Convert::ToNative(field->Name);
|
||||
if (yamlNode[FIELD_NAME])
|
||||
if (yamlNode[FIELD_NAME].IsDefined())
|
||||
{
|
||||
writeYamlIntoField(field, object, yamlNode[FIELD_NAME]);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue