BsComponent.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. void destroy();
  33. protected:
  34. friend class SceneObject;
  35. Component(const HSceneObject& parent);
  36. virtual ~Component();
  37. /**
  38. * @brief Called just before the component is destroyed.
  39. */
  40. virtual void onDestroyed() {}
  41. private:
  42. Component(const Component& other) { }
  43. protected:
  44. HSceneObject mParent;
  45. /************************************************************************/
  46. /* RTTI */
  47. /************************************************************************/
  48. public:
  49. friend class ComponentRTTI;
  50. static RTTITypeBase* getRTTIStatic();
  51. virtual RTTITypeBase* getRTTI() const;
  52. protected:
  53. Component() {} // Serialization only
  54. };
  55. }