从 Git 拉取项目后,Unity 无法识别一些 .cs 文件。

7
我目前正在使用Unity 2020.3.3f1开发一个项目。我使用git版本控制系统,并将我的项目存储在Bitbucket仓库中。当我克隆/拉取我的项目到另一台计算机(特别是macOS)时,我的一些cs文件在项目视图中显示为未知文件(不是脚本),而其他一些类无法找到该文件中定义的类。当我右键单击并选择“重新导入”cs文件时,它会立即恢复,并且我可以成功构建。
这会在我尝试通过Unity Cloud构建项目时造成问题,因为我会收到一些缺少的类的错误提示,而它们实际上是存在的。
[Unity] Initialize engine version: 2020.3.6f1 (338bb68529b2)
3: [Unity] -----CompilerOutput:-stdout--exitcode: 1--compilationhadfailure: True--outfile: Temp/ToonyColorsPro.Editor.dll
4: [Unity] Assets/JMO Assets/Toony Colors Pro/Editor/Shader Generator/Config.cs(192,13): error CS0246: The type or namespace name 'MaterialLayer' could not be found (are you missing a using directive or an assembly reference?)
5: [Unity] Assets/JMO Assets/Toony Colors Pro/Editor/Shader Generator/ShaderProperty.cs(417,40): error CS0246: The type or namespace name 'MaterialLayer' could not be found (are you missing a using directive or an assembly reference?)
6: [Unity] Assets/JMO Assets/Toony Colors Pro/Editor/Shader Generator/Config.cs(173,59): error CS0246: The type or namespace name 'MaterialLayer' could not be found (are you missing a using directive or an assembly reference?)
7: [Unity] Assets/JMO Assets/Toony Colors Pro/Editor/Shader Generator/Config.cs(192,13): error CS0246: The type or namespace name 'MaterialLayer' could not be found (are you missing a using directive or an assembly reference?)
8: [Unity] Assets/JMO Assets/Toony Colors Pro/Editor/Shader Generator/ShaderProperty.cs(417,40): error CS0246: The type or namespace name 'MaterialLayer' could not be found (are you missing a using directive or an assembly reference?)
9: [Unity] Assets/JMO Assets/Toony Colors Pro/Editor/Shader Generator/Config.cs(173,59): error CS0246: The type or namespace name 'MaterialLayer' could not be found (are you missing a using directive or an assembly reference?)
10: ! build of 'default-ios-ad-hoc' failed. exit
11: publishing finished successfully.
12: Finished: FAILURE

之后我试图从一台 Mac 设备上拉取工程,但工程也无法识别相同的 MaterialLayer.cs 文件。我使用“重新导入”轻松恢复了它。 我的项目设置 / 资产序列化:强制文本和“版本控制 / 可见元文件”已经设置。


4
请确保Unity为每个文件生成的相应".meta"文件已上传到仓库。只是为了给您一个可以检查是否有序的想法... - rustyBucketBay
2个回答

3

这可能是一种不太可能的解决方案,我只回答你因为我可以在这里附加图片:

C#解决方案中的每个文件都有属性:

输入图像描述

所以我的建议是双重检查那些“缺失”的,被识别错误的.cs文件是否具有与那些被正确识别的.cs文件相同的属性设置。


1
如果你在git上使用LFS,在拉取文件时,有时会出现这个问题,可能是由于LFS被拉取时出现了错误或元文件在拉取过程中被损坏,请仔细检查你的.gitattributes。可能是.meta的合并选项被错误地分配了。我在我的项目中使用this .gitattributes,仍然没有出现任何问题。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接