mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-24 03:56:31 +00:00
29 lines
1.0 KiB
C#
29 lines
1.0 KiB
C#
using System;
|
|
using Microsoft.Xna.Framework.Content;
|
|
using MonoGame.Extended.Serialization;
|
|
using MonoGame.Extended.TextureAtlases;
|
|
using Newtonsoft.Json;
|
|
|
|
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;
|
|
}
|
|
|
|
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
|
{
|
|
var textureAtlas = base.ReadJson(reader, objectType, existingValue, serializer) as TextureAtlas;
|
|
|
|
if (textureAtlas != null)
|
|
_textureRegionService.TextureAtlases.Add(textureAtlas);
|
|
|
|
return textureAtlas;
|
|
}
|
|
}
|
|
} |