Fixed issue where duplicate script assemblies are loaded again

This commit is contained in:
Kah Wei 2023-02-23 13:32:23 +08:00
parent d7846082a3
commit 7292f11cdb
4 changed files with 28 additions and 2 deletions

View File

@ -28,6 +28,18 @@ namespace SHADE
: Component(entity)
{}
void UIElement::ClearStaticEventData()
{
if (onClickEventMap != nullptr)
onClickEventMap->Clear();
if (onReleasedEventMap != nullptr)
onReleasedEventMap->Clear();
if (onHoverEnterEventMap != nullptr)
onHoverEnterEventMap->Clear();
if (onHoverExitEventMap != nullptr)
onHoverExitEventMap->Clear();
}
/*---------------------------------------------------------------------------------*/
/* Properties */
/*---------------------------------------------------------------------------------*/

View File

@ -73,6 +73,15 @@ namespace SHADE
CallbackEvent^ get();
}
internal:
/*-----------------------------------------------------------------------------*/
/* Static Clear Functions */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Disposes static event data which may contains data from SHADE_Scripting.
/// </summary>
static void ClearStaticEventData();
private:
/*-----------------------------------------------------------------------------*/
/* Event Handling Functions */
@ -108,6 +117,7 @@ namespace SHADE
/*-----------------------------------------------------------------------------*/
/* Static Data Members */
/*-----------------------------------------------------------------------------*/
// As these hold references to code in SHADE_Scripting, we must remember to dispose of them when changing scenes
static System::Collections::Generic::Dictionary<Entity, CallbackEvent^>^ onClickEventMap;
static System::Collections::Generic::Dictionary<Entity, CallbackEvent^>^ onReleasedEventMap;
static System::Collections::Generic::Dictionary<Entity, CallbackEvent^>^ onHoverEnterEventMap;

View File

@ -21,6 +21,7 @@ of DigiPen Institute of Technology is prohibited.
#include "Utility/Convert.hxx"
#include "Utility/Debug.hxx"
#include "Scripts/ScriptStore.hxx"
#include "Components/UIElement.hxx"
namespace SHADE
{
@ -43,6 +44,9 @@ namespace SHADE
oss << "[EngineInterface] Unloading " << Convert::ToNative(ManagedLibraryName) << ".dll";
ScriptStore::Exit();
// Unload static data of components that have access to the assembly
UIElement::ClearStaticEventData();
// Unload the script
scriptContext->Unload();
scriptContext = nullptr;