From 15740faf9fe9fe4be08965098bbf2947e096aeeb Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 14 Aug 2019 22:50:43 +0800 Subject: +Unity Runtime code --- Runtime/BaseClasses/RefCounted.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Runtime/BaseClasses/RefCounted.h (limited to 'Runtime/BaseClasses/RefCounted.h') diff --git a/Runtime/BaseClasses/RefCounted.h b/Runtime/BaseClasses/RefCounted.h new file mode 100644 index 0000000..cbe2934 --- /dev/null +++ b/Runtime/BaseClasses/RefCounted.h @@ -0,0 +1,36 @@ +#pragma once + +#include "Configuration/UnityConfigure.h" +#include "Runtime/Mono/MonoIncludes.h" +#include "Runtime/Scripting/ScriptingUtility.h" +#include "Runtime/Scripting/Backend/ScriptingBackendApi.h" + +class TrackedReferenceBase +{ +public: + int m_MonoObjectReference; + + TrackedReferenceBase () + { + m_MonoObjectReference = 0; + } + + ~TrackedReferenceBase () + { +#if ENABLE_SCRIPTING + if (m_MonoObjectReference) + { + ScriptingObjectPtr target = scripting_gchandle_get_target (m_MonoObjectReference); + if (target) + { + void* nativePointer = 0; + MarshallNativeStructIntoManaged(nativePointer,target); + target = SCRIPTING_NULL; + } + + scripting_gchandle_free (m_MonoObjectReference); + m_MonoObjectReference = 0; + } +#endif + } +}; -- cgit v1.1-26-g67d0