fxies
This commit is contained in:
@@ -26,9 +26,6 @@ namespace Darkmatter.Services.Capture
|
||||
int sw = Screen.width;
|
||||
int sh = Screen.height;
|
||||
|
||||
var disabledCanvases = DisableOtherRootCanvases(paperCanvas);
|
||||
var disabledGraphics = HideNonPaperGraphics(paperRT);
|
||||
|
||||
Rect crop = ComputeCropRect(captureObject, sw, sh);
|
||||
int cropW = Mathf.Max(1, (int)crop.width);
|
||||
int cropH = Mathf.Max(1, (int)crop.height);
|
||||
@@ -36,22 +33,30 @@ namespace Darkmatter.Services.Capture
|
||||
var prevFlags = cam.clearFlags;
|
||||
var prevBg = cam.backgroundColor;
|
||||
var prevTarget = cam.targetTexture;
|
||||
cam.clearFlags = CameraClearFlags.SolidColor;
|
||||
cam.backgroundColor = new Color(0f, 0f, 0f, 0f);
|
||||
|
||||
var rt = RenderTexture.GetTemporary(sw, sh, 24, RenderTextureFormat.ARGB32);
|
||||
cam.targetTexture = rt;
|
||||
|
||||
var prevMode = paperCanvas.renderMode;
|
||||
var prevWorldCam = paperCanvas.worldCamera;
|
||||
var prevPlaneDist = paperCanvas.planeDistance;
|
||||
paperCanvas.renderMode = RenderMode.ScreenSpaceCamera;
|
||||
paperCanvas.worldCamera = cam;
|
||||
paperCanvas.planeDistance = Mathf.Max(0.5f, (cam.nearClipPlane + cam.farClipPlane) * 0.5f);
|
||||
|
||||
List<Canvas> disabledCanvases = null;
|
||||
List<UnityEngine.UI.Graphic> disabledGraphics = null;
|
||||
|
||||
try
|
||||
{
|
||||
await UniTask.WaitForEndOfFrame(cancellationToken);
|
||||
|
||||
disabledCanvases = DisableOtherRootCanvases(paperCanvas);
|
||||
disabledGraphics = HideNonPaperGraphics(paperRT);
|
||||
|
||||
cam.clearFlags = CameraClearFlags.SolidColor;
|
||||
cam.backgroundColor = new Color(0f, 0f, 0f, 0f);
|
||||
cam.targetTexture = rt;
|
||||
|
||||
paperCanvas.renderMode = RenderMode.ScreenSpaceCamera;
|
||||
paperCanvas.worldCamera = cam;
|
||||
paperCanvas.planeDistance = Mathf.Max(0.5f, (cam.nearClipPlane + cam.farClipPlane) * 0.5f);
|
||||
|
||||
Canvas.ForceUpdateCanvases();
|
||||
cam.Render();
|
||||
|
||||
@@ -104,12 +109,14 @@ namespace Darkmatter.Services.Capture
|
||||
cam.clearFlags = prevFlags;
|
||||
cam.backgroundColor = prevBg;
|
||||
RenderTexture.ReleaseTemporary(rt);
|
||||
foreach (var g in disabledGraphics)
|
||||
if (g != null)
|
||||
g.enabled = true;
|
||||
foreach (var c in disabledCanvases)
|
||||
if (c != null)
|
||||
c.enabled = true;
|
||||
if (disabledGraphics != null)
|
||||
foreach (var g in disabledGraphics)
|
||||
if (g != null)
|
||||
g.enabled = true;
|
||||
if (disabledCanvases != null)
|
||||
foreach (var c in disabledCanvases)
|
||||
if (c != null)
|
||||
c.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,10 +173,12 @@ namespace Darkmatter.Services.Capture
|
||||
|
||||
private static Texture2D Resize(Texture2D src, int width, int height)
|
||||
{
|
||||
var rt = RenderTexture.GetTemporary(width, height);
|
||||
var rt = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
|
||||
var prev = RenderTexture.active;
|
||||
try
|
||||
{
|
||||
RenderTexture.active = rt;
|
||||
GL.Clear(false, true, new Color(0f, 0f, 0f, 0f));
|
||||
Graphics.Blit(src, rt);
|
||||
RenderTexture.active = rt;
|
||||
var dst = new Texture2D(width, height, TextureFormat.RGBA32, mipChain: false);
|
||||
|
||||
Reference in New Issue
Block a user