Skip to content

Commit

Permalink
fix pivot issue on Sprit from #17 (author: Silvris)
Browse files Browse the repository at this point in the history
  • Loading branch information
Albeoris committed Jan 6, 2022
1 parent bf65f0d commit 1fff68f
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions Memoria.FF1/Shared/IL2CPP/ResourceManager_IsLoadAssetCompleted.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private static Object ImportTextures(String fullPath)
{
return TextureHelper.ReadTextureFromFile(fullPath);
}

private static Object ImportSprite(Sprite asset, String fullPath)
{
Rect originalRect = asset.rect;
Expand All @@ -148,16 +148,26 @@ private static Object ImportSprite(Sprite asset, String fullPath)
Single originalHeight = asset.texture.height;

Texture2D texture = TextureHelper.ReadTextureFromFile(fullPath);

texture.wrapMode = asset.texture.wrapMode;
texture.wrapModeU = asset.texture.wrapModeU;
texture.wrapModeV = asset.texture.wrapModeV;
texture.wrapModeW = asset.texture.wrapModeW;

Single newWidth = texture.width;
Single newHeight = texture.height;
Single ox = newWidth / originalWidth;
Single oy = newHeight / originalHeight;
Single px = originalPivot.x / originalWidth;
Single py = originalPivot.y / originalHeight;
Rect newRect = new Rect(originalRect.x * ox, originalRect.y * oy, originalRect.width * ox, originalRect.height * oy);
Vector2 newPivot = new Vector2(originalPivot.x * ox, originalPivot.y * oy);

return Sprite.Create(texture, newRect, newPivot, asset.pixelsPerUnit);
Vector2 newPivot = new Vector2(px, py);
Sprite newSpr = Sprite.Create(texture, newRect, newPivot, asset.pixelsPerUnit, 0, SpriteMeshType.Tight, asset.border);
newSpr.name = asset.name;
return newSpr;
}

private static Object ImportBinaryAsset(String assetName, String fullPath)
{
// Il2CppStructArray<Byte> sourceBytes = Il2CppSystem.IO.File.ReadAllBytes(fullPath);
Expand Down

0 comments on commit 1fff68f

Please sign in to comment.