BsComponentRTTI.h 1.4 KB

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