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());
}
}
}