当我尝试构建我的项目时,Unity 出现奇怪的错误

问题描述

当我尝试构建我的项目时,出于某种原因,Unity 给了我这些奇怪的错误。我不知道为什么它给了我这些错误,而它们应该早点给出。我尝试重新启动统一,删除插件文件夹,删除 .sln 文件并将构建文件夹放在不同的文件夹中。我该如何修复这些奇怪的错误

这里的代码统一性不断给我错误,如果有帮助的话: https://paste.myst.rs/lwj5nsm1

这是 unity 给我的错误

Assets\LevelGenerator\Scripts\Editor\LevelEditor.cs(9,30): 错误 CS0115: 'GeneratorEditor.OnInspectorGUI()': 找不到合适的方法来覆盖

Assets\LevelGenerator\Scripts\Editor\LevelEditor.cs(7,48):错误 CS0234:命名空间“UnityEditor”中不存在类型或命名空间名称“Editor”(您是否缺少程序集引用?)

Assets\LevelGenerator\Scripts\Editor\LevelEditor.cs(6,6):错误 CS0246:找不到类型或命名空间名称“CustomEditorAttribute”(您是否缺少 using 指令或程序集引用?)>

Assets\LevelGenerator\Scripts\Editor\LevelEditor.cs(6,6):错误 CS0246:找不到类型或命名空间名称“CustomEditor”(您是否缺少 using 指令或程序集引用?)>

UnityEditor.BuildplayerWindow+BuildMethodException: 5 个错误 在 UnityEditor.BuildplayerWindow+DefaultBuildMethods.Buildplayer(UnityEditor.BuildplayerOptions 选项)[0x002ca] 中:0 在 UnityEditor.BuildplayerWindow.CallBuildMethods (System.Boolean askForBuildLocation,UnityEditor.BuildOptions defaultBuildOptions) [0x00080] 中:0 UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

解决方法

您的代码用于编辑器,因此不应包含在构建结果中。为了解决这个问题,我创建了一个“DONOTCOMPILETHIS”构建指令,并将其添加到播放器设置中。 PlayerSetting DLG

最后在您的代码中添加:

using UnityEngine;

#if !DONOTCOMPILETHIS

using UnityEditor;

using UnityEditor.IMGUI.Controls;


[CustomEditor(typeof(CGameTower)),CanEditMultipleObjects]

public class CBoundRectEditor : Editor

{

    private BoxBoundsHandle m_BoundsHandle = new BoxBoundsHandle();


    ...

}

#endif