通过代码使用预制体生成图片

 

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


public class HuangZhuShou : MonoBehaviour
{
//通过此代码可以使预制体生成图片
public GameObject[] prefabs;//需要装换成图片的预制体集合
// Start is called before the first frame update
void Start()
{
for (int i = 0; i < prefabs.Length; i++)
{
EditorUtility.SetDirty(prefabs[i]);
Texture2D image = AssetPreview.GetAssetPreview(prefabs[i]);
System.IO.File.WriteAllBytes(Application.dataPath + "/Resources/Image/image_" + i + ".png", image.EncodeToPNG());
}
}
}

posted @ 2023-02-02 08:58  陈晨111  阅读(52)  评论(0)    收藏  举报