2
0

BsComponentRTTI.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsRTTIType.h"
  4. #include "BsComponent.h"
  5. #include "BsGameObjectRTTI.h"
  6. namespace BansheeEngine
  7. {
  8. /** @cond RTTI */
  9. /** @addtogroup RTTI-Impl-Core
  10. * @{
  11. */
  12. class BS_CORE_EXPORT ComponentRTTI : public RTTIType<Component, GameObject, ComponentRTTI>
  13. {
  14. public:
  15. ComponentRTTI()
  16. { }
  17. void onDeserializationEnded(IReflectable* obj) override
  18. {
  19. Component* comp = static_cast<Component*>(obj);
  20. GODeserializationData& deserializationData = any_cast_ref<GODeserializationData>(comp->mRTTIData);
  21. // This shouldn't be null during normal deserialization but could be during some other operations, like applying
  22. // a binary diff.
  23. if (deserializationData.ptr != nullptr)
  24. {
  25. // Register the newly created SO with the GameObjectManager and provide it with the original ID so that
  26. // deserialized handles pointing to this object can be resolved.
  27. ComponentPtr compPtr = std::static_pointer_cast<Component>(deserializationData.ptr);
  28. GameObjectManager::instance().registerObject(compPtr, deserializationData.originalId);
  29. }
  30. comp->mRTTIData = nullptr;
  31. }
  32. const String& getRTTIName() override
  33. {
  34. static String name = "Component";
  35. return name;
  36. }
  37. UINT32 getRTTIId() override
  38. {
  39. return TID_Component;
  40. }
  41. std::shared_ptr<IReflectable> newRTTIObject() override
  42. {
  43. BS_EXCEPT(InternalErrorException, "Cannot instantiate an abstract class.");
  44. }
  45. };
  46. /** @} */
  47. /** @endcond */
  48. }