在Unity 3D中使用Git源代码控制的最佳实践是什么,特别是在处理Unity 3D项目的二进制性质时?请描述工作流程,在.gitignore中包含哪些路径,应该在Unity和/或项目中设置什么设置,以及任何其他应该注意的特殊事情。

注意:我知道使用资产服务器是unity推荐的方式,但出于各种原因,我想使用Git。请不要回答,状态或争论,我应该只是使用资产服务器。资产服务器真的不是我的选择。


当前回答

你可以使用Github for Unity,这是一个Unity扩展,将git工作流带入Unity的UI中。

Github for Unity刚刚发布了扩展的1.0版本。

它使用git-lfs (git大文件支持)来正确存储大资产 文件锁定,这样其他人就不会覆盖您的资产提交 向/从任何远程存储库推送和拉取 你也可以在Unity资产商店下载:https://assetstore.unity.com/packages/tools/version-control/github-for-unity-118069

其他回答

我和我的朋友在72小时的游戏jam中尝试过这种方法,请注意他们不知道GIT。

首先,我在[GitHub][1](私人回购现在是免费的)与预定义的.gitignore统一模板创建空回购,它应该与此相同:

# This .gitignore file should be placed at the root of your Unity project directory
#
# Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore
#
[Ll]ibrary/
[Tt]emp/
[Oo]bj/
[Bb]uild/
[Bb]uilds/
[Ll]ogs/
[Mm]emoryCaptures/

# Asset meta data should only be ignored when the corresponding asset is also ignored
!/[Aa]ssets/**/*.meta

# Uncomment this line if you wish to ignore the asset store tools plugin
# /[Aa]ssets/AssetStoreTools*

# Autogenerated Jetbrains Rider plugin
[Aa]ssets/Plugins/Editor/JetBrains*

# Visual Studio cache directory
.vs/

# Gradle cache directory
.gradle/

# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd
*.pdb
*.mdb
*.opendb
*.VC.db

# Unity3D generated meta files
*.pidb.meta
*.pdb.meta
*.mdb.meta

# Unity3D generated file on crash reports
sysinfo.txt

# Builds
*.apk
*.unitypackage

# Crashlytics generated file
crashlytics-build.properties

Then I've created a main scene, this scene shouldn't be modified by any individual while they are development, It should be the demo scene for all dev and artists in the team to test the latest features in game. First of all any new feature should be in a separate branch from main, also each team member has his own scene that he use it for testing and development. once everything is good he/she made a PR reviewed by other members. If the merged feature is complete then we add it to the main scene so that all other members see the impact and the progress.

关于美术文件,最好是通过精灵文件的变化来避免冲突,并将主要精灵替换为pr中完全调整过的新精灵。 [1]: https://github.com/

在Unity 4.3中,你还必须从首选项中启用外部选项,但自从Unity 4.5以来,他们放弃了这个选项,所以完整的设置过程如下:

在编辑器→项目设置→编辑器→版本控制模式中切换到可见元文件 在编辑器→项目设置→编辑器→资产序列化模式中切换到强制文本 从文件菜单保存场景和项目

此外,我们的团队正在使用一些扩展的.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

注意,您需要保存在源代码控制下的文件夹只有Assets和ProjectSettings。

更多关于将Unity项目置于源代码控制之下的信息,你可以在这篇文章中找到。

I suggest that you make a .gitignore file that includes everything other than the assets folder (all the other files that are originally inside a unity project). Next, you should place all your game projects in one folder. Next, duplicate the .gitignore in every single project folder for your games. This will exclude the libraries and unnecessary folders inside your projects other than the assets. If you have any projects you don't want, then put them in a new .gitignore inside where your game projects are stored. Note: You can have multiple .gitignore's and .gitignore is based on relative paths. I hope that helped!

除此之外,在Unity中使用git lfs也是很理想的。自从它问世以来,我一直在使用它,我没有遇到任何麻烦。

您需要将这个.gitattributes添加到.gitignore文件旁边

*.cs diff=csharp text
*.cginc text
*.shader text

*.mat merge=unityyamlmerge eol=lf
*.anim merge=unityyamlmerge eol=lf
*.unity merge=unityyamlmerge eol=lf
*.prefab merge=unityyamlmerge eol=lf
*.physicsMaterial2D merge=unityyamlmerge eol=lf
*.physicsMaterial merge=unityyamlmerge eol=lf
*.asset merge=unityyamlmerge eol=lf
*.meta merge=unityyamlmerge eol=lf
*.controller merge=unityyamlmerge eol=lf

*.a filter=lfs diff=lfs merge=lfs -text
*.mp3 filter=lfs diff=lfs merge=lfs -text
*.wav filter=lfs diff=lfs merge=lfs -text
*.aif filter=lfs diff=lfs merge=lfs -text
*.ttf filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
*.jpg filter=lfs diff=lfs merge=lfs -text
*.exr filter=lfs diff=lfs merge=lfs -text
*.fbx filter=lfs diff=lfs merge=lfs -text
*.FBX filter=lfs diff=lfs merge=lfs -text
*.rns filter=lfs diff=lfs merge=lfs -text
*.reason filter=lfs diff=lfs merge=lfs -text
*.lxo filter=lfs diff=lfs merge=lfs -text

这是我的滚动文件列表。如果使用未列出的其他二进制文件,请添加它们。

我也有文件配置使用yamlmerge,你需要设置这个。你可以在这里阅读:http://docs.unity3d.com/Manual/SmartMerge.html

只是补充一下吉提诺的主题。 推荐的方法只忽略Library和Temp,如果它在你的git项目的根目录内。如果你像我一样,有时需要统一项目成为回购的一部分,而不是整个回购,gitignore中正确的字符串将是:

**/[Tt]emp
**/[Ll]ibrary
**/[Bb]uild