mirror of
https://github.com/RHeavenStudioPlus/HeavenStudioPlus.git
synced 2024-12-03 23:07:30 +00:00
29 lines
1.1 KiB
C#
29 lines
1.1 KiB
C#
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.UI;
|
||
|
|
||
|
public class BackgroundManager : MonoBehaviour
|
||
|
{
|
||
|
public ScreenCaptureManager screenCaptureManager;
|
||
|
public ImageEffectController imageEffectController;
|
||
|
public RawImage backgroundImage;
|
||
|
public void CaptureAndSetBackground()
|
||
|
{
|
||
|
Texture2D capturedScreen = screenCaptureManager.CaptureScreen();
|
||
|
RenderTexture rt = RenderTexture.GetTemporary(capturedScreen.width,
|
||
|
capturedScreen.height);
|
||
|
Graphics.Blit(capturedScreen, rt, imageEffectController.effectMaterial);
|
||
|
Texture2D processedTexture = new Texture2D(capturedScreen.width,
|
||
|
capturedScreen.height, TextureFormat.RGB24, false);
|
||
|
RenderTexture.active = rt;
|
||
|
processedTexture.ReadPixels(new Rect(0, 0, capturedScreen.width,
|
||
|
capturedScreen.height), 0, 0);
|
||
|
processedTexture.Apply();
|
||
|
RenderTexture.active = null;
|
||
|
backgroundImage.texture = processedTexture;
|
||
|
RenderTexture.ReleaseTemporary(rt);
|
||
|
}
|
||
|
}
|
||
|
|