Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 错误CS0103:名称';资产审查';在当前上下文中不存在_C#_Unity3d - Fatal编程技术网

C# 错误CS0103:名称';资产审查';在当前上下文中不存在

C# 错误CS0103:名称';资产审查';在当前上下文中不存在,c#,unity3d,C#,Unity3d,在我的Unity项目中,我使用C#代码来获取png格式的预制预览图像 在Unity播放模式下,我对这个脚本和一切都没有错误,但当我尝试构建我的项目时,我收到了错误 我花了很多时间试图理解我在哪里犯了错误,但没有结果 有人能帮助解决这个问题吗 C#脚本 使用系统集合; 使用System.Collections.Generic; 使用UnityEngine; 使用UnityEngine.UI; 使用System.IO; 使用制度; 公共类LoadTexture:单行为 { [系统可序列化] 公共类L

在我的Unity项目中,我使用C#代码来获取png格式的预制预览图像

在Unity播放模式下,我对这个脚本和一切都没有错误,但当我尝试构建我的项目时,我收到了错误

我花了很多时间试图理解我在哪里犯了错误,但没有结果

有人能帮助解决这个问题吗

C#脚本

使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
使用UnityEngine.UI;
使用System.IO;
使用制度;
公共类LoadTexture:单行为
{
[系统可序列化]
公共类LoadTex
{
公共字符串名称;
公共游戏对象纹理;
公共纹理2D gameObjectTex;
公共纹理gameObjTex;
}
public List ItemTablezz=新列表();
//在第一帧更新之前调用Start
void Start()
{
for(int i=0;i
错误CS0103:当前上下文中不存在名称“AssetPreview”


我犯错误的地方?

UnityEditor。AssetPreview
属于
UnityEditor
命名空间

这只存在于Unity编辑器istelf中,并在构建中删除

=>在生成中不能使用
UnityEditor
命名空间中的任何内容


为了从构建中排除
UnityEditor
内容,基本上有两种解决方案:

预处理器 在c#中,可以使用,以便根据全局定义排除代码块。团结提供了这样的机会。在这种情况下,使用例如

#if UNITY_EDITOR
    // CODE USING UnityEditor
#endif
编辑器
文件夹 如果要从构建中排除整个脚本,只需将其放在名为的文件夹中即可。这将使它完全从构建中剥离


要在构建中使用此脚本,您必须使用另一个库或在Unity Editor中运行此脚本一次,并存储这些引用以在构建中使用它们,例如使用属性:

    void Start()
    {
#if UNITY_EDITOR
        LoadPreviewImages();
#endif

        // if nothing more comes here
        // rather remove this method entirely
        ...
    }

#if UNITY_EDITOR
    // This allows you to call this method 
    // from the according components context menu in the Inspector
    [ContextMenu("LoadPreviewImages")]
    private void LoadPreviewImages()
    {
        foreach (var loadText in ItemTablezz)
        {
            var getImage = UnityEditor.AssetPreview.GetAssetPreview(loadText.texture);
            print(getImage);
            loadText.gameObjectTex = getImage;
        }
    }
#endif

我稍后会尝试您的解决方案并反馈
    void Start()
    {
#if UNITY_EDITOR
        LoadPreviewImages();
#endif

        // if nothing more comes here
        // rather remove this method entirely
        ...
    }

#if UNITY_EDITOR
    // This allows you to call this method 
    // from the according components context menu in the Inspector
    [ContextMenu("LoadPreviewImages")]
    private void LoadPreviewImages()
    {
        foreach (var loadText in ItemTablezz)
        {
            var getImage = UnityEditor.AssetPreview.GetAssetPreview(loadText.texture);
            print(getImage);
            loadText.gameObjectTex = getImage;
        }
    }
#endif