Files
UltimateFishing2020/Assets/Scripts/Assembly-CSharp/AQUAS/AQUAS_CaptureBackground.cs
2026-03-04 10:03:45 +08:00

69 lines
1.4 KiB
C#

using UnityEngine;
namespace AQUAS
{
public class AQUAS_CaptureBackground : MonoBehaviour
{
public GameObject waterObj;
public RenderTexture target;
private Camera cam;
public int quality = 2;
public LayerMask layerMask = -1;
private void Start()
{
int num = (int)Mathf.Pow(2f, quality);
target = new RenderTexture(Screen.width / num, Screen.height / num, 32, RenderTextureFormat.ARGBHalf);
cam = GetComponent<Camera>();
cam.targetTexture = target;
cam.pixelRect = new Rect(0f, 0f, Screen.width / num, Screen.height / num);
}
private void OnPreCull()
{
if (!(waterObj == null))
{
cam.cullingMask = layerMask;
cam.cullingMask &= ~(1 << LayerMask.NameToLayer("Water"));
waterObj.layer = LayerMask.NameToLayer("Water");
}
}
private void OnPostRender()
{
if (!(waterObj == null))
{
waterObj.layer = LayerMask.NameToLayer("Default");
}
}
private void Update()
{
if (target.width != Screen.width || target.height != Screen.height)
{
target.Release();
target.width = Screen.width;
target.height = Screen.height;
}
}
private void OnRenderImage(RenderTexture source, RenderTexture destination)
{
Graphics.Blit(source, destination);
if (waterObj != null)
{
waterObj.GetComponent<Renderer>().sharedMaterials[1].SetTexture("_BackgroundTex", target);
target.Release();
}
else
{
target.Release();
}
}
}
}