【发布时间】:2018-07-31 15:15:58
【问题描述】:
是否可以统一生成3D人物/物体的2D头像图片(.png),是否可取。
在我的游戏过程中,我想在滚动条 UI 组件中动态生成并显示角色/对象列表,我懒得真正手动制作这些 2D 图像。
我想知道是否可以从一组 3D 预制件中生成角色/对象肖像列表以进行显示,或者是否更建议手动生成图片和将图片添加到 as assets。
除了懒惰之外,这也将更容易将字符/对象添加到我的项目并在更改时维护它们。
【问题讨论】:
是否可以统一生成3D人物/物体的2D头像图片(.png),是否可取。
在我的游戏过程中,我想在滚动条 UI 组件中动态生成并显示角色/对象列表,我懒得真正手动制作这些 2D 图像。
我想知道是否可以从一组 3D 预制件中生成角色/对象肖像列表以进行显示,或者是否更建议手动生成图片和将图片添加到 as assets。
除了懒惰之外,这也将更容易将字符/对象添加到我的项目并在更改时维护它们。
【问题讨论】:
您可以使用这样的脚本来拍摄场景照片。因此,您可以在某处实例化游戏对象,具有特定的方向、背景、照明、到相机的距离……然后您截取屏幕截图并将其与您的其他资产一起存储在某个地方。
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;
}
}
}
【讨论】: