BsComponent.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //__________________________ Banshee Project - A modern game development toolkit _________________________________//
  2. //_____________________________________ www.banshee-project.com __________________________________________________//
  3. //________________________ Copyright (c) 2014 Marko Pintera. All rights reserved. ________________________________//
  4. #pragma once
  5. #include "BsCorePrerequisites.h"
  6. #include "BsGameObject.h"
  7. namespace BansheeEngine
  8. {
  9. /**
  10. * @brief Components represent primarily logic elements in the scene.
  11. * They are attached to scene objects.
  12. */
  13. class BS_CORE_EXPORT Component : public GameObject
  14. {
  15. public:
  16. /**
  17. * @brief Returns the SceneObject this Component is assigned to.
  18. */
  19. HSceneObject sceneObject() const { return mParent; }
  20. /**
  21. * @copydoc sceneObject
  22. */
  23. HSceneObject SO() const { return sceneObject(); }
  24. /**
  25. * @brief Called once per frame on all components.
  26. *
  27. * @note Internal method.
  28. */
  29. virtual void update() { }
  30. /**
  31. * @brief Removes the component from parent SceneObject and deletes it. All
  32. * the references to this component will be marked as destroyed and you
  33. * will get an exception if you try to use them.
  34. */
  35. void destroy();
  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. }