BsPrefab.h 3.1 KB

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