使用 UnityYAMLMerge 工具以语义正确的方式合并场景和预制件文件。可从命令行中访问该工具,也可将其用于第三方版本控制软件。
在 Version Control 项目设置中(菜单: Edit > Project Settings > Version Control),当您在 Mode 字段中选择第三方版本控制工具(如 Perforce 或 PlasticSCM)时,将显示 Smart Merge。该菜单提供了以下选项:
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 中已列出最常用的工具,但可以编辑此文件以添加新工具或更改选项。
可从命令行中将 UnityYAMLMerge 作为独立工具运行(若要查看该工具的完整使用说明,可在运行时不带任何参数)。下面给出了常见版本控制系统的设置说明。
.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
。 <path to UnityYAMLMerge> merge -p %base %theirs %mine %merged
然后,按照相同的步骤添加 .prefab
扩展名。
.unity
扩展名。 <path to UnityYAMLMerge> merge -p "@basefile" "@sourcefile" "@destinationfile" "@output"
然后,按照相同的步骤添加 .prefab
扩展名。
merge -p $BASE $REMOTE $LOCAL $MERGED
。要自定义 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
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.