BsPrefab.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsGameObject.h"
  4. #include "BsResource.h"
  5. namespace BansheeEngine
  6. {
  7. /** @addtogroup Scene
  8. * @{
  9. */
  10. /**
  11. * Prefab is a saveable hierarchy of scene objects. In general it can serve as any grouping of scene objects
  12. * (e.g. a level) or be used as a form of a template instantiated and reused throughout the scene.
  13. */
  14. class BS_CORE_EXPORT Prefab : public Resource
  15. {
  16. public:
  17. Prefab();
  18. ~Prefab();
  19. /**
  20. * Creates a new prefab from the provided scene object. If the scene object has an existing prefab link it will
  21. * be broken. After the prefab is created the scene object will be automatically linked to it.
  22. */
  23. static HPrefab create(const HSceneObject& sceneObject);
  24. /**
  25. * Instantiates a prefab by creating an instance of the prefab's scene object hierarchy. The returned hierarchy
  26. * will be parented to world root by default.
  27. *
  28. * @return Instantiated clone of the prefab's scene object hierarchy.
  29. */
  30. HSceneObject instantiate();
  31. /**
  32. * Replaces the contents of this prefab with new contents from the provided object. Object will be automatically
  33. * linked to this prefab, and its previous prefab link (if any) will be broken.
  34. */
  35. void update(const HSceneObject& sceneObject);
  36. /**
  37. * Returns a hash value that can be used for determining if a prefab changed by comparing it to a previously saved
  38. * hash.
  39. */
  40. UINT32 getHash() const { return mHash; }
  41. /** @cond INTERNAL */
  42. /** Updates any prefab child instances by loading their prefabs and making sure they are up to date. */
  43. void _updateChildInstances();
  44. /**
  45. * Returns a reference to the internal prefab hierarchy. Returned hierarchy is not instantiated and cannot be
  46. * interacted with in a manner you would with normal scene objects.
  47. */
  48. HSceneObject _getRoot() const { return mRoot; }
  49. /**
  50. * Creates the clone of the prefab's current hierarchy but doesn't instantiate it.
  51. *
  52. * @return Clone of the prefab's scene object hierarchy.
  53. */
  54. HSceneObject _clone();
  55. /** @endcond */
  56. private:
  57. /** Initializes the internal prefab hierarchy. Must be called druing creation. */
  58. void initialize(const HSceneObject& sceneObject);
  59. /** Creates an empty and uninitialized prefab. */
  60. static PrefabPtr createEmpty();
  61. HSceneObject mRoot;
  62. UINT32 mHash;
  63. String mUUID;
  64. UINT32 mNextLinkId;
  65. /************************************************************************/
  66. /* RTTI */
  67. /************************************************************************/
  68. public:
  69. friend class PrefabRTTI;
  70. static RTTITypeBase* getRTTIStatic();
  71. virtual RTTITypeBase* getRTTI() const override;
  72. };
  73. /** @} */
  74. }