If I use AnimationSprite on Android, App happened exception 'TitleContainer.OpenStream requires a relative path' at TextureAtlasJsonConverter.

MonoGame's content loader need relative path on Android.
This fix is load content by relative path if happened exception.
This commit is contained in:
garakuta
2022-08-10 08:04:04 +09:00
parent 2f9d6256b5
commit a47e066458
@@ -53,8 +53,17 @@ namespace MonoGame.Extended.TextureAtlases
var directory = Path.GetDirectoryName(_path);
var relativePath = Path.Combine(_contentManager.RootDirectory, directory, textureDirectory, textureName);
var resolvedAssetName = Path.GetFullPath(relativePath);
var texture = _contentManager.Load<Texture2D>(resolvedAssetName);
Texture2D texture;
try
{
texture = _contentManager.Load<Texture2D>(resolvedAssetName);
}
catch (Exception ex) {
if (textureDirectory == null || textureDirectory == "")
texture = _contentManager.Load<Texture2D>(textureName);
else
texture = _contentManager.Load<Texture2D>(textureDirectory + "/" + textureName);
}
return TextureAtlas.Create(resolvedAssetName, texture, metadata.RegionWidth, metadata.RegionHeight);
}
}