是否有可能生成3D字符/物体的二维化身肖像图片(.png),这是可取的。
在我的游戏中,我想动态地生成和显示滚动条UI组件中的字符/对象列表,而且我太懒了,以至于无法手动生成这些2D图像。
我想知道是否可以从一组3D预制板中生成一个字符/对象肖像列表来显示,或者更可取的做法是手动生成图片并将图片添加到as资产中。
这样,除了懒惰之外,向我的项目中添加字符/对象并在更改它们时维护它们也要容易得多。
发布于 2018-07-31 15:34:57
你可以用这样的脚本来拍一张场景的照片。所以你可以在某个地方实例化游戏对象,有一个特定的方向,背景,照明,距离相机.然后你拿着屏幕截图,把它和你的其他资产放在一起。
using UnityEngine;
using System.Collections;
public class HiResScreenShots : MonoBehaviour {
public int resWidth = 2550;
public int resHeight = 3300;
private bool takeHiResShot = false;
public static string ScreenShotName(int width, int height) {
return string.Format("{0}/screenshots/screen_{1}x{2}_{3}.png",
Application.dataPath,
width, height,
System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"));
}
public void TakeHiResShot() {
takeHiResShot = true;
}
void LateUpdate() {
takeHiResShot |= Input.GetKeyDown("k");
if (takeHiResShot) {
RenderTexture rt = new RenderTexture(resWidth, resHeight, 24);
camera.targetTexture = rt;
Texture2D screenShot = new Texture2D(resWidth, resHeight, TextureFormat.RGB24, false);
camera.Render();
RenderTexture.active = rt;
screenShot.ReadPixels(new Rect(0, 0, resWidth, resHeight), 0, 0);
camera.targetTexture = null;
RenderTexture.active = null; // JC: added to avoid errors
Destroy(rt);
byte[] bytes = screenShot.EncodeToPNG();
string filename = ScreenShotName(resWidth, resHeight);
System.IO.File.WriteAllBytes(filename, bytes);
Debug.Log(string.Format("Took screenshot to: {0}", filename));
takeHiResShot = false;
}
}
}https://stackoverflow.com/questions/51616753
复制相似问题