Unity是一款跨平台的游戏开发引擎,可以用于开发2D和3D游戏。在Unity中,可以通过以下步骤获得蒙版纹理并另存为png:
using UnityEngine;
public class CaptureTexture : MonoBehaviour
{
public RenderTexture renderTexture;
private void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
Texture2D texture = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.RGB24, false);
RenderTexture.active = renderTexture;
texture.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
texture.Apply();
byte[] bytes = texture.EncodeToPNG();
System.IO.File.WriteAllBytes(Application.dataPath + "/captured_texture.png", bytes);
RenderTexture.active = null;
Destroy(texture);
}
}
}
完成以上步骤后,你将能够通过按下空格键来获取蒙版纹理并保存为png文件。
领取专属 10元无门槛券
手把手带您无忧上云