BsPrefab.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsGameObject.h"
  4. #include "BsResource.h"
  5. namespace BansheeEngine
  6. {
  7. /**
  8. * @brief Prefab is a saveable hierarchy of scene objects. In general it
  9. * can serve as any grouping of scene objects (e.g. a level) or be used
  10. * as a form of a template instantiated and reused throughout the scene.
  11. */
  12. class BS_CORE_EXPORT Prefab : public Resource
  13. {
  14. public:
  15. Prefab();
  16. /**
  17. * @brief Creates a new prefab from the provided scene object. If the scene object
  18. * has an existing prefab link it will be broken. After the prefab is created the
  19. * scene object will be automatically linked to it.
  20. */
  21. static HPrefab create(const HSceneObject& sceneObject);
  22. /**
  23. * @brief Instantiates a prefab by creating an instance of the prefab's
  24. * scene object hierarchy. The returned hierarchy will be parented
  25. * to world root by default.
  26. */
  27. HSceneObject instantiate();
  28. /**
  29. * @brief Replaces the contents of this prefab with new contents
  30. * from the provided object.
  31. */
  32. void update(const HSceneObject& sceneObject);
  33. /**
  34. * @brief Returns a reference to the internal prefab hierarchy. Returned hierarchy is not instantiated and cannot
  35. * be interacted with in a manner you would with normal scene objects.
  36. *
  37. * @note Internal method.
  38. */
  39. HSceneObject _getRoot() const { return mRoot; }
  40. /**
  41. * @brief Returns a hash value that can be used for determining if a prefab changed
  42. * by comparing it to a previously saved hash.
  43. */
  44. UINT32 getHash() const { return mHash; }
  45. private:
  46. /**
  47. * @brief Initializes the internal prefab hierarchy. Must be called druing creation.
  48. */
  49. void initialize(const HSceneObject& sceneObject);
  50. /**
  51. * @brief Creates an empty and uninitialized prefab.
  52. */
  53. static PrefabPtr createEmpty();
  54. HSceneObject mRoot;
  55. UINT32 mHash;
  56. /************************************************************************/
  57. /* RTTI */
  58. /************************************************************************/
  59. public:
  60. friend class PrefabRTTI;
  61. static RTTITypeBase* getRTTIStatic();
  62. virtual RTTITypeBase* getRTTI() const override;
  63. };
  64. }