BsPrefab.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. ~Prefab();
  17. /**
  18. * @brief Creates a new prefab from the provided scene object. If the scene object
  19. * has an existing prefab link it will be broken. After the prefab is created the
  20. * scene object will be automatically linked to it.
  21. */
  22. static HPrefab create(const HSceneObject& sceneObject);
  23. /**
  24. * @brief Instantiates a prefab by creating an instance of the prefab's
  25. * scene object hierarchy. The returned hierarchy will be parented
  26. * to world root by default.
  27. *
  28. * @returns Instantiated clone of the prefab's scene object hierarchy.
  29. */
  30. HSceneObject instantiate();
  31. /**
  32. * @brief Replaces the contents of this prefab with new contents
  33. * from the provided object. Object will be automatically linked to
  34. * this prefab, and its previous prefab link (if any) will be broken.
  35. */
  36. void update(const HSceneObject& sceneObject);
  37. /**
  38. * @brief Updates any prefab child instances by loading their prefabs and making sure they are up to date.
  39. *
  40. * @note Internal method.
  41. */
  42. void _updateChildInstances();
  43. /**
  44. * @brief Returns a reference to the internal prefab hierarchy. Returned hierarchy is not instantiated and cannot
  45. * be interacted with in a manner you would with normal scene objects.
  46. *
  47. * @note Internal method.
  48. */
  49. HSceneObject _getRoot() const { return mRoot; }
  50. /**
  51. * @brief Creates the clone of the prefab's current hierarchy but doesn't instantiate it.
  52. *
  53. * @returns Clone of the prefab's scene object hierarchy.
  54. *
  55. * @note Internal method.
  56. */
  57. HSceneObject _clone();
  58. /**
  59. * @brief Returns a hash value that can be used for determining if a prefab changed
  60. * by comparing it to a previously saved hash.
  61. */
  62. UINT32 getHash() const { return mHash; }
  63. private:
  64. /**
  65. * @brief Initializes the internal prefab hierarchy. Must be called druing creation.
  66. */
  67. void initialize(const HSceneObject& sceneObject);
  68. /**
  69. * @brief Creates an empty and uninitialized prefab.
  70. */
  71. static PrefabPtr createEmpty();
  72. HSceneObject mRoot;
  73. UINT32 mHash;
  74. String mUUID;
  75. UINT32 mNextLinkId;
  76. /************************************************************************/
  77. /* RTTI */
  78. /************************************************************************/
  79. public:
  80. friend class PrefabRTTI;
  81. static RTTITypeBase* getRTTIStatic();
  82. virtual RTTITypeBase* getRTTI() const override;
  83. };
  84. }