BsPrefab.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. /** Initializes the internal prefab hierarchy. Must be called druing creation. */
  63. void initialize(const HSceneObject& sceneObject);
  64. /** Creates an empty and uninitialized prefab. */
  65. static PrefabPtr createEmpty();
  66. HSceneObject mRoot;
  67. UINT32 mHash;
  68. String mUUID;
  69. UINT32 mNextLinkId;
  70. /************************************************************************/
  71. /* RTTI */
  72. /************************************************************************/
  73. public:
  74. friend class PrefabRTTI;
  75. static RTTITypeBase* getRTTIStatic();
  76. virtual RTTITypeBase* getRTTI() const override;
  77. };
  78. /** @} */
  79. }