Unity supports version control integration with Perforce and Plastic SCM, refer to these pages for specific information regarding your choice of 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.
Follow these steps once you have your version control software setup according to their own instructions:
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 工具。
就目前而言,您应该能够通过右键单击 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 中解决。
可以从__版本控制窗口__ (Window > Version Control) 中查看位于变更列表中的文件。该窗口停靠在 Editor 中的 Inspector 旁边:
“Outgoing”选项卡列出等待提交到版本控制系统的所有本地更改,而“Incoming”选项卡列出需要从版本控制系统中拉取的所有更改。
通过右键单击此窗口中的资源或变更列表,可以对它们执行操作。要在变更列表之间移动资源,只需将资源从一个变更列表拖动到目标变更列表的标题上。
Unity Editor 中会显示以下图标,从而显示文件/资源的版本控制状态:
图标 | 含义 | 其他信息 |
已在本地添加文件 | 等待添加到版本控制系统 | |
文件由另一个用户添加到版本控制系统 | 等待添加到版本控制系统 | |
文件已被您签出 | 已在本地签出 | |
文件已被另一个用户签出 | 已远程签出 | |
合并此文件时存在冲突 | 需要解决冲突 | |
文件已被您删除 | 等待版本控制系统中删除 | |
文件已被另一个用户删除 | 等待版本控制系统中删除 | |
文件尚未受版本控制 | 无 | |
文件已被您锁定 | 其他用户无法修改 | |
文件已被另一个用户锁定 | 您无法修改 | |
另一个用户已签入此文件的新版本 | 使用“Apply Incoming Changes”获取最新版本 |
注意事项:
处理资源时,Unity 会自动签出资源文件以及相关的 .meta 文件。但是,在大多数情况下,不会修改 .meta 文件,这可能会导致一些额外的工作,例如在稍后合并分支时。
Unity 支持在脱机模式下工作,例如,在没有网络连接到版本控制库的情况下继续工作。
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.
For work with the Asset Server (Unity’s internal Version Control System) refer to the Asset Server documentation.
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