template<> struct ClassMetadata<::Visual::SpriteComponent> : public IClassMetadata { std::type_index GetTypeIndex() const override { return typeid(Visual::SpriteComponent); } // Список на базовые метаданные. Нужен для вызова сгенерированных методов для базовых классов const std::vector& GetBaseMetas() const override { static std::vector classes = { Visual::MaterialComponent::GetMetaStatic(), }; return classes; } // Загрузка void Load(BaseInputArchive& archive, Serializable& obj) const override { auto&& value = static_cast<::Visual::SpriteComponent&>(obj); // Вызов базовых методов загрузки IClassMetadata::Load(archive, value); Visual::Ser::Load(archive, value._color, VSO_ARCHIVE_KEY("color", 62411)); ManagedSpriteOrTexture ___spriteOrTexture; if (Visual::Ser::Load(archive, ___spriteOrTexture, VSO_ARCHIVE_KEY("spriteOrTexture", 41639))) { value.SetSpriteOrTexture(___spriteOrTexture); } } // Сохранение доступно только для редакторов #if VSO_EDITOR_ENABLED void Save(BaseOutputArchive& archive, const Serializable& obj) const override { auto&& value = static_cast(obj); using namespace Visual; // Вызов базовых методов сохранения IClassMetadata::Save(archive, value); // Не пишем дефолтные значения, если не требуется if (archive.IsWriteDefaults() || value._color != Color::WHITE) { Visual::Ser::Save(archive, value._color, VSO_ARCHIVE_KEY("color", 62411)); } if (archive.IsWriteDefaults() || !Visual::IsDefault(value._spriteOrTexture)) { Visual::Ser::Save(archive, value._spriteOrTexture, VSO_ARCHIVE_KEY("spriteOrTexture", 41639)); } } #endif ​ BaseCloneable* MakeClone(const BaseCloneable& obj) const override { auto&& value = boost::polymorphic_downcast(&obj); return new Visual::SpriteComponent(*value); } ​ void TryRegisterEvents(Entity* entity, NodeSubscription& subscriptions, bool addEventCallbackToEnd) const override { auto value = boost::polymorphic_downcast(entity); NodeSubscription::TryRegisterEvents(value, subscriptions, addEventCallbackToEnd); } // Биндинг свойств для системы анимаций void Build(const PropertiesBinder& binder) const override { IClassMetadata::Build(binder); binder.AddProperty("color", std::make_unique>(&::Visual::SpriteComponent::GetColor, &::Visual::SpriteComponent::SetColor)); binder.AddProperty("alpha", std::make_unique>(&::Visual::SpriteComponent::GetAlpha, &::Visual::SpriteComponent::SetAlpha)); binder.AddProperty("id", std::make_unique>(&::Visual::SpriteComponent::GetId, &::Visual::SpriteComponent::SetId)); } };