Unity3D + Git = Swag Concept | Infogen Labs
Ciklum India
We develop Digital Solutions for Fortune 500 and fast-growing organisations alike around the world.
Problem Statement:
By default, the Unity editor does not work well with Git. To name a few problems:
The Solution:
You’ll find that, in any ordinary Unity project, there are quite a lot of files and folders, good news that only three folders should be kept under source control: Assets, Packages, and ProjectSettings. The solution is straightforward:
1.??Add Unity-specific .gitignore settings
2.??Configure Unity for version control
3.??Proper resolving Merge Conflicts
1. Add Unity-specific .gitignore Settings
The .gitignore file is a metadata file that controls how Git operates on your repository. Files listed in .gitignore will be — like the name implies — ignored. They won’t show up in git status and they won’t be added to the repository. Set up an ignore (.gitignore, you can download from here) filter for the unnecessary folders and files.
2. Configure Unity For Version Control
Before checking your project in, you have to tell Unity to modify the project structure slightly to make it compatible with storing assets in an external version control system. This will show a text file for every asset in the Assets directory containing the necessary bookkeeping information required by Unity.
The files will have a .meta file extension with the first part being the full file name of the asset it is associated with. Moving and renaming assets within Unity should also update the relevant .meta files. However, if you move or rename assets from an external tool, make sure to synchronize the relevant .meta files as well.
To create your own source control repository please visit: Creating Your First Source Control Repository
3. Proper Resolving Merge Conflicts
Manually resolving merge conflicts between Unity-generated YAML files is very difficult and error-prone. The Unity editor is translating our commands and our knowledge into a language (the Unity YAML format) that is difficult to understand, and indeed that was not really meant to be manipulated directly.
?By default, Git is totally unaware of the type of content that you’re checking in. If a file is changed in two different branches, it will try to merge the file just by looking at the lines, without understanding them. The metadata file that Git uses is called .gitattributes. In gitattributes you can configure how files are merged when two people change the same file in two different branches.?This means that you can set up Unity’s “Smart Merge” functionality.
?Using Unity Smart Merge
Unity incorporates a tool called UnityYAMLMerge that can merge scene and prefab files in a semantically correct way. The tool can be accessed from the command line and is also available to third-party version control software. If you are using Unity 5 or later, you can use the editor’s Smart Merge (a.k.a, “Unity YAML Merge”).
领英推荐
In the Editor Settings (menu: Edit > Project Settings > Editor), you have the option to select a third party version control tool (Perforce or PlasticSCM, for example). When one of these tools is enabled, you will see a Smart Merge menu under the Version Control heading. The menu has four options:
?Setting up UnityYAMLMerge for Use with Third Party Tools
The UnityYAMLMerge tool is shipped with the Unity editor; assuming Unity is installed in the standard location, the path to UnityYAMLMerge will be:
…on Windows and
…on Mac OSX (use the Show Package Contents command from the Finder to access this folder).
UnityYAMLMerge is shipped with a default fallback file (called mergespecfile.txt, also in the Tools folder) that specifies how it should proceed with unresolved conflicts or unknown files. This also allows you to use it as the main merge tool for version control systems (such as git) that don’t automatically select merge tools based on file extensions. The most common tools are already listed by default in mergespecfile.txt but you can edit this file to add new tools or change options.
Add the following text to your .git or .gitconfig file:
Zinject: Dependency Injection Framework for Unity3D
Fortunately, a code-centric approach to Unity development (ex., via Zenject) can minimize these kinds of problems, while also supporting numerous software development best practices that are often lacking in Unity development.
Zenject is a lightweight dependency injection framework built specifically to target Unity 3D (however it can be used outside of Unity as well). It can be used to turn your application into a collection of loosely-coupled parts with highly segmented responsibilities. Zenject can then glue the parts together in many different configurations to allow you to easily write, re-use, refactor and test your code in a scalable and extremely flexible way.
Conclusion
?Visit Us:?corp.infogen-labs.com?
DevOps Engineer at JetSynthesys Pvt. Ltd.
2 年Nice blog