Maoyeedy

Sep 27, 2023

小迪睿频 Unity Smart Locks

一个学生团队中的常见案例

在台湾的时候,我们游戏设计课是四人小组,用的是 UE && Perforce Helix Core VCS
有一天早上,小迪狠狠改了一下 Level.umap,并点了上传按钮。
过了几分钟,小钟也小改了一下 Level.umap,也点了上传按钮,却看到:
Error: You need to pull the latest changes from server before pushing.
小钟想着:“好那我先把小迪的改动下载下来。”却看到:
Error: Merge Confict On Level.umap: Binary files can’t auto merge.

为什么会这样

UE的场景文件.umap是二进制文件,无法像.unity文件那样自动合并。

如何解决这种情况

如果你是小钟,你可以手动解决冲突:
  1. 把你本地的 Level.umap Ctrl+D 复制为 Level_Bak.umap
  1. 强制下载小迪的 Level.umap,让它替换掉你本地的 Level.umap
  1. 打开你刚刚备份的 Level_Bak.umap,把你做的改动手动添加到小迪的 Level.umap
🤔
但如果出现冲突的是 Cover.png , Player.fbx 或 Music.wav 呢? 手动解决冲突还有这么简单吗?
很多 Git 用户都曾被这样的问题困扰过,于是在2015年,有人向
git-lfs
git-lfsUpdated Nov 11, 2023
提了一个 Feature Request,原话是:
🙏
We need the ability to lock files to discourage (we can never prevent) parallel editing of binary files which will result in an unmergeable situation.

什么是 Git LFS Lock

早在2016年,Git LFS v1.3.0 便已支持这项特性了。
你无法修改别人锁定的文件
你无法修改别人锁定的文件
然而,主流的公共 Git 托管平台中,至今只有 Gitlab 与 Bitbucket 支持这项特性。
并且用起来较为繁琐,需手动锁定与解锁。
git lfs lock 1.png git lfs unlock --force 1.png
git lfs lock "*.png" #一键锁定当前所有png
当然,你可以往 .git/hooks 写一个 pre-push/pre-commit hook,以下是一个范例:
git-lfs-lock-pre-commit-hook
wanadevUpdated Aug 18, 2021
即便如此,Git LFS Lock还是两个明显的缺陷:
  1. git commit 时才能得知 1.png 已经被别人上了锁。
  1. Github 不支持这项特性。
 
所幸,Plastic SCM 在 2023.06 宣布并公测了 Smart Lock 相比 Git LFS Lock,它:
  • 由管理员在 Dashboard 设置全局的 Lock rules,如 *.png *.fbx。
  • 由服务器判定哪些文件需要上锁,而不是由用户手动锁定。
  • 在 Unity Editor 中:你会在被别人锁定的文件上方看到一个🔒
  • 在 Unity Editor 中:你无法对别人锁定的文件执行 Ctrl+S

什么是 Smart Locks

💡
Smart Locks in Unity Version Control simplify the version control process and make it easier to collaborate on projects. Smart Locks let you lock non-mergeable assets, such as 3D models, images, or audio files, during checkout to avoid merge conflicts.
When you check out a file with existing lock rules in place, Unity VCS locks the file and displays a locked status to indicate that the file is locked. If you try to check out a locked file, a dialog informs you that the file is locked. You can't check out, check in, or merge any files that are locked by another user; whoever has the file locked is the only person who can update it. This prevents multiple users from changing the same file in parallel and ensures that only the latest revision is modified.

官方文档

短篇介绍:原理解释 与 Use Cases

notion image
notion image

如何设置 Smart Locks

如果你使用的是 PlasticSCM Web UI,详见:
如果你使用的是 UnityDevOps Dashboard,详见:
PlasticSCM Web UI
PlasticSCM Web UI
Unity DevOps Dashboard
Unity DevOps Dashboard
以下是我写的 Lock Rules 范例,大家可以按需复制:
*.wav, *.mp3, *.ogg
*.jpg, *.jpeg, *.png, *.gif, *.tiff, *.tif, *.bmp, *.tga, *.exr, *.hdr, *.svg,*.psd, *.psb
*.fbx, *.obj, *.dae, *.abc, *.usd, *.usda, *.usdz, *.usdc, *.glb, *.gltf
*.blend, *.ma, *.mb, *.max, *.3ds

那如果你是国区用户呢?

优三缔科技(上海)有限公司 做的 国区特供版 PlasticHub https://plastichub.unity.cn/ 不支持设置 Smart Locks,所以国区用户只能等后续更新。
我写这篇博客写到一半才发现这一点 ^^…

Copyright © 2024 Maoyeedy

logo