Use the UnityYAMLMerge tool to merge scene and prefab files in a semantically correct way. The tool can be accessed from the command line and is also available to third-party version control software.
In the Version Control project settings (menu: Edit > Project Settings > Version Control), when you select a third-party version control tool in the Mode field, for example Perforce or PlasticSCM, the Smart Merge is displayed. The menu has the following options:
UnityYAMLMerge 工具随附于 Unity Editor;假设 Unity 安装在标准位置,则 UnityYAMLMerge 的路径将是:
C:\Program Files\Unity\Editor\Data\Tools\UnityYAMLMerge.exe
or
C:\Program Files (x86)\Unity\Editor\Data\Tools\UnityYAMLMerge.exe
/Applications/Unity/Unity.app/Contents/Tools/UnityYAMLMerge
UnityYAMLMerge 附带了一个默认的回退文件(称为 mergespecfile.txt,也在 Tools 文件夹中),用于指定如何处理未解决的冲突或未知文件。此外,还可将其用作不会根据文件扩展名自动选择合并工具的版本控制系统(例如 git)的主要合并工具。默认情况下,mergespecfile.txt 中已列出最常用的工具,但可以编辑此文件以添加新工具或更改选项。
You can run UnityYAMLMerge as a standalone tool from the command line (you can see full usage instructions by running it without any arguments). Setup instructions for common version control systems are given below.
.unity
.merge -p %b %1 %2 %r
然后,按照相同的步骤添加 .prefab
扩展名。
将以下文本添加到 .git
或 .gitconfig
文件中:
[merge]
tool = unityyamlmerge
[mergetool "unityyamlmerge"]
trustExitCode = false
cmd = '<path to UnityYAMLMerge>' merge -p "$BASE" "$REMOTE" "$LOCAL" "$MERGED"
将以下文本添加到 .hgrc
文件中:
[merge-patterns]
**.unity = unityyamlmerge
**.prefab = unityyamlmerge
[merge-tools]
unityyamlmerge.executable = <path to UnityYAMLMerge>
unityyamlmerge.args = merge -p --force $base $other $local $output
unityyamlmerge.checkprompt = True
unityyamlmerge.premerge = False
unityyamlmerge.binary = False
将以下文本添加到 ~/.subversion/config
文件中:
[helpers]
merge-tool-cmd = <path to UnityYAMLMerge>
.unity
in the extension field. <path to UnityYAMLMerge> merge -p %base %theirs %mine %merged
然后,按照相同的步骤添加 .prefab
扩展名。
.unity
extension. <path to UnityYAMLMerge> merge -p "@basefile" "@sourcefile" "@destinationfile" "@output"
然后,按照相同的步骤添加 .prefab
扩展名。
merge -p $BASE $REMOTE $LOCAL $MERGED
in the Arguments field.要自定义 UnityYAMLMerge 合并文件的方式,请配置 mergerules.txt 文件。该文件位于您的 Unity 安装的 Editor/Data/Tools
文件夹中。
各种配置选项如下。
arrays 配置部分告知 UnityYAMLMerge 将指定路径视为一个数组;或者作为带有键值的 “set”,或者作为没有键值的 “plain” 数组。所有数组的默认设置是采用混合模式并尝试与一些已知的启发式方法匹配。
[arrays]
set *.GameObject.m_Component *.fileID
set *.Prefab.m_Modification.m_Modifications target.fileID target.guid propertyPath
plain *.MeshRenderer.m_Materials
plain *.Renderer.m_Materials
exclusions 配置部分指示要从合并中排除哪些路径。如果双方都已修改,则它们将被视为冲突,并将显示给用户输入。
[exclusions]
exclude *.MeshRenderer.m_Materials.*
exclude *.SpriteRenderer.m_Materials
exclude *.SpriteRenderer.m_Color
include *.ParticleSystem.InitialModule
exclude *.ParticleSystem.*
exclude *.ParticleSystem.InitialModule.*
# excludeDepend *.MonoBehaviour m_Script ^m_
excludeIfContains *.MonoBehaviour.* x y z
excludeIfContains *.MonoBehaviour.* r g b
comparisons 部分考虑了浮点值之间可以忽略的差异,以忽略每个用户的设置。启用后,在浮点比较时会考虑相对误差。您可以按照以下方式配置比较:
相对比较值决定了 epsilon 以及比较将如何随着浮点数相对误差的大小而缩放。绝对比较截止值决定了在距离 0 点的哪个位置将浮点比较从绝对切换到相对(在图上)。
注意:比较值应该在 float epsilon(0.00000011921)和 1.0 之间
[comparisons]
float *.Transform.m_LocalPosition.x 0.0000005
float *.Transform.m_LocalPosition.y 0.0000005
float *.Transform.m_LocalPosition.z 0.0000005
float *.Transform.m_LocalRotation.x 0.00005 0.001
float *.Transform.m_LocalRotation.y
float *.Transform.m_LocalRotation.z 0.00005 0.001
float *.Transform.m_LocalRotation.w