主要思路: 利用RenderTexture
效果:
场景 添加一个 渲染RenderTeture的摄像机 添加一个画布(背景、字体)
资源 新建RenderTexture 新建一个材质 材质引用贴图RenderTexture
修改Text的值 材质贴到模型上 此时已经能直接看到效果了
如何保存?
public string str;
public RenderTexture m_RenderTexture;
private void _SaveRenderTexture(RenderTexture renderTexture)
{
RenderTexture active = RenderTexture.active;
RenderTexture.active = renderTexture;
Texture2D outImage = new Texture2D(renderTexture.width, renderTexture.height,
TextureFormat.ARGB32, false);
outImage.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
outImage.Apply();
RenderTexture.active = active;
byte[] bytes = outImage.EncodeToPNG();
string path = string.Format("Assets/MyImg/{0}.png", str);
FileStream fileStream = File.Open(path, FileMode.Create);
BinaryWriter writer = new BinaryWriter(fileStream);
writer.Write(bytes);
writer.Flush();
writer.Close();
fileStream.Close();
Destroy(outImage);
outImage = null;
Debug.Log("保存成功!" + path);
}



