在Unity項目中使用Git

本文參考了Unity官網的Mastering Unity Project Folder Structure - Version Control SystemsUsing External Version Control Systems with Unityhtml

首先須要瞭解一下Unity的目錄結構。假設有一個叫作testproject的項目,那麼它的結構應該以下圖所示。git

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.oop

Assembly-UnityScript-vs.unityproj 和 Assembly-UnityScript.unityproj:相同的項目文件,只不過是爲JavaScript腳本。ui

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.this

testproject.sln 和 testproject-csharp.sln:IDE的解決方案文件,第一個包括全部的C#、JavaScript和Boo腳本;而第二個只包括C#腳本,被設計用來在Visual Studio中打開,由於VS不知道如何處理JavaScript和Boo項目。spa

testproject.userprefs and testproject-csharp.userprefs – configuration files where MonoDevelop stores current opened files, breakpoints, watches etc.設計

testproject.userprefs 和 testproject-csharp.userprefs:MonoDevelop用來存儲當前打開文件、斷點、觀測等的配置文件。3d

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。

看完了以上的內容就能夠知道,咱們只須要將AssetsProjectSettings兩個文件夾歸入版本控制便可。但在編寫.gitignore文件前,還須要如下幾個步驟,將設置以文本形式存儲以利於版本控制:

  1. 在 Edit->Project Settings->Editor->Version Control Mode 中選擇 Visible Meta files
  2. 在 Edit->Project Settings->Editor->Asset Serialization Mode 中選擇 Force Text
  3. 保存場景和項目。

下面是一份參考的.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
相關文章
相關標籤/搜索