'error CS0103: The name 'AssetPreview' does not exist in the current context
In my Unity Project I've C# code to get Prefabs preview image in png format.
In Unity Play mode I have not errors with this Script and everything it's ok, but when I trie to build my project I've receive error.
I spend a lot of times to try understand where I'd made a mistake, but no result.
Can some body help with this problem?
C# Script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.IO;
using System;
public class LoadTexture : MonoBehaviour
{
[System.Serializable]
public class LoadTex
{
public string name;
public GameObject texture;
public Texture2D gameObjectTex;
public Texture gameObjTex;
}
public List<LoadTex> ItemTablezz = new List<LoadTex>();
// Start is called before the first frame update
void Start()
{
for (int i = 0; i < ItemTablezz.Count; i++)
{
var getImage = UnityEditor.AssetPreview.GetAssetPreview(ItemTablezz[i].texture);
print(getImage);
ItemTablezz[i].gameObjectTex = getImage;
}
}
// Update is called once per frame
void Update()
{
CheckIfNull();
}
void CheckIfNull()
{
for (int k = 0; k < ItemTablezz.Count; k++)
{
Texture2D tex = new Texture2D(128, 128, TextureFormat.RGBA32, false);
Color[] colors = ItemTablezz[k].gameObjectTex.GetPixels();
int i = 0;
Color alpha = colors[i];
for (; i < colors.Length; i++)
{
if (colors[i] == alpha)
{
colors[i].a = 0;
}
}
tex.SetPixels(colors);
tex.Apply();
byte[] png = tex.EncodeToPNG();
File.WriteAllBytes(Application.persistentDataPath + "/" + ItemTablezz[k].name + ".png", png);
}
}
}
error CS0103: The name 'AssetPreview' does not exist in the current context
Where I'd made mistake?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
