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