BsPrefab.h 3.1 KB

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