BsPrefab.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. The scene object
  18. * must not have a prefab link already. 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.
  35. */
  36. HSceneObject getRoot() const { return mRoot; }
  37. /**
  38. * @brief Returns a hash value that can be used for determining if a prefab changed
  39. * by comparing it to a previously saved hash.
  40. */
  41. UINT32 getHash() const { return mHash; }
  42. private:
  43. /**
  44. * @brief Initializes the internal prefab hierarchy. Must be called druing creation.
  45. */
  46. void initialize(const HSceneObject& sceneObject);
  47. /**
  48. * @brief Creates an empty and uninitialized prefab.
  49. */
  50. static PrefabPtr createEmpty();
  51. HSceneObject mRoot;
  52. UINT32 mHash;
  53. /************************************************************************/
  54. /* RTTI */
  55. /************************************************************************/
  56. public:
  57. friend class PrefabRTTI;
  58. static RTTITypeBase* getRTTIStatic();
  59. virtual RTTITypeBase* getRTTI() const override;
  60. };
  61. }