通过脚本将unity3D模型转出图片

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

public class ChangeToTexture : MonoBehaviour
{

//这里是要导出模型的数组
public GameObject[] prefabs;
// Start is called before the first frame update
void Start()
{

//循环数组
for (int i = 0; i < prefabs.Length; i++)
{

//通过unity编辑器模式下的集脏方法
EditorUtility.SetDirty(prefabs[i]);

//导出图片  类型为texture2D
Texture2D image = AssetPreview.GetAssetPreview(prefabs[i]);

//通过io将图片写入到指定路径中【这里需要注意路径的拼接+后缀】
System.IO.File.WriteAllBytes(Application.dataPath + "/Resources/Icon/" + prefabs[i].name + ".png", image.EncodeToPNG());
}
}
}

posted @   old_Host  阅读(249)  评论(1编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示