问题
使用 MonoDevelop 编辑代码时出现了错误:
Error CS01013: The name ‘UnityEngine’ does not exist in the current context.

找不到 UnityEngine 类库,所有相关方法都标红显示错误,但是 Unity 编辑器可以正常编译运行。
原因
自行编辑过项目的代码格式: Project > Assembly-CSharp options > Source Code > Code Formatting,导致 Assembly-CSharp.csproj 文件被插入了配置代码:
1 2 3 4 5 6 7 8 9 10
| <ProjectExtensions xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <MonoDevelop> <Properties> <Policies> <TextStylePolicy inheritsSet="null" scope="text/x-csharp"/> <CSharpFormattingPolicy NamespaceBraceStyle="EndOfLine" ClassBraceStyle="EndOfLine" InterfaceBraceStyle="EndOfLine" StructBraceStyle="EndOfLine" EnumBraceStyle="EndOfLine" MethodBraceStyle="EndOfLine" ConstructorBraceStyle="EndOfLine" DestructorBraceStyle="EndOfLine" BeforeMethodDeclarationParentheses="False" BeforeMethodCallParentheses="False" BeforeConstructorDeclarationParentheses="False" BeforeIndexerDeclarationBracket="False" BeforeDelegateDeclarationParentheses="False" AfterDelegateDeclarationParameterComma="True" NewParentheses="False" SpacesBeforeBrackets="False" inheritsSet="Mono" inheritsScope="text/x-csharp" scope="text/x-csharp"/> </Policies> </Properties> </MonoDevelop> </ProjectExtensions>
|
解决
删除 Assembly-CSharp.csproj 文件,重新在 Unity 编辑器中打开代码文件,生成新的项目文件。
- 注意,修改配置需要操作的是项目根节点的配置,而不是 Assembly-CSharp 或 Assembly-CSharp-Editor 项目的配置。