(搬运自我在SegmentFault的博客)
本文参考了Unity官网的Mastering Unity Project Folder Structure - Version Control Systems和Using External Version Control Systems with Unity。
首先需要了解一下Unity的目录结构。假设有一个叫做testproject
的项目,那么它的结构应该如下图所示。
Assembly-CSharp-vs.csproj and Assembly-CSharp.csproj – Visual Studio (with -vs suffix) and MonoDevelop project files generated for your C# scripts.
Assembly-CSharp-vs.csproj 和 Assembly-CSharp.csproj :Visual Studio(带有-vs后缀)和MonoDevelop为C#脚本生成的项目文件。
Assembly-UnityScript-vs.unityproj and Assembly-UnityScript.unityproj – the same project files but for JavaScript scripts.
Assembly-UnityScript-vs.unityproj 和 Assembly-UnityScript.unityproj:相同的项目文件,只不过是为JavaScript脚本。
testproject.sln and testproject-csharp.sln – solution files for IDEs, first one includes all C#, JavaScript and Boo projects, while the second one – only C# projects and is designed to be opened in Visual Studio, because VS doesn’t know to handle JavaScript and Boo projects.
testproject.sln 和 testproject-csharp.sln:IDE的解决方案文件,第一个包括所有的C#、JavaScript和Boo脚本;而第二个只包括C#脚本,被设计用来在Visual Studio中打开,因为VS不知道如何处理JavaScript和Boo项目。
testproject.userprefs and testproject-csharp.userprefs – configuration files where MonoDevelop stores current opened files, breakpoints, watches etc.
testproject.userprefs 和 testproject-csharp.userprefs:MonoDevelop用来存储当前打开文件、断点、观测等的配置文件。
Assets – folder where all game resources are stored, including scripts, textures, sound, custom editors etc. Definitely the most important folder in your project.
Assets:存储所有游戏资源的文件夹,包括脚本、纹理、声音、编辑器定制等。当然是项目中最重要的文件夹。
ProjectSettings – in this folder Unity stores all project settings like Physics, Tags, Player settings etc. In other words everything you setup from Edit → Project Settings set of menus goes into this folder.
ProjectSettings:在这个文件夹中Unity存储所有的项目设置,如物理、标签、角色设置等。或者说,所有你从 Edit → Project 的菜单中设置的都在这个文件夹中。
Library – local cache for imported assets, when using external version control system should be completely ignored.
Library:被导入资源的本地缓存,当使用外部版本控制系统时应当被完全忽略。
obj and Temp – folders for temporary files generated during build, first one used by MonoDevelop, second – by Unity.
obj 和 Temp:存储构建时产生的临时文件的文件夹,第一个用于MonoDevelop,第二个用于Unity。
看完了以上的内容就可以知道,我们只需要将Assets
和ProjectSettings
两个文件夹纳入版本控制即可。但在编写.gitignore
文件前,还需要以下几个步骤,将设置以文本形式存储以利于版本控制:
- 在 Edit->Project Settings->Editor->Version Control Mode 中选择
Visible Meta files
。 - 在 Edit->Project Settings->Editor->Asset Serialization Mode 中选择
Force Text
。 - 保存场景和项目。
下面是一份参考的.gitignore
文件:
===============
Unity generated
===============
Temp/
Library/
=====================================
Visual Studio / MonoDevelop generated
=====================================
ExportedObj/
obj/
*.svd
*.userprefs
/*.csproj
*.pidb
*.suo
/*.sln
*.user
*.unityproj
*.booproj
============
OS generated
============
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db