Files
Main/Assets/Plugins/References/FuncellBase/UnityUtils/RenderTextureUtils.cs
2025-01-25 04:38:09 +08:00

76 lines
2.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
namespace Thousandto.Core.Base
{
//RenderTexture处理的类
public class RenderTextureUtils
{
//创建纹理 -- 按照比例来进行
public static RenderTexture CreateTextureBaseScale(float scale, int d, RenderTextureFormat format)
{
int w = (int)Math.Round(Screen.width * scale);
int h = (int)Math.Round(Screen.height * scale);
return CreateTexture(w, h, d, format);
}
//创建纹理 -- 按照高度来进行
public static RenderTexture CreateTextureBaseHeight(int h, int d, RenderTextureFormat format)
{
int w = (int)Math.Round(Screen.width * ((float)h / (float)Screen.height));
return CreateTexture(w, h, d, format);
}
//创建RenderTexture纹理
public static RenderTexture CreateTexture(int w, int h, int d, RenderTextureFormat format)
{
if (GetSuppertFormat(ref format))
{
return RenderTexture.GetTemporary(w, h, d, format);
}
return null;
}
//释放RenderTextureTexture
public static void ReleaseTexture(RenderTexture tex)
{
if (tex != null)
{
RenderTexture.ReleaseTemporary(tex);
}
}
//获取当前支持的格式
public static bool GetSuppertFormat(ref RenderTextureFormat format)
{
if (SystemInfo.SupportsRenderTextureFormat(format))
{
return true;
}
else if (SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.RGB565))
{
format = RenderTextureFormat.RGB565;
}
else if (SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGB4444))
{
format = RenderTextureFormat.ARGB4444;
}
else if (SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGB1555))
{
format = RenderTextureFormat.ARGB1555;
}
else if (SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGB32))
{
format = RenderTextureFormat.ARGB32;
}
else
{
return false;
}
return true;
}
}
}