Fixed bugs related to C# script serialization and deserialization #277

Merged
Pycorax merged 4 commits from SP3-6-c-scripting into main 2022-11-25 00:08:58 +08:00
2 changed files with 15 additions and 1 deletions
Showing only changes of commit 50232cd15f - Show all commits

View File

@ -74,7 +74,7 @@ namespace SHADE
// Add the script in
script->Initialize(GameObject(entity));
entityScriptList->Insert(System::Math::Clamp(index, 0, entityScriptList->Count), script);
if (Application::IsPlaying && !SHSceneManager::HasSceneChanged())
if (Application::IsPlaying && !isDeserialising)
{
// Only call immediately if we are in game and is not loading another scene
script->Awake();
@ -423,6 +423,8 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/
void ScriptStore::Init()
{
isDeserialising = false;
// Create an enumerable list of script types
refreshScriptTypeList();
// Get stored methods for interop variants of functions
@ -724,6 +726,10 @@ namespace SHADE
bool ScriptStore::DeserialiseScripts(Entity entity, System::IntPtr yamlNodePtr)
{
SAFE_NATIVE_CALL_BEGIN
// Flag that deserialization processs is ongoing
isDeserialising = true;
// Convert to pointer
YAML::Node* yamlNode = reinterpret_cast<YAML::Node*>(yamlNodePtr.ToPointer());
@ -765,9 +771,16 @@ namespace SHADE
Debug::LogWarning("[ScriptStore] Script with unloaded type detected, skipping.");
}
}
// Unset flag for deserialization process
isDeserialising = false;
return true;
SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore")
// Unset flag for deserialization process
isDeserialising = false;
return false;
}

View File

@ -337,6 +337,7 @@ namespace SHADE
static ScriptSet disposalQueue;
static System::Collections::Generic::IEnumerable<System::Type^>^ scriptTypeList;
static System::Reflection::MethodInfo^ addScriptMethod;
static bool isDeserialising;
/*-----------------------------------------------------------------------------*/
/* Helper Functions */