Unity には意味的に正しい方法でシーンやプレハブのファイルをマージすることができる UnityYAMLMerge というツールが組み込まれています。このツールは、コマンドラインからアクセスでき、サードパーティのバージョン管理ソフトウェアも利用可能です。
Editor ウィンドウ (Edit> Project Settings の順に移動し、Editor カテゴリを選択) で、サードパーティ製のバージョン管理ツール (Perforce や PlasticSCM など) を選択することができます。これらのツールの 1 つが有効になっている場合、Version Control 見出しの下に Smart Merge メニューが表示されます。メニューには 4 つのオプションがあります。
UnityYAMLMerge ツールは、Unity editor が同梱されています。 Unity が標準の場所にインストールされていると仮定すると、UnityYAMLMerge へのパスは次のようになります。
C:\Program Files\Unity\Editor\Data\Tools\UnityYAMLMerge.exe
または
C:\Program Files (x86)\Unity\Editor\Data\Tools\UnityYAMLMerge.exe
…Windows 上と
/Applications/Unity/Unity.app/Contents/Tools/UnityYAMLMerge
…MacOSX 上で (このフォルダーにアクセスするには、Finder から Show Package Contents コマンドを使用します。)
UnityYAMLMerge は、それがどのように未解決のコンフリクトまたは未知のファイルを続行するかを指定するデフォルトのフォールバックファイル( Tools フォルダーでも mergespecfile.txt と呼ばれます)が同梱されています。これはまた、ファイル拡張子に基づいて自動的にマージツールを選択しない(例えば、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
と入力します。To customize how UnityYAMLMerge merges files, configure the mergerules.txt file. This is available in the Editor/Data/Tools
folder of your Unity installation.
The various configuration options are as follows.
The arrays configuration section tells UnityYAMLMerge to treat the specified path as an array; either as a “set” with a key value, or as a “plain” array without key values. The default for all arrays is to do a hybrid mode and try to match with some known heuristics.
[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
The exclusions configuration section indicates which paths to exclude from merging. If both sides have been modified, they are then treated as a conflict and will show up for user input.
[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
The comparisons section takes into account negligible differences between float values to ignore per user settings. When enabled, floating point comparison is done relatively to account for relative error. You can configure comparison in the following ways:
The relative comparison value determines epsilon and how comparison will scale with the size of the floats’ relative error. The absolute comparison cutoff determines at which point float comparison switches from absolute to relative from zero (on a graph).
Note: Comparison values should be between float epsilon (~0.00000011921) and 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