BsScriptGizmoManager.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #pragma once
  2. #include "BsScriptEditorPrerequisites.h"
  3. #include "BsModule.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief Available flags to be used when defining gizmos.
  8. */
  9. // Note: Must match the C# enum DrawGizmoFlags
  10. enum class DrawGizmoFlags
  11. {
  12. Selected = 0x01, /**< Gizmo is only displayed when its scene object is selected. */
  13. ParentSelected = 0x02, /**< Gizmo is only displayed when its parent scene object is selected. */
  14. NotSelected = 0x04, /**< Gizmo is only displayed when its scene object is not selected. */
  15. Pickable = 0x08 /**< Gizmo can be clicked on (selected). */
  16. };
  17. /**
  18. * @brief Manages all active managed gizmo methods.
  19. */
  20. class BS_SCR_BED_EXPORT ScriptGizmoManager : public Module<ScriptGizmoManager>
  21. {
  22. /**
  23. * @brief Data about a managed gizmo method.
  24. */
  25. struct GizmoData
  26. {
  27. MonoClass* componentType; /**< Component the gizmo method belongs to. */
  28. MonoMethod* drawGizmosMethod; /**< Method that displays the gizmo. */
  29. UINT32 flags; /**< Gizmo flags of type DrawGizmoFlags that control gizmo properties. */
  30. };
  31. public:
  32. ScriptGizmoManager(ScriptAssemblyManager& scriptObjectManager);
  33. ~ScriptGizmoManager();
  34. /**
  35. * @brief Iterates over all managed gizmos, calls their draw methods and registers
  36. * the gizmos with the native GizmoManager.
  37. */
  38. void update();
  39. private:
  40. /**
  41. * @brief Finds all gizmo methods (marked with the DrawGizmo attribute). Clears any previously found methods.
  42. */
  43. void reloadAssemblyData();
  44. /**
  45. * @brief Checks is the provided method a valid gizmo draw method and if it is, returns
  46. * properties of that method.
  47. *
  48. * @param method Method to check.
  49. * @param componentType Output parameter containing the component the method is part of. Only valid if this method returns true.
  50. * @param drawGizmoFlags Output parameters containing optional flags that control gizmo properties. Only valid if this method returns true.
  51. *
  52. * @return True if the method is a valid draw gizmo method.
  53. */
  54. bool isValidDrawGizmoMethod(MonoMethod* method, MonoClass*& componentType, UINT32& drawGizmoFlags);
  55. ScriptAssemblyManager& mScriptObjectManager;
  56. HEvent mDomainLoadedConn;
  57. MonoClass* mDrawGizmoAttribute;
  58. MonoField* mFlagsField;
  59. Map<String, GizmoData> mGizmoDrawers;
  60. };
  61. }