BsPrefab.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. * (e.g. 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. /** @cond INTERNAL */
  44. /** Updates any prefab child instances by loading their prefabs and making sure they are up to date. */
  45. void _updateChildInstances();
  46. /**
  47. * Returns a reference to the internal prefab hierarchy. Returned hierarchy is not instantiated and cannot be
  48. * interacted with in a manner you would with normal scene objects.
  49. */
  50. HSceneObject _getRoot() const { return mRoot; }
  51. /**
  52. * Creates the clone of the prefab's current hierarchy but doesn't instantiate it.
  53. *
  54. * @return Clone of the prefab's scene object hierarchy.
  55. */
  56. HSceneObject _clone();
  57. /** @endcond */
  58. private:
  59. /** Initializes the internal prefab hierarchy. Must be called druing creation. */
  60. void initialize(const HSceneObject& sceneObject);
  61. /** Creates an empty and uninitialized prefab. */
  62. static PrefabPtr createEmpty();
  63. HSceneObject mRoot;
  64. UINT32 mHash;
  65. String mUUID;
  66. UINT32 mNextLinkId;
  67. /************************************************************************/
  68. /* RTTI */
  69. /************************************************************************/
  70. public:
  71. friend class PrefabRTTI;
  72. static RTTITypeBase* getRTTIStatic();
  73. virtual RTTITypeBase* getRTTI() const override;
  74. };
  75. /** @} */
  76. }