BsGameObjectRTTI.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsRTTIType.h"
  4. #include "BsGameObject.h"
  5. #include "BsSceneObject.h"
  6. #include "BsGameObjectManager.h"
  7. namespace BansheeEngine
  8. {
  9. class BS_CORE_EXPORT GameObjectRTTI : public RTTIType<GameObject, IReflectable, GameObjectRTTI>
  10. {
  11. private:
  12. String& getName(GameObject* obj) { return obj->mName; }
  13. void setName(GameObject* obj, String& name) { obj->mName = name; }
  14. UINT64& getInstanceID(GameObject* obj) { return obj->mInstanceData->mInstanceId; }
  15. void setInstanceID(GameObject* obj, UINT64& instanceId)
  16. {
  17. // The system will have already assigned the instance ID, but since other objects might be referencing
  18. // the old (serialized) ID we store it in the GameObjectSerializationManager so we can map from old to new id.
  19. GameObjectManager::instance().registerDeserializedId(instanceId, obj->getInstanceId());
  20. }
  21. INT32& getLinkId(GameObject* obj) { return obj->mLinkId; }
  22. void setLinkId(GameObject* obj, INT32& linkId) { obj->mLinkId = linkId; }
  23. public:
  24. template <typename T>
  25. static std::shared_ptr<T> createGameObject()
  26. {
  27. return SceneObject::createEmptyComponent<T>();
  28. }
  29. public:
  30. GameObjectRTTI()
  31. {
  32. addPlainField("mInstanceID", 0, &GameObjectRTTI::getInstanceID, &GameObjectRTTI::setInstanceID);
  33. addPlainField("mName", 1, &GameObjectRTTI::getName, &GameObjectRTTI::setName);
  34. addPlainField("mLinkId", 2, &GameObjectRTTI::getLinkId, &GameObjectRTTI::setLinkId);
  35. }
  36. virtual const String& getRTTIName()
  37. {
  38. static String name = "GameObject";
  39. return name;
  40. }
  41. virtual UINT32 getRTTIId()
  42. {
  43. return TID_GameObject;
  44. }
  45. virtual std::shared_ptr<IReflectable> newRTTIObject()
  46. {
  47. BS_EXCEPT(InternalErrorException, "Cannot instantiate an abstract class.");
  48. }
  49. };
  50. }