Compare commits

...

3 Commits

4 changed files with 16 additions and 19 deletions

View File

@ -551,13 +551,13 @@ RectTransform:
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4232056521759880276} m_GameObject: {fileID: 4232056521759880276}
m_LocalRotation: {x: 1, y: 0, z: 0, w: 0} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: -1, z: 1}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: [] m_Children: []
m_Father: {fileID: 4232056520494431727} m_Father: {fileID: 4232056520494431727}
m_LocalEulerAnglesHint: {x: 180, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1} m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0} m_AnchoredPosition: {x: 0, y: 0}

View File

@ -1688,7 +1688,7 @@ RectTransform:
m_GameObject: {fileID: 5162569472849600096} m_GameObject: {fileID: 5162569472849600096}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: -1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: [] m_Children: []
m_Father: {fileID: 5970282275929291192} m_Father: {fileID: 5970282275929291192}

View File

@ -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);
} }

View File

@ -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();