using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
using System.IO;
///
/// pass
///
public class UIToTextureExporter : MonoBehaviour
{
public RectTransform targetUIRoot;
public Vector2Int outputResolution = new Vector2Int(1024, 1024);
public string fileName = "UIRender";
public string saveFolder = "Exports";
[ContextMenu("导出 UI 图像")]
public void ExportUI()
{
if (targetUIRoot == null)
{
Debug.LogError("请指定 UI 根节点!");
return;
}
// 创建RenderTexture
RenderTexture rt = new RenderTexture(outputResolution.x, outputResolution.y, 24);
RenderTexture.active = rt;
// 清空背景
GL.Clear(true, true, new Color(0, 0, 0, 0));
// 创建一个临时Canvas进行渲染
GameObject tempCanvasGO = new GameObject("TempCanvas", typeof(Canvas));
Canvas tempCanvas = tempCanvasGO.GetComponent