2
0

BsScriptGizmoManager.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsScriptEditorPrerequisites.h"
  5. #include "Utility/BsModule.h"
  6. namespace bs
  7. {
  8. /** @addtogroup EditorScript
  9. * @{
  10. */
  11. /** Available flags to be used when defining gizmos. */
  12. enum class DrawGizmoFlags // Note: Must match the C# enum DrawGizmoFlags
  13. {
  14. Selected = 0x01, /**< Gizmo is only displayed when its scene object is selected. */
  15. ParentSelected = 0x02, /**< Gizmo is only displayed when its parent scene object is selected. */
  16. NotSelected = 0x04, /**< Gizmo is only displayed when its scene object is not selected. */
  17. Pickable = 0x08 /**< Gizmo can be clicked on in scene view, which will select its scene object. */
  18. };
  19. /**
  20. * Manages all active managed gizmo methods. Finds all gizmos methods in loaded assemblies, and calls them every frame.
  21. */
  22. class BS_SCR_BED_EXPORT ScriptGizmoManager : public Module<ScriptGizmoManager>
  23. {
  24. /** Data about a managed gizmo drawing method. */
  25. struct GizmoData
  26. {
  27. MonoClass* type; /**< Component the gizmo method belongs to. */
  28. MonoMethod* method; /**< Method that displays the gizmo. */
  29. UINT32 flags; /**< Gizmo flags of type DrawGizmoFlags that control gizmo properties. */
  30. };
  31. /** Data about a managed selection changed callback method. */
  32. struct SelectionChangedData
  33. {
  34. MonoClass* type; /**< Component or resource the selection method should trigger on. */
  35. MonoMethod* method; /**< Method that receives the selection changed callback. */
  36. };
  37. public:
  38. ScriptGizmoManager(ScriptAssemblyManager& scriptObjectManager);
  39. ~ScriptGizmoManager();
  40. /**
  41. * Iterates over all managed gizmos, calls their draw methods and registers the gizmos with the native GizmoManager.
  42. */
  43. void update();
  44. private:
  45. /** Finds all gizmo methods (marked with the DrawGizmo attribute). Clears any previously found methods. */
  46. void reloadAssemblyData();
  47. /**
  48. * Triggered when entries are added or removed from the selection.
  49. *
  50. * @param[in] sceneObjects Newly selected or deselected scene objects.
  51. * @param[in] added If true, the provided objects were added to the selection. If false, the provided
  52. * objects were removed from the selection.
  53. */
  54. void onSOSelectionChanged(const Vector<HSceneObject>& sceneObjects, bool added);
  55. /**
  56. * Checks is the provided method a valid gizmo draw method and if it is, returns properties of that method.
  57. *
  58. * @param[in] method Method to check.
  59. * @param[in] componentType Output parameter containing the component the method is part of. Only valid if this
  60. * method returns true.
  61. * @param[in] drawGizmoFlags Output parameters containing optional flags that control gizmo properties. Only
  62. * valid if this method returns true.
  63. * @return True if the method is a valid draw gizmo method.
  64. */
  65. bool isValidDrawGizmoMethod(MonoMethod* method, MonoClass*& componentType, UINT32& drawGizmoFlags);
  66. /**
  67. * Checks is the provided method a valid selection changed callback method.
  68. *
  69. * @param[in] method Method to check.
  70. * @param[in] componentType Output parameter containing the component the method is part of. Only valid if this
  71. * method returns true.
  72. * @return True if the method is a valid selection changed callback method.
  73. */
  74. bool isValidOnSelectionChangedMethod(MonoMethod* method, MonoClass*& componentType);
  75. ScriptAssemblyManager& mScriptObjectManager;
  76. HEvent mDomainLoadedConn;
  77. HEvent mSelectionSOAddedConn;
  78. HEvent mSelectionSORemovedConn;
  79. MonoClass* mDrawGizmoAttribute = nullptr;
  80. MonoField* mFlagsField = nullptr;
  81. MonoClass* mOnSelectionChangedAttribute = nullptr;
  82. Map<String, GizmoData> mGizmoDrawers;
  83. Map<String, SelectionChangedData> mSelectionChangedCallbacks;
  84. };
  85. /** @} */
  86. }