public void CreatePng(ref byte[] pngData, int createW = 252, int createH = 352, float renderRate = 1f) { if (createW == 0 || createH == 0) { createW = 252; createH = 352; } Vector2 screenSize = ScreenInfo.GetScreenSize(); float screenRate = ScreenInfo.GetScreenRate(); float screenCorrectY = ScreenInfo.GetScreenCorrectY(); float num = 720f * screenRate / screenSize.y; int num4 = (int)(504f * renderRate); int num5 = (int)(704f * renderRate); RenderTexture temporary; if (QualitySettings.antiAliasing == 0) { temporary = RenderTexture.GetTemporary((int)(1280f * renderRate / num), (int)(720f * renderRate / num), 24); } else { temporary = RenderTexture.GetTemporary((int)(1280f * renderRate / num), (int)(720f * renderRate / num), 24, RenderTextureFormat.Default, RenderTextureReadWrite.Default, QualitySettings.antiAliasing); } if (Camera.main) { Camera main = Camera.main; RenderTexture targetTexture = main.targetTexture; Rect rect = main.rect; main.targetTexture = temporary; main.Render(); main.targetTexture = targetTexture; main.rect = rect; } Texture2D texture2D = new Texture2D(num4, num5, TextureFormat.RGB24, false, true); RenderTexture.active = temporary; float x = 388f * renderRate + (1280f / num - 1280f) * 0.5f * renderRate; float y = 8f * renderRate + screenCorrectY / screenRate * renderRate; texture2D.ReadPixels(new Rect(x, y, num4, num5), 0, 0); texture2D.Apply(); RenderTexture.active = null; RenderTexture.ReleaseTemporary(temporary); if (num4 != createW || num5 != createH) { TextureScale.Bilinear(texture2D, createW, createH); } pngData = texture2D.EncodeToPNG(); Destroy(texture2D); }
public static void CreatePng( ref byte[] pngData, int capW = 504, int capH = 704, int createW = 252, int createH = 352, float renderRate = 1f, bool drawBackSp = true, bool drawFrontSp = true) { GameObject gameObjectWithTag = GameObject.FindGameObjectWithTag("SpriteTop"); Vector2 screenSize = ScreenInfo.GetScreenSize(); float screenRate = ScreenInfo.GetScreenRate(); float screenCorrectY = ScreenInfo.GetScreenCorrectY(); float num1 = (float)(720.0 * (double)screenRate / screenSize.y); int num2 = capW; int num3 = capH; int num4 = (int)((double)num2 * (double)renderRate); int num5 = (int)((double)num3 * (double)renderRate); RenderTexture renderTexture = QualitySettings.get_antiAliasing() != 0 ? RenderTexture.GetTemporary((int)(1280.0 * (double)renderRate / (double)num1), (int)(720.0 * (double)renderRate / (double)num1), 24, (RenderTextureFormat)0, (RenderTextureReadWrite)0, QualitySettings.get_antiAliasing()) : RenderTexture.GetTemporary((int)(1280.0 * (double)renderRate / (double)num1), (int)(720.0 * (double)renderRate / (double)num1), 24); if (drawBackSp && Object.op_Inequality((Object)null, (Object)gameObjectWithTag)) { GameObject loop = gameObjectWithTag.get_transform().FindLoop("BackSpCam"); if (Object.op_Inequality((Object)null, (Object)loop)) { Camera component = (Camera)loop.GetComponent <Camera>(); if (Object.op_Inequality((Object)null, (Object)component)) { component.set_targetTexture(renderTexture); component.Render(); component.set_targetTexture((RenderTexture)null); } } } if (Object.op_Inequality((Object)null, (Object)Camera.get_main())) { Camera main = Camera.get_main(); RenderTexture targetTexture = main.get_targetTexture(); Rect rect = main.get_rect(); main.set_targetTexture(renderTexture); main.Render(); main.set_targetTexture(targetTexture); main.set_rect(rect); } if (drawFrontSp && Object.op_Inequality((Object)null, (Object)gameObjectWithTag)) { GameObject loop = gameObjectWithTag.get_transform().FindLoop("FrontSpCam"); if (Object.op_Inequality((Object)null, (Object)loop)) { Camera component = (Camera)loop.GetComponent <Camera>(); if (Object.op_Inequality((Object)null, (Object)component)) { component.set_targetTexture(renderTexture); component.Render(); component.set_targetTexture((RenderTexture)null); } } } Texture2D tex = new Texture2D(num4, num5, (TextureFormat)5, false, true); RenderTexture.set_active(renderTexture); float num6 = (float)((double)(1280 - capW) / 2.0 * (double)renderRate + (1280.0 / (double)num1 - 1280.0) * 0.5 * (double)renderRate); float num7 = (float)((double)(720 - capH) / 2.0 * (double)renderRate + (double)screenCorrectY / (double)screenRate * (double)renderRate); tex.ReadPixels(new Rect(num6, num7, (float)num4, (float)num5), 0, 0); tex.Apply(); RenderTexture.set_active((RenderTexture)null); RenderTexture.ReleaseTemporary(renderTexture); if (num4 != createW || num5 != createH) { TextureScale.Bilinear(tex, createW, createH); } pngData = ImageConversion.EncodeToPNG(tex); Object.Destroy((Object)tex); }