BsScriptGameObject.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. /** @copydoc ScriptObjectBase::beginRefresh */
  24. ScriptObjectBackup beginRefresh() override;
  25. /** @copydoc ScriptObjectBase::endRefresh */
  26. void endRefresh(const ScriptObjectBackup& backupData) override;
  27. protected:
  28. /**
  29. * Makes the object reference the specific managed instance. Internally this allocates a GC handle that keeps a
  30. * reference to the object and allows getManagedInstance to retrieve the managed instance when requested. Should
  31. * be called on initial creation and whenever the managed instance changes (e.g. after assembly refresh). This
  32. * creates a strong reference to the managed instance, and you need to make sure to release it with
  33. * freeManagedInstance() when no longer required.
  34. */
  35. void setManagedInstance(MonoObject* instance);
  36. /**
  37. * Frees a managed instace assigned with setManagedInstance(). Should be called before the object is destroyed or
  38. * when you changing the managed instance it points to (in order to release the previous instance).
  39. */
  40. void freeManagedInstance();
  41. bool mRefreshInProgress;
  42. UINT32 mGCHandle;
  43. };
  44. /** Interop class between C++ & CLR for GameObject. */
  45. class BS_SCR_BE_EXPORT ScriptGameObject : public ScriptObject<ScriptGameObject, ScriptGameObjectBase>
  46. {
  47. public:
  48. SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "GameObject")
  49. private:
  50. ScriptGameObject(MonoObject* instance);
  51. /************************************************************************/
  52. /* CLR HOOKS */
  53. /************************************************************************/
  54. static UINT64 internal_getInstanceId(ScriptGameObject* nativeInstance);
  55. };
  56. /** @} */
  57. }