BsGameObjectRTTI.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. public:
  22. template <typename T>
  23. static std::shared_ptr<T> createGameObject()
  24. {
  25. return SceneObject::createEmptyComponent<T>();
  26. }
  27. public:
  28. GameObjectRTTI()
  29. {
  30. addPlainField("mInstanceID", 0, &GameObjectRTTI::getInstanceID, &GameObjectRTTI::setInstanceID);
  31. addPlainField("mName", 1, &GameObjectRTTI::getName, &GameObjectRTTI::setName);
  32. }
  33. virtual const String& getRTTIName()
  34. {
  35. static String name = "GameObject";
  36. return name;
  37. }
  38. virtual UINT32 getRTTIId()
  39. {
  40. return TID_GameObject;
  41. }
  42. virtual std::shared_ptr<IReflectable> newRTTIObject()
  43. {
  44. BS_EXCEPT(InternalErrorException, "Cannot instantiate an abstract class.");
  45. }
  46. };
  47. }