BsComponent.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsGameObject.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief Components represent primarily logic elements in the scene.
  8. * They are attached to scene objects.
  9. */
  10. class BS_CORE_EXPORT Component : public GameObject
  11. {
  12. public:
  13. /**
  14. * @brief Returns the SceneObject this Component is assigned to.
  15. */
  16. HSceneObject sceneObject() const { return mParent; }
  17. /**
  18. * @copydoc sceneObject
  19. */
  20. HSceneObject SO() const { return sceneObject(); }
  21. /**
  22. * @brief Called once per frame on all components.
  23. *
  24. * @note Internal method.
  25. */
  26. virtual void update() { }
  27. /**
  28. * @brief Removes the component from parent SceneObject and deletes it. All
  29. * the references to this component will be marked as destroyed and you
  30. * will get an exception if you try to use them.
  31. *
  32. * @param [in] immediate If true the destruction will be performed immediately, otherwise
  33. * it will be delayed until the end of the current frame (preferred option).
  34. */
  35. void destroy(bool immediate = false);
  36. protected:
  37. friend class SceneObject;
  38. Component(const HSceneObject& parent);
  39. virtual ~Component();
  40. /**
  41. * @brief Called just before the component is destroyed.
  42. */
  43. virtual void onDestroyed() {}
  44. private:
  45. Component(const Component& other) { }
  46. protected:
  47. HSceneObject mParent;
  48. /************************************************************************/
  49. /* RTTI */
  50. /************************************************************************/
  51. public:
  52. friend class ComponentRTTI;
  53. static RTTITypeBase* getRTTIStatic();
  54. virtual RTTITypeBase* getRTTI() const;
  55. protected:
  56. Component() {} // Serialization only
  57. };
  58. }