BsPrefabDiff.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsIReflectable.h"
  4. #include "BsGameObject.h"
  5. namespace BansheeEngine
  6. {
  7. /**
  8. * @brief Contains differences between two components of the same type.
  9. *
  10. * @see PrefabDiff
  11. */
  12. struct BS_CORE_EXPORT PrefabComponentDiff : public IReflectable
  13. {
  14. INT32 id;
  15. SPtr<SerializedObject> data;
  16. /************************************************************************/
  17. /* RTTI */
  18. /************************************************************************/
  19. public:
  20. friend class PrefabComponentDiffRTTI;
  21. static RTTITypeBase* getRTTIStatic();
  22. virtual RTTITypeBase* getRTTI() const override;
  23. };
  24. /**
  25. * @brief Contains a set of prefab differences for a single scene object.
  26. *
  27. * @see PrefabDiff
  28. */
  29. struct BS_CORE_EXPORT PrefabObjectDiff : public IReflectable
  30. {
  31. INT32 id;
  32. String name;
  33. Vector<SPtr<PrefabComponentDiff>> componentDiffs;
  34. Vector<INT32> removedComponents;
  35. Vector<SPtr<SerializedObject>> addedComponents;
  36. Vector<SPtr<PrefabObjectDiff>> childDiffs;
  37. Vector<INT32> removedChildren;
  38. Vector<SPtr<SerializedObject>> addedChildren;
  39. /************************************************************************/
  40. /* RTTI */
  41. /************************************************************************/
  42. public:
  43. friend class PrefabObjectDiffRTTI;
  44. static RTTITypeBase* getRTTIStatic();
  45. virtual RTTITypeBase* getRTTI() const override;
  46. };
  47. /**
  48. * @brief Contains modifications between an prefab and its instance. The modifications are a set of
  49. * added/removed children or components and per-field "diffs" of their components.
  50. */
  51. class BS_CORE_EXPORT PrefabDiff : public IReflectable
  52. {
  53. public:
  54. /**
  55. * @brief Creates a new prefab diff by comparing the provided instanced scene object hierarchy
  56. * with the prefab scene object hierarchy.
  57. */
  58. static SPtr<PrefabDiff> create(const HSceneObject& prefab, const HSceneObject& instance);
  59. /**
  60. * @brief Applies the internal prefab diff to the provided object. The object should have
  61. * similar hierarchy as the prefab the diff was created for, otherwise the results are
  62. * undefined.
  63. */
  64. void apply(const HSceneObject& object);
  65. private:
  66. /**
  67. * @brief Recurses over every scene object in the prefab a generates differences between itself
  68. * and the instanced version.
  69. *
  70. * @see create
  71. */
  72. static SPtr<PrefabObjectDiff> generateDiff(const HSceneObject& prefab, const HSceneObject& instance);
  73. /**
  74. * @brief Recursively applies a per-object set of prefab differences to a specific object.
  75. *
  76. * @see apply
  77. */
  78. static void applyDiff(const SPtr<PrefabObjectDiff>& diff, const HSceneObject& object);
  79. SPtr<PrefabObjectDiff> mRoot;
  80. /************************************************************************/
  81. /* RTTI */
  82. /************************************************************************/
  83. public:
  84. friend class PrefabDiffRTTI;
  85. static RTTITypeBase* getRTTIStatic();
  86. virtual RTTITypeBase* getRTTI() const override;
  87. };
  88. }