Repository URL to install this package:
Version:
2025.1.5 ▾
|
using UnityEngine;
namespace Gs2.Editor.ResourceTree.Core
{
public static class TextureExt
{
public static Texture2D ToTexture2D(this Texture self) {
var sw = self.width;
var sh = self.height;
var format = TextureFormat.RGBA32;
var result = new Texture2D(sw, sh, format, false);
var currentRT = RenderTexture.active;
var rt = new RenderTexture(sw, sh, 32);
Graphics.Blit(self, rt);
RenderTexture.active = rt;
var source = new Rect(0, 0, rt.width, rt.height);
result.ReadPixels(source, 0, 0);
result.Apply();
RenderTexture.active = currentRT;
return result;
}
}
}