Unity3d SVN版本控制 详细讲解和原理

Unity SVN小团队合作

梦想之家翻译作品

——braveyoung(绿灯伴书影) @2013.8.16

Inthis post we are going to highlight what needs to be committed to SVN and alsoabout the workflow of a small team (5-6) people using Unity (free).

在这一节中我们将要指出什么是需要提交到SVN的,以及小团队使用Unity开发的流程。

Ifyou want to have a better understanding of what Unity is doing underneath youmight want to have a look at the links found at the end of this post.

如果你想要明白Unity底层做了什么,那么你就需要看看这一节后面的连接。

Let’sstart with a new project.

1.     Create a new project

2.     Create a prefab

3.     Create a cube

4.     Drag cube into new prefab

5.     Create a material

6.     Import a texture

7.     Assign the texture to the material

8.     Assign the material to the prefab

9.     Save scene

10.   Quit

Inyour scene you should have a camera and a prefab instance.

Let’stry removing some files, and try relaunching Unity afterwords. Before launching Unity, create a copy of the trimmedproject. You’ll soon know why.
In the project folder (if you launched Menodevelop) delete the following:

o  Temp

o  *.csproj

o  *.pidb

o  *.sln

o  *.userprefs

现在我们尝试着去删除一些文件,稍候重新启动Unity。在重启之前,先给项目做一个备份。等一下你就会知道为什么要这样做了。

如果你的开发工具是Monodevelop,那么在项目文件中就需要删除如下的文件:

o   Temp

o   *.csproj

o   *.pidb

o   *.sln

o   *.userprefs

InLibrary folder you need to delete the following (DON’T DELETE METADATA!!!)

Library文件夹中,你需要删除下面的东西:(使用批处理文佳,不要删除METADATA

o  cache

o  previews

o  ScriptAssemblies

o  assetDatabase3

o  AssetImportState

o  AssetServerCacheV3

o  AssetVersioning.db

o  AudioManager.asset

o  BuildPlayer.prefs

o  BuildSettings.asset

o  DynamicsManager.asset

o  EditorSettings.asset

o  EditorUserBuildSettings.asset

o  expandedItems

o  FailedAssetImports.txt

o  guidmapper

o  InspectorExpandedItems.asset

o  MonoManager.asset

o  NetworkManager.asset

o  ScriptMapper

DON’TDELETE METADATA!!!

切记不删除metadata!!!
The files in Library should look somethinglike this

Library目录下的文件结构:

Afterlaunching Unity, you should see that it’s re-importing and compilingeverything. The textures and prefabs should appear fine in your scene.

在启动了Unity的时候,你就会看到Unity在重新导入和编译一些文件了。Textureprefabs正常显示你的场景中!

Ifit loaded fine then you can import the trimmed version (the copy you had made)into your SVN repo. I would upload it in a folder called unity, so you can haveother folders for art (like PSDs, 3dsmax files etc) and docs separate from theunity project.
Once it’s imported, delete your project since it is not associated with SVNyet. Do a checkout of the project folder. Launch Unity and open the SVNproject. You should see it reimporting everything and you should get everythingas it originally was.

The main idea is that we don’t commitanything which can be automatically generated by Unity.This will also eliminate a lot of uselessconflicts. We can set up an ignore list so that the SVN client doesn’t botherus with.

项目在unity中加载显示的很好,接下来我们就把备份的项目上传到SVN吧。比如我上传到一个Unity的文件夹中,当然你也可以取一些比较有艺术感的名字(比如PSDs, 3dsmax 等等)。

上传之后就删除备份的项目吧!这个时候SVN不会在访问它了。

下面我们检出这个上传的项目,新建一个文件夹就行的。项目检出之后,打开Unity同时打开检出的项目。因为备份的项目也是删除了文件的。所以这个时候Unity会重新编译,重新生成一些重要的文件。

重要的思想:

我们不能提交unity自动生成的文件,这样就会避免很多的冲突了。

我们可以在SVN中设置忽略列表,这样SVN就不会提交这写文件了。
To the ignore list add the files that you had deleted and that now havereappeared because of Unity’s recompilation process

Hereare some commandments the team should follow:

1.     thou shalt not modify the same asset(scene/prefab/material/texture). Do this by doing an SVN lock on any binaryfile BEFORE doing any changes.

你不能修改同一个asset(比如:scene/prefab/material/texture)。在做任何改变之前,你需要二进制文件加SVN锁。加了SVN锁之后,就可以在同一个Asset上编辑和修改了。

2.     thou shalt not forget to add any new assets and relatedmetadata to the repository

你要记得添加任何新的assets和关联的metadatarepository目录中。

3.     thou shalt not forget to remove any deleted assets andrelated orphaned metadata folders. Keep SVN repo clean

你应该删除一些文件,这样保持SVN的干净,不至于冗余。

4.     thou shalt close Unity before doing any SVN operations

在做任何SVN的操作之前,你需要先关闭unity.

5.     thou shalt do an update before committing

在提交之前,要先做一次更新

6.     thou shalt run the leanAndMean batch file after an update

在做了更新操作之后,你需要运行一下leanAndMean.bat的批处理文件

7.     thou shalt not save the scene, if you actually didn’tmodify the scene’s hierarchy or instance values in some way (avoids uselesscommits)

在某一些方面,你要是没有改变场景,就不需要保存场景。

The1st commandment is the toughest. Try to communicate between you who ismodifying what. If you are working on some tasks which will finally end up inone scene, you might want to create a temp scene for each individual, sort ofprototype scenes. Then the leader should merge all the assets in the main finalscene. This could be done by dragging of prefabs, or importing unity packagesin the main scene. Also locking will help (see below)

要做到如上的第一条要求是很艰难的事情,试着告知你谁在修改什么是很一件很难的事情。如果你正在做的一些任务,这些人物需要在一个场景完成。这个时候你也许会想到为每个单独的场景都创建一个临时的场景文件。然后项目负责人就会在一个最终的场景中,合并所有的资源。为了合并场景,我们可以使用拖动prefabs或者是直接在主场景中导入unitypackage文件,这个时候SVN锁就有作用了。
To keep it from getting messy, only programmers should interact with SVN. Forthe artists you could have a separate folder, or only give them instructions toupload directly in Assets/Sounds or Assets/Textures folders. But PSDs shouldnot be part of Assets as it would take much more time when Unity is rebuildingthe Library files after you run the clean batch file.

为了避免麻烦,只有程序员和SVN交互,对于美工人员,他们应该有自己独立的文件夹。或者是让美工直接给Assets/Sounds文件夹和Assets/Textures文件上传文件。但是PSD文件不应该作为Assets的一部分,因为你一旦执行了清理的批处理文件,这个时候unity重新编译生成Library文件,这个时候对于PSD来说就会浪费很多的时间。
If the artists in the team are not technical and you think that SVN is going todrive them nuts, then set up some shared Dropbox folder and the leader wouldneed to commit any art done by the artists.

如果美工人员在这个团队不是技术,那么他们可能就不会使用SVN。然后设置一些共享Dropbox文件夹,项目管理员需要提交任何美工人员做的东西。。

 

 

Bediligent when committing and add any assets you’ve created, and any newmetadata files/folders in the Library/metadata. Also when delete a file whichis not part of your game anymore, delete files through SVN, relaunch Unity andtheir related metadata will automatically deleted. Keep SVN clean.

当你提交和添加任何你新创建的Assets,还有任何Library/metadata目录下新的元数据文件/文件夹做这些操作的时候你就要勤快一点了。当删除一个文件,它不属于你的游戏了.通过SVN删除文件,重新启动Unity,相关元数据将自动删除。这样便于保持SVN清洁

Whenyou delete assets, their related metadata is removed but their associatedfolder will not be removed. You can safely SVN delete empty folders in themetadata folder.

你删除一些资源之后,它们关联的数据就被移除了。但是它们不会删除关联的文件夹,你可以通过SVN删除元数据文件夹中空文件夹

Afterdoing an update, you should get the Library folder lean and mean again. Theeasiest way will be by doing a script or batch file.
Here’s one for Macs. Call it leanAndMean.sh and place it in your Libraryfolder:

在更新之后,你需要再Library文件夹中运行一下leanAndMean批处理文件

MAC版本的批处理文件:

rm assetDatabase3
rm AssetImportState
rm assetservercachev3
rm AssetServerCacheV3
rm AssetVersioning.db
rm AudioManager.asset
rm BuildPlayer.prefs
rm BuildSettings.asset
rm DynamicsManager.asset
rm EditorSettings.asset
rm EditorUserBuildSettings.asset
rm expandedItems
rm FailedAssetImports.txt
rm guidmapper
rm InspectorExpandedItems.asset
rm MonoManager.asset
rm NetworkManager.asset
rm ScriptMapper
rm -r -d -f cache
rm -r -d -f previews
rm -r -d -f ScriptAssemblies

Rememberto do chmod 777 leanAndMean.sh in some terminalwindow版本的比处理文件:
For Windows the leanAndMean.bat will look something like this:

del assetDatabase3
del AssetImportState
del assetservercachev3
del AssetServerCacheV3
del AssetVersioning.db
del AudioManager.asset
del BuildPlayer.prefs
del BuildSettings.asset
del DynamicsManager.asset
del EditorSettings.asset
del EditorUserBuildSettings.asset
del expandedItems
del FailedAssetImports.txt
del guidmapper
del InspectorExpandedItems.asset
del MonoManager.asset
del NetworkManager.asset
del ScriptMapper
rmdir /s cache /q
rmdir /s previews /q
rmdir /s ScriptAssemblies /q

Alsodon’t forget to add it to your SVN repo on your next commit

在你下一次提交修改的时候,就把这个批处理文件上传上去。

What happens if you forget to run thisbatch file?

不运行批处理文件会发生什么事情呢?

Let’ssay you create a new material with a new texture and associate with a prefab, andyou commit. The other guys after doing an update would see a pink color insteadof your texture.

比如你使用新的texture创建了一个新的材质球,同时附加到一个prefab上。然后你提交你的东西,其他的人更新项目,你的texture就没有了,这个时候被粉红粉色代替了。
Running the batch file/script will solve this issue.

运行一下前面说到的批处理文件就可以解决问题了。

Evenif you are going to try your very best to avoid people working on the sameassets, it will inevitably happen at some point in time. Let’s think of ascenario.

在对同一个资源进行编辑的时候,是很难避免的多人同时操作同一资源的情况的。让我们想象一下如下的情景:
If A modifies a scene (e.g. a value of a script within a prefab instance) andcommits, AND B modifies the same scene, and tries to do an update he will get aconflict. Since it’s binary it will not be merged automatically. You will have3 files, e.g:

.unity文件冲突

比如说:程序员A在修改一个unity场景(eg:修改了一个拖到prefab的脚本的值),同时提交了修改。程序员B修改了同一个场景,这个时候更新就会发生冲突。这是因为二进制文件没有被自动合并。你将会得到如下的三个文件,比如:
scene.unity
• scene.unity.r3
• scene.unity.r5

These are basically your current version and the previous 2 remote versions.

这些基本上是你的当前版本和之前的2远程版本。
Since it’s not text, it cannot merge it. You will have to decide which is thebest version by inspecting them in Unity. So you will have to play around byopening the different versions. For the case of scenes, perhaps renaming themto scene_r3.unity and scene_r5.unity might help to open them quickly withinUnity.

因为.unity文件不是文本文件,因此是不能合并的。这个时候,你就不得不根据你的unity来选择最好的版本。为了选择最好版本的,你就需要打开不同的版本,你可以用下面的方式:分别重新命名为scene_r3.unityscene_r5.unity然后分辨打开就行了。
Once you merge them manually, delete the remote versions (r3, and r5 in thiscase), mark your scene file as merged, and commit.

一旦你手动合并这些场景之后,删除远程版本文件,同时标记场景文件为合并,最后提交。

Prefab冲突问题:
Prefab conflicts will be similar. Let’s say you have your version calledtest.prefab, and the last two remote versions, test.prefab.r5 andtest.prefab.r7. You have to manually decide which is the best one or mergemanually by inspecting the values within unity and creating the merged prefab.

Prefab的冲突也是相似的。假设你有一个版本叫做test.prefab,和2个最新的远程版本,test.prefab.r5test.prefab.r7。这个时候你不得不决定最好的版本或者是在unity中手动合并,然后创建合并之后的prefab

给文件加svn

Sofar we didn’t mention anything about locking a file. What we covered so far isCopy-Modify-Merge flow (update, do the changes, commit and hope no one touchedthe file).

到目前为止我们还没有提到有关给文件加锁的事情。我们目前而至介绍的是复制修改合并的流程


Abetter workflow would be for binary files such as scenes, textures, material,prefabs (but not scripts as they are just textfiles and easily mergeable), we should use the Lock-Modify-Unlock approach(lock, do the changes, commit and should automatically unlock the resource).

对于二进制文件(比如scenes, textures, material, prefabs)最好处理方式是加锁->修改->解锁(意思就是加锁->做一些修改->提交,这个时候SVN会自动解锁的)
So if person A wants to modify test.prefab, he first should do an SVN lock onthe file. While he is doing the changes, if person B wants to also modify thetest.prefab he needs to first try to obtain the lock. If the file is stilllocked by A then SVN will warn B that someone else has the lock and soshouldn't modify until A commits and releases the lock.

比如:如果人员A想修改test.prefab,那么他首先要对这个test.prefab文件加锁。当A正在对test.prefab进行修改的时候,如果程序员B也想要修改test.prefab。那么程序员B首先要尝试去获得这个SVN锁,如果SVN锁任然被A使用着,那么SVN就会警告程序员Bsomeone elsehas the lock and so shouldn't modify until A commits and releases the lock.

Solock, do any changes, commit. If the lock fails don't do any changes. Needssome diligence but this will avoid any conflicts.

因为加锁,做修改,提交。如果加SVN失败就不要做任何修改了,如果你勤快一点就会避免很多的冲突了。

引用连接:

http://bitflipgames.com/2010/09/13/tips-for-working-with-unity-1-source-control/
http://answers.unity3d.com/questions/22604/which-unity-project-files-can-be-ignored-for-versi.html
http://svnbook.red-bean.com/en/1.5/svn.advanced.locking.html

转载请注明原链接地址,谢谢合作.




 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值