通过脚本将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 @ 2023-02-02 08:20  old_Host  阅读(145)  评论(1编辑  收藏  举报