报错内容:error CS0246: The type or namespace name 'XXX' could not be found (are you missing a using directive or an assembly reference?)
(1)报错场景:
测试Unity打包AssetBundle的API,部分代码如下:
```
[MenuItem("Game/StartBuild")]
static void StartBuild()
{
StartBuildMenu();
}
public static void StartBuildMenu()
{
var buildList = new List<AssetBundleBuild>();
var assetPath = AssetsDir;
if (Directory.Exists(assetPath))
{
// 1.取得所有需要打包的资源
DirectoryInfo di = new DirectoryInfo(assetPath);
var filters = fileFilter.Split('|');
var files = filters.SelectMany(filterChar =>
{
var ret = di.GetFiles(filterChar, SearchOption.AllDirectories);
return ret;
}).ToList();
// var assetPaths = fileFilter.Split('|').SelectMany(filterChar =>
// di.GetFiles(filterChar, SearchOption.AllDirectories)).ToArray();
// 2.创建打包对象
foreach (var file in files)
{
AssetBundleBuild build = new AssetBundleBuild();
build.assetBundleName = GetFileAbName(file.FullName);
var start = file.FullName.IndexOf("Assets");
var assetName = file.FullName.Substring(start);
build.assetNames = new string[] {assetName};
buildList.Add(build);
}
if (!Directory.Exists(ABSaveDir))
Directory.CreateDirectory(ABSaveDir);
BuildPipeline.BuildAssetBundles(ABSaveDir, buildList.ToArray(), BuildAssetBundleOptions.None, BuildTarget.Android);
}
}
```
执行StartBuildMenu后报错:
error CS0246: The type or namespace name 'MenuItemAttribute' could not be found (are you missing a using directive or an assembly reference?)
error CS0246: The type or namespace name 'MenuItem' could not be found (are you missing a using directive or an assembly reference?)
error CS0246: The type or namespace name 'AssetBundleBuild' could not be found (are you missing a using directive or an assembly reference?)
error CS0246: The type or namespace name 'BuildAssetBundleOptions' could not be found (are you missing a using directive or an assembly reference?)
(2)解析错误日志:
报错都是提示缺少 using 指令或程序集引用,并且发现缺少引用的都是UnityEditor下的类型
(3)解决办法:
在unity中所有使用UnityEditor命名空间的脚本,必须放到Assets目录下的Editor文件夹中,这个Editor文件夹可以直接放到Assets目录下的任何地方,只要名字是Editor就可以。
本文发布于:2024-01-31 03:53:20,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170664439925214.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |