BsPrefab.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. * @param onlyClone If true the internal prefab hierarchy will be cloned and returned, but not actually
  29. * instantiated. Caller must ensure to call ::instantiate on the returned scene object.
  30. * If false the returned scene object will be instantiated before returning.
  31. *
  32. * @returns Clone of the prefab's scene object hierarchy.
  33. */
  34. HSceneObject instantiate(bool onlyClone = false);
  35. /**
  36. * @brief Replaces the contents of this prefab with new contents
  37. * from the provided object. Object will be automatically linked to
  38. * this prefab, and its previous prefab link (if any) will be broken.
  39. */
  40. void update(const HSceneObject& sceneObject);
  41. /**
  42. * @brief Returns a reference to the internal prefab hierarchy. Returned hierarchy is not instantiated and cannot
  43. * be interacted with in a manner you would with normal scene objects.
  44. *
  45. * @note Internal method.
  46. */
  47. HSceneObject _getRoot() const { return mRoot; }
  48. /**
  49. * @brief Returns a hash value that can be used for determining if a prefab changed
  50. * by comparing it to a previously saved hash.
  51. */
  52. UINT32 getHash() const { return mHash; }
  53. private:
  54. /**
  55. * @brief Initializes the internal prefab hierarchy. Must be called druing creation.
  56. */
  57. void initialize(const HSceneObject& sceneObject);
  58. /**
  59. * @brief Creates an empty and uninitialized prefab.
  60. */
  61. static PrefabPtr createEmpty();
  62. HSceneObject mRoot;
  63. UINT32 mHash;
  64. String mUUID;
  65. UINT32 mNextLinkId;
  66. /************************************************************************/
  67. /* RTTI */
  68. /************************************************************************/
  69. public:
  70. friend class PrefabRTTI;
  71. static RTTITypeBase* getRTTIStatic();
  72. virtual RTTITypeBase* getRTTI() const override;
  73. };
  74. }