BsPrefab.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsGameObject.h"
  4. #include "BsResource.h"
  5. namespace BansheeEngine
  6. {
  7. /**
  8. * @brief Prefab is a saveable hierarchy of scene objects. In general it
  9. * can serve as any grouping of scene objects (e.g. a level) or be used
  10. * as a form of a template instantiated and reused throughout the scene.
  11. */
  12. class BS_CORE_EXPORT Prefab : public Resource
  13. {
  14. public:
  15. Prefab();
  16. /**
  17. * @brief Creates a new prefab from the provided scene object. The scene object
  18. * must not have a prefab link already. After the prefab is created the
  19. * scene object will be automatically linked to it.
  20. */
  21. static HPrefab create(const HSceneObject& sceneObject);
  22. /**
  23. * @brief Instantiates a prefab by creating an instance of the prefab's
  24. * scene object hierarchy. The returned hierarchy will be parented
  25. * to world root by default.
  26. */
  27. HSceneObject instantiate();
  28. /**
  29. * @brief Replaces the contents of this prefab with new contents
  30. * from the provided object.
  31. */
  32. void update(const HSceneObject& sceneObject);
  33. /**
  34. * @brief Returns a reference to the internal prefab hierarchy.
  35. */
  36. HSceneObject getRoot() const { return mRoot; }
  37. private:
  38. /**
  39. * @brief Initializes the internal prefab hierarchy. Must be called druing creation.
  40. */
  41. void initialize(const HSceneObject& sceneObject);
  42. /**
  43. * @brief Creates an empty and uninitialized prefab.
  44. */
  45. static PrefabPtr createEmpty();
  46. HSceneObject mRoot;
  47. /************************************************************************/
  48. /* RTTI */
  49. /************************************************************************/
  50. public:
  51. friend class PrefabRTTI;
  52. static RTTITypeBase* getRTTIStatic();
  53. virtual RTTITypeBase* getRTTI() const override;
  54. };
  55. }