我们首先找到要生成的对象因为是prefab 预制体的格式 我们要进行一个转换
我们看一下代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor; //引入编辑器
public class DrawDao : 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 img = AssetPreview.GetAssetPreview(prefabs[i]);//返回资源的预览纹理。
System.IO.File.WriteAllBytes(Application.dataPath+"/Resources/Image/xx_" + i + ".png",img.EncodeToPNG());//将该纹理编码为 PNG 格式
}
//刷新数据
AssetDatabase.Refresh();
}
// Update is called once per frame
void Update()
{
}
}
我们有一个问题 UnityEditor 是不能打包的 我们必须放在这个文件夹中
我们可以先把自己需要的资源的图片生成 后放入 因为我们要运行
扩展----
我们要进行换个角度
首先创立一个父节点去进行旋转就行