public void SetTexture(int index)
{
if (index >= _regions.Count) return;
var region = _regions[index];
_drawableElement.Material.DiffuseTexture = region.Texture;
if (region.Rectangle.HasValue)
{
var rectangle = region.Rectangle.Value;
_drawableElement.Material.TexcoordOffset = region.Texture.GetTexcoordsFromPixelCoords(rectangle.X, rectangle.Y);
_drawableElement.Material.TexcoordScale = region.Texture.GetTexcoordsFromPixelCoords(rectangle.Width, rectangle.Height);
}
else
{
_drawableElement.Material.TexcoordOffset = Vector2.Zero;
_drawableElement.Material.TexcoordScale = Vector2.One;
}
}