BsScriptGameObject.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsScriptEnginePrerequisites.h"
  5. #include "BsScriptObject.h"
  6. namespace bs
  7. {
  8. /** @addtogroup ScriptInteropEngine
  9. * @{
  10. */
  11. /** Base class for all GameObject interop classes. */
  12. class BS_SCR_BE_EXPORT ScriptGameObjectBase : public PersistentScriptObjectBase
  13. {
  14. public:
  15. ScriptGameObjectBase(MonoObject* instance);
  16. virtual ~ScriptGameObjectBase();
  17. /** Returns the internal native GameObject handle. */
  18. virtual HGameObject getNativeHandle() const = 0;
  19. /** Sets the internal native GameObject handle. */
  20. virtual void setNativeHandle(const HGameObject& gameObject) = 0;
  21. /** Returns the managed version of this game object. */
  22. MonoObject* getManagedInstance() const;
  23. protected:
  24. /**
  25. * Makes the object reference the specific managed instance. Internally this allocates a GC handle that keeps a
  26. * reference to the object and allows getManagedInstance to retrieve the managed instance when requested. Should
  27. * be called on initial creation and whenever the managed instance changes (e.g. after assembly refresh). This
  28. * creates a strong reference to the managed instance, and you need to make sure to release it with
  29. * freeManagedInstance() when no longer required.
  30. */
  31. void setManagedInstance(MonoObject* instance);
  32. /**
  33. * Frees a managed instace assigned with setManagedInstance(). Should be called before the object is destroyed or
  34. * when you changing the managed instance it points to (in order to release the previous instance).
  35. */
  36. void freeManagedInstance();
  37. UINT32 mGCHandle;
  38. };
  39. /** Interop class between C++ & CLR for GameObject. */
  40. class BS_SCR_BE_EXPORT ScriptGameObject : public ScriptObject<ScriptGameObject, ScriptGameObjectBase>
  41. {
  42. public:
  43. SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "GameObject")
  44. private:
  45. ScriptGameObject(MonoObject* instance);
  46. /************************************************************************/
  47. /* CLR HOOKS */
  48. /************************************************************************/
  49. static UINT64 internal_getInstanceId(ScriptGameObject* nativeInstance);
  50. };
  51. /** @} */
  52. }