BsPrefab.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. If the scene object
  18. * has an existing prefab link it will be broken. 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. Object will be automatically linked to
  31. * this prefab, and its previous prefab link (if any) will be broken.
  32. */
  33. void update(const HSceneObject& sceneObject);
  34. /**
  35. * @brief Returns a reference to the internal prefab hierarchy. Returned hierarchy is not instantiated and cannot
  36. * be interacted with in a manner you would with normal scene objects.
  37. *
  38. * @note Internal method.
  39. */
  40. HSceneObject _getRoot() const { return mRoot; }
  41. /**
  42. * @brief Returns a hash value that can be used for determining if a prefab changed
  43. * by comparing it to a previously saved hash.
  44. */
  45. UINT32 getHash() const { return mHash; }
  46. private:
  47. /**
  48. * @brief Initializes the internal prefab hierarchy. Must be called druing creation.
  49. */
  50. void initialize(const HSceneObject& sceneObject);
  51. /**
  52. * @brief Creates an empty and uninitialized prefab.
  53. */
  54. static PrefabPtr createEmpty();
  55. HSceneObject mRoot;
  56. UINT32 mHash;
  57. /************************************************************************/
  58. /* RTTI */
  59. /************************************************************************/
  60. public:
  61. friend class PrefabRTTI;
  62. static RTTITypeBase* getRTTIStatic();
  63. virtual RTTITypeBase* getRTTI() const override;
  64. };
  65. }