---
title: Mono Scripting Backend
product: Unity Editor
version: '6000.0'
latest_version: '7000.0'
status: This page documents version 6000.0. The latest version is 7000.0.
canonical: https://docs.unity.com/zh-cn/engine/6000.0/manual/scripting/compilation-and-code-reload/script-compilation/backends/mono
latest_url: https://docs.unity.com/zh-cn/engine/7000.0/manual/scripting/compilation-and-code-reload/script-compilation/backends/mono.md
generated_at: 2026-11-16T08:01:48.149Z
locale: zh-cn
---

# Mono Scripting Backend

> Mono 是一个稳定、成熟的 .NET 运行时，为 C# 代码的实时(JIT)编译提供 Managed Environment。

Mono Scripting Backend 是 Unity 对 Open 音频源 [Mono Project](https://www.mono-project.com/) 的[分支](https://github.com/Unity-Technologies/mono)。Mono 是一个成熟的跨平台 .NET 运行时，可为兼容平台上的 Unity Editor 和玩家提供支持。它提供快速迭代和良好的工具，但运行时性能低于 [IL2CPP](/engine/6000.0/manual/scripting/compilation-and-code-reload/script-compilation/backends/il2cpp.md)，并且与最新的 .NET Features 不匹配。

Mono 使用即时 (JIT) 编译在运行时将 C# 代码转换为机器代码。Mono 管理 Managed 对象的 Lifecycle，处理代码重新加载，并使用 [Boehm-Demers-Weiser](https://www.hboehm.info/gc/) 垃圾回收器对作用域外的对象执行 Automatic 垃圾 Collection。可以在一定程度上Configured垃圾回收器的行为。有关更多信息，请参阅 [Garbage Collection 模式](/engine/6000.0/manual/analysis/performance-memory/managed-memory/incremental-garbage-collection.md)。

Mono 支持托Managed代码的调试。有关更多信息，请参阅[在 Unity 中调试](/engine/6000.0/manual/scripting/debugging-and-diagnostics/managed-code-debugging.md) C# 代码。

## 使用 Mono 构建 Project##building-a-project-with-mono

要开始生成过程，请打开 **Build Profiles** 窗口（菜单：**文件** > **版本配置文件**），然后选择**版本**。

您可以通过两种方式之一Change Unity 用于版本应用程序程序的Scripting Backend：

* 通过 Editor 中的 Editor 菜单。执行以下步骤可通过 **Player Settings** 菜单更改 Scripting Backend：

  1. 转到**编辑** > Editor。
  2. 单击 ON **Player Settings** 按钮可在 [**Inspector**](/engine/6000.0/manual/unity-editor/editor-windows-views-reference/using-the-inspector.md) 中打开当前平台的 [**Player**](/engine/6000.0/manual/unity-editor/editor-settings-reference/comp-manager-group/class-player-settings.md) Settings。
  3. 导航到 **Other Settings** 子菜单下的 **Configuration** 部分标题。
  4. 单击 ON Editor 下拉菜单，然后选择 **Mono**。

  还可以从 **版本配置文件**窗口打开 **Player Settings** 菜单；转到 **文件** > **版本配置文件**，然后单击 ON **Player Settings** 选项卡。

* 通过 Editor 脚本 API。使用 [`PlayerSettings.SetScriptingBackend`](/engine/6000.0/script-reference/unityeditor/playersettings/setscriptingbackend.md) 属性可更改 Unity 使用的 Scripting Backend。


**The Configuration section of the Player settings:**
![](/api/media?file=/engine/6000.0/media/images/backend-mono.png)

Mono 和 IL2CPP 脚本后端都需要针对每个Target平台进行新建的版本。例如，要同时Support Android 和 iOS 平台，需要版本两次应用程序程序并生成两个Binary进制文件，一个用于 Android，另一个用于 iOS。

## 域重新加载##domain-reload

Unity Editor 嵌入 Mono，因此 C# 代码 Mono Managed，并在 Editor 的播放模式下runningWhen Mono 的约束。其中的一个关键方面是，进入和退出播放模式或重新编译脚本会触发 [AppDomain](https://learn.microsoft.com/en-us/dotnet/api/system.appdomain?view=net-9.0) 重新加载，从而重置 Static 状态。您可以[配置 Unity 如何进入播放模式](/engine/6000.0/manual/scripting/compilation-and-code-reload/code-reloading-editor/configurable-enter-play-mode.md)并关闭 OFF 域重新加载以加快迭代速度，但随后代码必须手柄 Static 状态的Reset。有关更多信息，请参阅[进入播放模式](/engine/6000.0/manual/scripting/compilation-and-code-reload/code-reloading-editor/domain-reloading.md)并禁用域重新加载。

## 优化 Mono 构建##optimizing-mono-builds

Mono 和 IL2CPP 使用相同的底部 .NET 库因此许多性能问题和最佳实践都适用于两者。但是，在 Mono 上下文中，请考虑以下几点：

* Mono的 JIT 编译意味着与 IL2CPP 的 AOT 编译相比，它在大型代码库中的运行时时性性能更低，启动时间更长。始终使用 [Unity Profiler](/engine/6000.0/manual/analysis/profiler.md) 进行配置文件以聚光灯 GC 和 JIT 热点。[Project Auditor](/engine/6000.0/manual/project-auditor.md) 工具还可以帮助您识别和修复常见的性能问题。如需了解更多信息，请参阅[优化](/engine/6000.0/manual/analysis.md)。

* 某些编码做法（例如在运行时导致大量分配的做法）可能会增加垃圾回收器的开销并降低性能。ON 关于在 Unity 中编写高性能托管代码的指导，请参阅[针对托管内存优化代码](/engine/6000.0/manual/scripting/optimization/performance-optimizing-code-managed-memory.md)。有关 ON 跟踪和减少垃圾回收器开销的信息，请参阅[托管内存](/engine/6000.0/manual/analysis/performance-memory/managed-memory.md)。

* Unity API 通常不是线程Safe的，这意味着需要从 Unity 的线程程调用它们。避免将 .NET `Task`与 Unity API 结合使用。

  * 当处理固有的异步和长期 running 操作时，Unity 提供 `Awaitable` 类作为 .NET `Task` 的更有效替代方案。有关更多信息，请参阅使用 Awaitable [类异步编程](/engine/6000.0/manual/scripting/optimization/async-await-support.md)。
  * 对于生命周期较短但计算密集型更强的并行化工作，Unity 提供了可[爆发编译](/engine/6000.0/manual/scripting/compilation-and-code-reload/script-compilation/burst.md)的[任务 System](/engine/6000.0/manual/scripting/optimization/job-system.md)。有关更多信息，请参阅使用任务系统[编写多线程代码](/engine/6000.0/manual/scripting/optimization/job-system.md)。

* Mono 的[`DateTime`](https://learn.microsoft.com/en-us/dotnet/api/system.datetime?view=net-9.0)、[`TimeZoneInfo`](https://learn.microsoft.com/en-us/dotnet/api/system.timezoneinfo?view=net-9.0)和[`CultureInfo`](https://learn.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo?view=net-9.0)实现方式可能与 Windows .NET 行为不同。makeONTarget平台测试试全球化的指定的于区域性的代码。

## 使用 爆发 优化运行时性能##optimizing-runtime-performance-with-burst

在合适的Projects中，可以通过将 爆发 编译器与 Mono 结合使用来提高Project的运行时性能，从而将代码的兼容部分编译为高度优化的机器代码。有关更多信息，请参阅[爆发编译](/engine/6000.0/manual/scripting/compilation-and-code-reload/script-compilation/burst.md)。

## 其他资源##additional-resources

* [Unity .NET Features](/engine/6000.0/manual/scripting/environment-and-tools/overview-of-dot-net-in-unity.md)
* [生成配置文件](/engine/6000.0/manual/building-and-publishing/build-settings.md)
