BsPrefab.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. ~Prefab();
  17. /**
  18. * @brief Creates a new prefab from the provided scene object. If the scene object
  19. * has an existing prefab link it will be broken. After the prefab is created the
  20. * scene object will be automatically linked to it.
  21. */
  22. static HPrefab create(const HSceneObject& sceneObject);
  23. /**
  24. * @brief Instantiates a prefab by creating an instance of the prefab's
  25. * scene object hierarchy. The returned hierarchy will be parented
  26. * to world root by default.
  27. */
  28. HSceneObject instantiate();
  29. /**
  30. * @brief Replaces the contents of this prefab with new contents
  31. * from the provided object. Object will be automatically linked to
  32. * this prefab, and its previous prefab link (if any) will be broken.
  33. */
  34. void update(const HSceneObject& sceneObject);
  35. /**
  36. * @brief Returns a reference to the internal prefab hierarchy. Returned hierarchy is not instantiated and cannot
  37. * be interacted with in a manner you would with normal scene objects.
  38. *
  39. * @note Internal method.
  40. */
  41. HSceneObject _getRoot() const { return mRoot; }
  42. /**
  43. * @brief Returns a hash value that can be used for determining if a prefab changed
  44. * by comparing it to a previously saved hash.
  45. */
  46. UINT32 getHash() const { return mHash; }
  47. private:
  48. /**
  49. * @brief Initializes the internal prefab hierarchy. Must be called druing creation.
  50. */
  51. void initialize(const HSceneObject& sceneObject);
  52. /**
  53. * @brief Creates an empty and uninitialized prefab.
  54. */
  55. static PrefabPtr createEmpty();
  56. HSceneObject mRoot;
  57. UINT32 mHash;
  58. /************************************************************************/
  59. /* RTTI */
  60. /************************************************************************/
  61. public:
  62. friend class PrefabRTTI;
  63. static RTTITypeBase* getRTTIStatic();
  64. virtual RTTITypeBase* getRTTI() const override;
  65. };
  66. }