preface

Organize the directory structure of a project, is to maintain an important point of the project, we study the source code, others understand others design begins with a directory structure, a clear directory structure, development and maintenance of the project, project management is very important, directory maintenance of good, we work together very happy, directory maintenance is not good, There’s a risk of messing up the project.

Today we’ll take a look at how Unity architects maintain their own directory structures, and see how many of them are in common with you.

1: Basic principles of Unity projects

The principle of (1) :

** Does not include any nodes in the scene except the startup node. **Unity provides a convenient scene editor, as if we drag and drop directly into the scene to build the scene and then switch scenes, which we didn’t advocate when we opened the project. This has two disadvantages :**A:** It is not convenient for multiple people to edit the scene at the same time after the code submission and merge, if there is A conflict is more troublesome. B: It is not convenient to empty the package. All nodes are in the scene. Resources dependent on nodes are packed into the package. C: It is easy to maintain. It is known who has maintained complex scenarios.

The principle of (2) :

** Do not directly hang logical code components on nodes or preforms. * * this is easy to understand, if we directly on the nodes or prefabricated body hanging code components, the code is very difficult to maintain, if we are going to search which code where the call, can’t check it by searching, if one node, a point of a prefabricated body open to find, so that to maintain very trouble, don’t heat more convenient resource update and code.

(3)

Do not drag nodes, components, or resources directly to the properties editor of the code logic component. For example, attach the response function directly to the Button component. Principle 2 ensures that principle (3)** does not appear, but I must emphasize it.

The reason is that it is not easy to maintain code and collaborate with multiple people for development and submission.

(4)

Run only one scene, all content code control.

There is no content allowed in the scene, so there is no point in doing a scene switch, so we only have a run-time scene. All the content, we have to generate through the code, so that the search code, maintenance code can see the entire game logic. Other scenes can be used to edit maps, edit characters, etc. After editing, generate a prefab of resources one by one. So an empty scene at runtime in our project, and other resource editor level editing scenes, which are used to edit the resource map, will not be packaged.

The principle of (5)

Use pure AssetsBundles to manage the loading and unloading of the entire resource without using the Resouces mechanism.

Why not use the Resources mechanism to load and unload Resources? Resources mechanism is not easy to update Resources, it is not easy to empty the package, all Resources under Resources and related dependencies will be packaged. Resources are not easy to update, so use pure AssetsBundle to load and uninstall Resources, which is convenient for empty packages and easy to update Resources. If you do not empty the package, just put the packaged AB package into StreammingAssets directory. All the resources in this directory will be packaged and then go here to read the AB package.

The principle of (6)

The directory structure of third-party resources and plug-ins should be placed in the same folder.

We often need to use Unity plug-ins to complete a Unity project, and Unity plug-ins are developed from their own perspective, so the directory structure may be inconsistent with our project directory structure concept maintenance, so we need to sort out third-party plug-ins, and may include code.

2: Unity project’s level 1 directory structure

Level 1 directory structure is as follows:

AssetsPackages: Store all game resources in this directory. Editor: Framework and project Editor extension code. Scenes: All game Scenes, including running Scenes, map editing Scenes, character editing Scenes, special effects editing Scenes. Scripts: All game code, including framework and game logic code. 3rd: Location of the third-party plug-in. SteammingAssets: Stores the packed AB resource package, so that the AB package can be inserted into the installation package.

3: primary directory structure Subdirectory structure

1: How to classify AssetsPackage directory?

AssetsPackage stores all resources, and how resources are classified determines the resource management when ab package is made. Therefore, we try our best to classify resources according to their functions, so I will divide AssetsPackage into main subdirectories.

AssetsPackage/GUI: Store the GUI pictures of each UI interface, etc. AssetsPackage/Sounds: Store the game’s music and sound effects. AssetsPackage/Charactors: deposit character animation and related resources. AssetsPackage/Effects: Stores resources related to particle Effects. AssetsPackage/Excels: stores table data of game configuration files.

2: How to classify the Scripts directory?

Scripts is the folder that the body of the code maintains, and the classification of that folder is actually very important, and this is what I do here. 3rd: used to store pure third party C# code, not plugins such as protobuf for C# etc. Scripts/Managers: Used to store major management module code (resource management, network module, sound module, etc.) Scripts/AssetsBundle: code related to Ab resource pack management updates. …

3: How to classify directories in the Editor?

Editor is the directory where the Editor extension codes are placed. I sorted the corresponding Editor extension codes according to their functions and extended modules, as follows:

Editor/AssetBundle: Editor extension ab package automation, version management, Editor related code; Editor/Common: Common code for some Editor extensions. Editor/ExcelBuild: table manipulation tool code; Editor/PackageBuild: Tool code for packaging…

Put your Editor extension tools and features in the Editor directory.

4: AssetBundles output directory structure

The entire project adopts the AssetsBundle resource management mode, so the outgoing AssetsBundle package also has a corresponding directory structure. This directory structure is not placed in the Assets folder of the Unity project, but in the same position as the Assets folder, as shown in the figure:

The AB packages of each platform and channel are different, so in AssetsBundle, we need to package them by channel and platform. Therefore, under the AssetBundles path, the platform is divided first, and then the channel. AssetBundles AssetBundles/iOS/Android/XXXX platform/XXXX platform

Of course these are best done automatically when making AssetBundles.

The last

Today’s Unity framework directory structure classification and management, to introduce to you here, is mainly introduced to manage the project directory structure of some ideas, and your project how much is consistent with it?