mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-15 15:09:29 +00:00
b1ad92a7a0
* Correct exception message * Pass serializer options as param for MultiDimensional reads * Refactor to use TryGetRegion * Update for System.Text.Json parsing
34 lines
842 B
C#
34 lines
842 B
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using MonoGame.Extended.Graphics;
|
|
|
|
namespace MonoGame.Extended.Serialization.Json
|
|
{
|
|
public interface ITextureRegionService
|
|
{
|
|
Texture2DRegion GetTextureRegion(string name);
|
|
}
|
|
|
|
public class TextureRegionService : ITextureRegionService
|
|
{
|
|
public TextureRegionService()
|
|
{
|
|
TextureAtlases = new List<Texture2DAtlas>();
|
|
}
|
|
|
|
public IList<Texture2DAtlas> TextureAtlases { get; }
|
|
|
|
public Texture2DRegion GetTextureRegion(string name)
|
|
{
|
|
foreach (Texture2DAtlas atlas in TextureAtlases)
|
|
{
|
|
if (atlas.TryGetRegion(name, out Texture2DRegion region))
|
|
{
|
|
return region;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
}
|