unity 资源路径生成缩略图
时间: 2023-08-04 07:15:37 浏览: 54
在 Unity 中,可以通过以下代码生成缩略图:
```csharp
using UnityEngine;
using UnityEditor;
public class GenerateThumbnail : EditorWindow
{
[MenuItem("Assets/Generate Thumbnail")]
static void Init()
{
Texture2D texture = AssetPreview.GetAssetPreview(Selection.activeObject);
if (texture != null)
{
string path = AssetDatabase.GetAssetPath(Selection.activeObject);
string thumbnailPath = path.Replace(".prefab", "Thumbnail.png");
byte[] bytes = texture.EncodeToPNG();
System.IO.File.WriteAllBytes(thumbnailPath, bytes);
AssetDatabase.Refresh();
Debug.Log("Thumbnail generated at " + thumbnailPath);
}
else
{
Debug.Log("Selected object is not a valid asset.");
}
}
}
```
这段代码可以在 Unity Editor 中创建一个菜单,点击菜单可以生成当前选中对象的缩略图,并保存为 PNG 格式的文件。你只需要将该脚本保存到 Unity 项目中,然后在 Assets 菜单中找到 Generate Thumbnail 菜单项即可使用。