BsScriptHandleManager.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #pragma once
  2. #include "BsScriptEditorPrerequisites.h"
  3. #include "BsHandleManager.h"
  4. #include <mono/jit/jit.h>
  5. namespace BansheeEngine
  6. {
  7. /**
  8. * @brief Renders, updates and manipulates handles declared in managed code.
  9. * Managed code handles have a [CustomHandle] attribute and must implement
  10. * BansheeEditor.Handle.
  11. */
  12. class BS_SCR_BED_EXPORT ScriptHandleManager : public HandleManager
  13. {
  14. /**
  15. * @brief Contains data about a manage type that draws and handles
  16. * interaction with a custom handle.
  17. */
  18. struct CustomHandleData
  19. {
  20. MonoClass* handleType;
  21. MonoClass* componentType;
  22. MonoMethod* ctor;
  23. };
  24. /**
  25. * @brief Data about an active instance of a managed custom handle object.
  26. * Active handle means its scene object is currently selected and the
  27. * handle is displayed and can be interacted with.
  28. */
  29. struct ActiveCustomHandleData
  30. {
  31. MonoObject* object;
  32. uint32_t gcHandle;
  33. };
  34. /**
  35. * @brief Data about all active managed custom handle objects
  36. * for a specific scene object. Active handle means its
  37. * scene object is currently selected and the handle is displayed
  38. * and can be interacted with.
  39. */
  40. struct ActiveCustomHandles
  41. {
  42. HSceneObject selectedObject;
  43. Vector<ActiveCustomHandleData> handles;
  44. };
  45. public:
  46. ScriptHandleManager(ScriptAssemblyManager& scriptObjectManager);
  47. ~ScriptHandleManager();
  48. protected:
  49. /**
  50. * @copydoc HandleManager::refreshHandles
  51. */
  52. void refreshHandles() override;
  53. /**
  54. * @copydoc HandleManager::triggerHandles
  55. */
  56. void triggerHandles() override;
  57. /**
  58. * @copydoc HandleManager::queueDrawCommands
  59. */
  60. void queueDrawCommands() override;
  61. /**
  62. * @brief Clears references to all managed types and objects. Must be called before loadAssemblyData if
  63. * loadAssemblyData was called previously.
  64. */
  65. void clearAssemblyData();
  66. /**
  67. * @brief Loads internal managed assembly types and finds all custom handle classes.
  68. * Must be called after construction and after assembly reload.
  69. */
  70. void loadAssemblyData();
  71. /**
  72. * @brief Checks is the provided type a valid custom handle class. Custom handles
  73. * must have a [CustomHandle] attribute and must implement BansheeEditor.Handle.
  74. *
  75. * @param type Type to check.
  76. * @param componentType Component type for which the handle should be displayed for. Handle will not
  77. * be displayed unless a component of this type is selected. Only valid if method returns true.
  78. * @param ctor Constructor method for the handle type. Only valid if method returns true.
  79. *
  80. * @return True if the type is a valid custom handle type.
  81. */
  82. bool isValidHandleType(MonoClass* type, MonoClass*& componentType, MonoMethod*& ctor);
  83. /**
  84. * @brief Triggers the PreInput method on the provided Handle object. Pre
  85. * input happens before any handles are selected or moved and allows you
  86. * to position the handles or prepare them in some other way.
  87. */
  88. void callPreInput(MonoObject* instance);
  89. /**
  90. * @brief Triggers the PostInput method on the provided Handle object.
  91. * Post input happens after we know in what way has the user interacted
  92. * with the handles this frame.
  93. */
  94. void callPostInput(MonoObject* instance);
  95. /**
  96. * @brief Triggers the Draw method on the provided Handle object. Draw allows
  97. * you to draw the visual representation of the handles. Called after PostInput.
  98. */
  99. void callDraw(MonoObject* instance);
  100. /**
  101. * @brief Triggers the Destroy method on the provided Handle object. Destroy
  102. * is called when the handle is no longer being displayed.
  103. */
  104. void callDestroy(MonoObject* instance);
  105. ScriptAssemblyManager& mScriptObjectManager;
  106. HEvent mDomainUnloadConn;
  107. HEvent mDomainLoadConn;
  108. Map<String, CustomHandleData> mHandles;
  109. ActiveCustomHandles mActiveHandleData;
  110. MonoObject* mDefaultHandleManager = nullptr;
  111. uint32_t mDefaultHandleManagerGCHandle = 0;
  112. MonoClass* mCustomHandleAttribute = nullptr;
  113. MonoField* mTypeField = nullptr;
  114. MonoClass* mHandleBaseClass = nullptr;
  115. MonoClass* mDefaultHandleManagerClass = nullptr;
  116. typedef void(__stdcall *DestroyThunkDef) (MonoObject*, MonoException**);
  117. MonoMethod* mPreInputMethod;
  118. MonoMethod* mPostInputMethod;
  119. MonoMethod* mDrawMethod;
  120. DestroyThunkDef mDestroyThunk;
  121. };
  122. }