2
0

BsPrefab.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. * @param[in] sceneObject Scene object to create the prefab from.
  26. * @param[in] isScene Determines if the prefab represents a scene or just a generic group of objects.
  27. * @see isScene().
  28. */
  29. static HPrefab create(const HSceneObject& sceneObject, bool isScene = true);
  30. /**
  31. * Instantiates a prefab by creating an instance of the prefab's scene object hierarchy. The returned hierarchy
  32. * will be parented to world root by default.
  33. *
  34. * @return Instantiated clone of the prefab's scene object hierarchy.
  35. */
  36. HSceneObject instantiate();
  37. /**
  38. * Replaces the contents of this prefab with new contents from the provided object. Object will be automatically
  39. * linked to this prefab, and its previous prefab link (if any) will be broken.
  40. */
  41. void update(const HSceneObject& sceneObject);
  42. /**
  43. * Returns a hash value that can be used for determining if a prefab changed by comparing it to a previously saved
  44. * hash.
  45. */
  46. UINT32 getHash() const { return mHash; }
  47. /**
  48. * Determines if the prefab represents a scene or just a generic group of objects. The only difference between the
  49. * two is the way root object is handled: scenes are assumed to be saved with the scene root object (which is
  50. * hidden), while object group root is a normal scene object (not hidden). This is relevant when when prefabs are
  51. * loaded, so the systems knows to append the root object to non-scene prefabs.
  52. */
  53. bool isScene() const { return mIsScene; }
  54. public: // ***** INTERNAL ******
  55. /** @name Internal
  56. * @{
  57. */
  58. /** Updates any prefab child instances by loading their prefabs and making sure they are up to date. */
  59. void _updateChildInstances();
  60. /**
  61. * Returns a reference to the internal prefab hierarchy. Returned hierarchy is not instantiated and cannot be
  62. * interacted with in a manner you would with normal scene objects.
  63. */
  64. HSceneObject _getRoot() const { return mRoot; }
  65. /**
  66. * Creates the clone of the prefab's current hierarchy but doesn't instantiate it.
  67. *
  68. * @return Clone of the prefab's scene object hierarchy.
  69. */
  70. HSceneObject _clone();
  71. /** @} */
  72. private:
  73. using CoreObject::initialize;
  74. /** Initializes the internal prefab hierarchy. Must be called druing creation. */
  75. void initialize(const HSceneObject& sceneObject);
  76. /** Creates an empty and uninitialized prefab. */
  77. static SPtr<Prefab> createEmpty();
  78. HSceneObject mRoot;
  79. UINT32 mHash;
  80. String mUUID;
  81. UINT32 mNextLinkId;
  82. bool mIsScene;
  83. /************************************************************************/
  84. /* RTTI */
  85. /************************************************************************/
  86. public:
  87. friend class PrefabRTTI;
  88. static RTTITypeBase* getRTTIStatic();
  89. RTTITypeBase* getRTTI() const override;
  90. };
  91. /** @} */
  92. }