BsScriptGizmoManager.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 SBansheeEditor
  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 method. */
  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. * Iterates over all managed gizmos, calls their draw methods and registers the gizmos with the native GizmoManager.
  36. */
  37. void update();
  38. private:
  39. /** Finds all gizmo methods (marked with the DrawGizmo attribute). Clears any previously found methods. */
  40. void reloadAssemblyData();
  41. /**
  42. * Checks is the provided method a valid gizmo draw method and if it is, returns properties of that method.
  43. *
  44. * @param[in] method Method to check.
  45. * @param[in] componentType Output parameter containing the component the method is part of. Only valid if this
  46. * method returns true.
  47. * @param[in] drawGizmoFlags Output parameters containing optional flags that control gizmo properties. Only
  48. * valid if this method returns true.
  49. * @return True if the method is a valid draw gizmo method.
  50. */
  51. bool isValidDrawGizmoMethod(MonoMethod* method, MonoClass*& componentType, UINT32& drawGizmoFlags);
  52. ScriptAssemblyManager& mScriptObjectManager;
  53. HEvent mDomainLoadedConn;
  54. MonoClass* mDrawGizmoAttribute;
  55. MonoField* mFlagsField;
  56. Map<String, GizmoData> mGizmoDrawers;
  57. };
  58. /** @} */
  59. }