Version: 2017.2
Perforce 集成

Version control integration

Unity supports version control integration with Perforce and Plastic SCM, refer to these pages for specific information regarding your choice of version control.

Why should I use version control?

Using a version control system makes it easier for a user/multiple users to manage their code. It is a repository of files with monitored access, which in the case of Unity, will be all the files associated with a Unity project. With version control it is possible to follow every change to the source along with information on who made the change, why they made it and what they changed/added. This makes it easy to revert back to an earlier version of the code or to compare differences in versions. It also becomes easier to locate when a bug first occurred along with what code might have caused it.

Setting up your version control in Unity

Follow these steps once you have your version control software setup according to their own instructions:

  1. Setup or sync a workspace on your computer using your chosen client (refer to the Plastic SCM Integration guide or the Perforce Integration guide for help with this step).
  2. Copy an existing project into the workspace or start Unity and create a new project in the workspace.
  3. Open the project and go to the Edit->Project Settings->Editor menu.
  4. Choose your version control Mode according to the version control system that you chose.

1.填写版本控制设置,例如用户名/密码/服务器/工作空间。 1. Keep Automatic add checked if you want your files to be automatically added to version control when they’re added to the project (or the folder on disk). Otherwise you will have to add new files manually. 1. You have to option to work in offline. This mode is only recommended to advanced users who know how to manually integrate changes back into their choice of version control (Working offline with Perforce). 1. The Asset Serialization, Default Behaviour Mode and Sprite Packer options can be edited to suit your team’s preferences and choice of version control. 1. Click connect and verify that “Connected” is displayed above the connect button after a short while. 1. Use your standard client (e.g. p4v) to make sure that all files in the Assets and ProjectSettings folders (including files ending with .meta) are added.

注意:随时都可以转到 Prefences 菜单并选择 __External Tools__,然后调整 Revision Control Diff/Merge 工具。

Using version control

就目前而言,您应该能够通过右键单击 Project 视图中的资源(而不是通过版本控制客户端)来直接执行大多数重要的版本控制操作。版本控制操作取决于所选择的版本控制系统,下表显示了每个版本控制系统中可直接使用的操作:

版本控制操作 描述 Perforce Plastic SCM
签出 (Check Out) 允许对文件进行更改
与 HEAD 的差异 (Diff against head) 比较本地文件和 HEAD 中的文件之间的差异
获取最新 (Get Latest) 拉取最新更改并更新文件 否*
锁定 (Lock) 阻止其他用户对文件进行更改 否**
标记添加 (Mark Add) 在本地添加但不添加到版本控制系统
解决冲突 (Resolve Conflicts) 解决已被多个用户更改的文件的冲突 否***
还原 (Revert) 放弃对打开的已更改文件所做的更改
还原未更改内容 (Revert Unchanged) 放弃对打开的未更改文件所做的更改
提交 (Submit) 将文件当前状态提交给版本控制系统
解锁 (Unlock) 解锁并允许任何人进行更改 否**

* 要使用 Plastic SCM 获取最新更改并更新文件,需要使用版本控制窗口。

** 使用 Plastic SCM 来锁定和解锁需要您在外部编辑特定的 Plastic SCM 锁定文件,请参阅 Plastic SCM 集成页面以了解更多信息。

*** 冲突会显示在版本控制菜单中,但需要在 Plastic SCM GUI 中解决。

Mac 上的 Plastic SCM 版本控制操作
Mac 上的 Plastic SCM 版本控制操作
Windows 上的 Perforce 版本控制操作
Windows 上的 Perforce 版本控制操作

Version Control Window

可以从__版本控制窗口__ (Window > Version Control) 中查看位于变更列表中的文件。该窗口停靠在 Editor 中的 Inspector 旁边:




Unity Editor 中会显示以下图标,从而显示文件/资源的版本控制状态:

图标 含义 其他信息
已在本地添加文件 等待添加到版本控制系统
文件由另一个用户添加到版本控制系统 等待添加到版本控制系统
文件已被您签出 已在本地签出
文件已被另一个用户签出 已远程签出
合并此文件时存在冲突 需要解决冲突
文件已被您删除 等待版本控制系统中删除
文件已被另一个用户删除 等待版本控制系统中删除
文件已被您锁定 其他用户无法修改
文件已被另一个用户锁定 您无法修改
另一个用户已签入此文件的新版本 使用“Apply Incoming Changes”获取最新版本


  • 有些版本控制系统在资源标记为 Checked out 之前不允许编辑资源(除非已选中 __Work offline__)。
  • 保存对 .scene 文件的更改时,将自动签出。
  • Project Settings Inspector 的右下角有一个 checkout 按钮可用于签出设置。
  • 通常会出现黄色警告,提醒将项签出以便对其进行更改,主要出现在 Project Settings Inspector 中。
  • 在 Plastic SCM 中会自动添加/签出自动生成的资源(例如光照贴图)。


处理资源时,Unity 会自动签出资源文件以及相关的 .meta 文件。但是,在大多数情况下,不会修改 .meta 文件,这可能会导致一些额外的工作,例如在稍后合并分支时。

Offline Mode

Unity 支持在脱机模式下工作,例如,在没有网络连接到版本控制库的情况下继续工作。

  • 如果希望能够与版本控制系统断开连接,请从 Version Control Settings 中选择 Work offline


If Unity for some reason cannot commit your changes to your version control client, e.g. if server is down or license issues, your changes will be stored in a separate changeset.

Working with the Asset Server

For work with the Asset Server (Unity’s internal Version Control System) refer to the Asset Server documentation.

Working with other version control systems

In order to work with a version control system unsupported by Unity, select MetaData as the Mode for Version Control in the Editor Settings. This allows you to manage the source assets and metadata for those assets with a version control system of your choice. For more on this, see the documentation for External Version Control Systems

Perforce 集成