mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-26 00:45:20 +00:00
* Converted to use `System.Text.Json` * Remove Newtonsoft.Json Dependency Newtonsoft.Json dependency has been removed in favor of System.Text.Json * Treat MGFXO file as binary
32 lines
1.0 KiB
C#
32 lines
1.0 KiB
C#
using System;
|
|
using System.Text.Json;
|
|
using Microsoft.Xna.Framework.Content;
|
|
using MonoGame.Extended.Serialization;
|
|
using MonoGame.Extended.TextureAtlases;
|
|
|
|
namespace MonoGame.Extended.Gui.Serialization
|
|
{
|
|
public class GuiTextureAtlasJsonConverter : ContentManagerJsonConverter<TextureAtlas>
|
|
{
|
|
private readonly IGuiTextureRegionService _textureRegionService;
|
|
|
|
public GuiTextureAtlasJsonConverter(ContentManager contentManager, IGuiTextureRegionService textureRegionService)
|
|
: base(contentManager, atlas => atlas.Name)
|
|
{
|
|
_textureRegionService = textureRegionService;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override TextureAtlas Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
|
{
|
|
var textureAtlas = base.Read(ref reader, typeToConvert, options);
|
|
if (textureAtlas is not null)
|
|
{
|
|
_textureRegionService.TextureAtlases.Add(textureAtlas);
|
|
}
|
|
|
|
return textureAtlas;
|
|
}
|
|
}
|
|
}
|