Update screenshot transparency for Unity 2022

This commit is contained in:
katboi01
2025-01-31 10:30:46 +01:00
parent 8eadd54906
commit 45a17176be
5 changed files with 1454 additions and 10 deletions
+3 -7
View File
@@ -77,7 +77,7 @@ public class Screenshot : MonoBehaviour
UmaViewerUI.Instance.GifSlider.value = (float)frame / clipFrameCount;
UmaViewerUI.Instance.AnimationProgressChange((float)frame / clipFrameCount);
yield return new WaitForEndOfFrame();
var tex = GrabFrame(camera, width, height, transparent, transparent);
var tex = GrabFrame(camera, width, height, transparent);
CaptureToGIFCustom.Instance.Frames.Add(new Image(tex));
Destroy(tex);
frame++;
@@ -92,7 +92,7 @@ public class Screenshot : MonoBehaviour
UmaViewerUI.Instance.GifSlider.value = 1;
}
public static Texture2D GrabFrame(Camera cam, int width, int height, bool transparent = true, bool gifBackground = false)
public static Texture2D GrabFrame(Camera cam, int width, int height, bool transparent = true)
{
var dimensions = GetResolution(width, height);
width = dimensions.x;
@@ -103,15 +103,11 @@ public class Screenshot : MonoBehaviour
Color oldBG = cam.backgroundColor;
cam.cullingMask = ~LayerMask.GetMask("UI");
if (gifBackground)
if (transparent)
{
cam.clearFlags = CameraClearFlags.SolidColor;
cam.backgroundColor = new Color32(0, 0, 0, 0);
}
else if (transparent)
{
cam.clearFlags = CameraClearFlags.Depth;
}
var tex_color = new Texture2D(width, height, TextureFormat.ARGB32, false);
int aaLevel = QualitySettings.antiAliasing == 0? 1 : QualitySettings.antiAliasing; //RT uses '1' for no antialiasing