BsComponentRTTI.h 1.7 KB

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