BsScriptGizmoManager.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 "BsModule.h"
  6. namespace BansheeEngine
  7. {
  8. /**
  9. * @brief Available flags to be used when defining gizmos.
  10. */
  11. // Note: Must match the C# enum DrawGizmoFlags
  12. enum class 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. /**
  25. * @brief Data about a managed gizmo method.
  26. */
  27. struct GizmoData
  28. {
  29. MonoClass* componentType; /**< Component the gizmo method belongs to. */
  30. MonoMethod* drawGizmosMethod; /**< Method that displays the gizmo. */
  31. UINT32 flags; /**< Gizmo flags of type DrawGizmoFlags that control gizmo properties. */
  32. };
  33. public:
  34. ScriptGizmoManager(ScriptAssemblyManager& scriptObjectManager);
  35. ~ScriptGizmoManager();
  36. /**
  37. * @brief Iterates over all managed gizmos, calls their draw methods and registers
  38. * the gizmos with the native GizmoManager.
  39. */
  40. void update();
  41. private:
  42. /**
  43. * @brief Finds all gizmo methods (marked with the DrawGizmo attribute). Clears any previously found methods.
  44. */
  45. void reloadAssemblyData();
  46. /**
  47. * @brief Checks is the provided method a valid gizmo draw method and if it is, returns
  48. * properties of that method.
  49. *
  50. * @param method Method to check.
  51. * @param componentType Output parameter containing the component the method is part of. Only valid if this method returns true.
  52. * @param drawGizmoFlags Output parameters containing optional flags that control gizmo properties. Only valid if this method returns true.
  53. *
  54. * @return True if the method is a valid draw gizmo method.
  55. */
  56. bool isValidDrawGizmoMethod(MonoMethod* method, MonoClass*& componentType, UINT32& drawGizmoFlags);
  57. ScriptAssemblyManager& mScriptObjectManager;
  58. HEvent mDomainLoadedConn;
  59. MonoClass* mDrawGizmoAttribute;
  60. MonoField* mFlagsField;
  61. Map<String, GizmoData> mGizmoDrawers;
  62. };
  63. }