Unity预制体(prefab)生成png格式的缩略图

预制体名字为ObjectPrefab,生成的图片为SavedScreen.png,保存在Asset文件夹下。

  • 导入UnityEditor 和 System.IO包。
  • 将ObjectPrefab预制体放在Assets 下的Resources 文件夹下。
//using UnityEditor;
//using System.IO;
GameObject prefab = Resources.Load<GameObject>("ObjectPrefab");
Texture2D Tex = AssetPreview.GetAssetPreview(prefab);
// Encode texture into PNG
byte[] bytes = Tex.EncodeToPNG();
File.WriteAllBytes(Application.dataPath + "/../Assets/SavedScreen.png", bytes);

猜你喜欢

转载自blog.csdn.net/kaixinjiaoluo/article/details/124486651
今日推荐