获取EmuCore的OutputTex时,还会根据DrawCanvas的localscale,来纠正存档图片Y轴翻转的处理
This commit is contained in:
parent
8e24f556af
commit
959956706f
AxibugEmuOnline.Client/Assets/Script/AppMain
@ -67,7 +67,7 @@ namespace AxibugEmuOnline.Client
|
|||||||
{
|
{
|
||||||
var stateData = m_ingameUI.Core.GetStateBytes();
|
var stateData = m_ingameUI.Core.GetStateBytes();
|
||||||
var tex = m_ingameUI.Core.OutputPixel;
|
var tex = m_ingameUI.Core.OutputPixel;
|
||||||
var screenData = tex.ToJPG();
|
var screenData = tex.ToJPG(m_ingameUI.Core.DrawCanvas.transform.localScale);
|
||||||
|
|
||||||
m_savFile.Save(m_savFile.Sequecen, stateData, screenData);
|
m_savFile.Save(m_savFile.Sequecen, stateData, screenData);
|
||||||
}
|
}
|
||||||
|
@ -55,29 +55,26 @@ namespace AxibugEmuOnline.Client
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] ToJPG(this Texture texture)
|
public static byte[] ToJPG(this Texture texture, Vector2 scale)
|
||||||
{
|
{
|
||||||
Texture2D outputTex = null;
|
Texture2D outputTex = ConvertFromRenderTexture(texture, scale);
|
||||||
if (texture is RenderTexture rt)
|
|
||||||
{
|
|
||||||
outputTex = ConvertFromRenderTexture(rt);
|
|
||||||
}
|
|
||||||
else if (texture is Texture2D)
|
|
||||||
{
|
|
||||||
outputTex = texture as Texture2D;
|
|
||||||
}
|
|
||||||
|
|
||||||
return outputTex.EncodeToJPG();
|
return outputTex.EncodeToJPG();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Texture2D ConvertFromRenderTexture(RenderTexture rt)
|
private static Texture2D ConvertFromRenderTexture(Texture src, Vector2 scale)
|
||||||
{
|
{
|
||||||
|
float offsetX = (scale.x < 0) ? 1 : 0;
|
||||||
|
float offsetY = (scale.y < 0) ? 1 : 0;
|
||||||
|
|
||||||
|
var offset = new Vector2(offsetX, offsetY);
|
||||||
|
|
||||||
// 创建临时RenderTexture并拷贝内容
|
// 创建临时RenderTexture并拷贝内容
|
||||||
RenderTexture tempRT = RenderTexture.GetTemporary(rt.width, rt.height, 0, RenderTextureFormat.ARGB32);
|
RenderTexture tempRT = RenderTexture.GetTemporary(src.width, src.height, 0, RenderTextureFormat.ARGB32);
|
||||||
Graphics.Blit(rt, tempRT);
|
Graphics.Blit(src, tempRT, scale, offset);
|
||||||
|
|
||||||
// 读取到Texture2D
|
// 读取到Texture2D
|
||||||
Texture2D tex = new Texture2D(rt.width, rt.height, TextureFormat.RGBA32, false);
|
Texture2D tex = new Texture2D(src.width, src.height, TextureFormat.RGBA32, false);
|
||||||
RenderTexture.active = tempRT;
|
RenderTexture.active = tempRT;
|
||||||
tex.ReadPixels(new Rect(0, 0, tempRT.width, tempRT.height), 0, 0);
|
tex.ReadPixels(new Rect(0, 0, tempRT.width, tempRT.height), 0, 0);
|
||||||
tex.Apply();
|
tex.Apply();
|
||||||
|
Loading…
Reference in New Issue
Block a user