#pragma once #include "Game/Export.h" #include "Core/SObject.h" #include "Core/Factory.hpp" #include "Core/Logger.h" #include #include #define SRPO(T)\ SCLASS(T)\ struct _SRPO_Registry_##T\ {\ using Factory = sh::core::Factory;\ ~_SRPO_Registry_##T()\ {\ auto& stype = T::GetStaticType();\ auto& factory = *Factory::GetInstance();\ SH_INFO_FORMAT("UnRegister {}", stype.type.name);\ factory.UnRegister(std::string{ stype.type.name });\ }\ static auto GetStatic() -> _SRPO_Registry_##T*\ {\ auto& stype = T::GetStaticType();\ auto& factory = *Factory::GetInstance();\ if (factory.HasKey(std::string{ stype.type.name }))\ return nullptr;\ factory.Register(std::string{ stype.type.name }, []() {return sh::core::SObject::Create(); });\ static _SRPO_Registry_##T registry{};\ return ®istry;\ }\ };\ inline static _SRPO_Registry_##T* _srpoRegistry = _SRPO_Registry_##T::GetStatic();\ namespace sh::game { class ScriptableObject : public core::SObject { SCLASS(ScriptableObject) public: SH_GAME_API auto Serialize() const -> core::Json override; SH_GAME_API void Deserialize(const core::Json& json) override; public: using Factory = sh::core::Factory; }; }//namespace