We create a 2d project through Dashboard to demonstrate the project structure of CocosCreator.
After the creation is completed, you will get the following project:
1. assets folder
assets folder : It is a resource directory, used to store all local resources, such as various pictures and script resources.
Only the content in this directory will be displayed in the resource manager of the cocos editor.
One very important point is that after importing each file in assets, a .meta file with the same name as the file will be generated.
1. The role of meta files
Understanding the role and update timing of meta files is of great significance for us to solve problems such as resource conflicts, file loss, and component attribute loss.
For example, we create a folder named script in the resource manager of the cocos editor to store script files.
After the creation is completed, a script.meta file with the same name as the file will be generated:
script.meta file content:
Contains ver (version), uuid (unique id), importer (resource type) and other parameters.
Let’s import another image resource:
The meta file generated by image resources has a lot of content. In addition to the basic information such as ver
and uuid
, it also records the size, offset, grid and other data of the image.
as follows:
{
"ver": "1.0.26",
"importer": "image",
"imported": true,
"uuid": "dadcda60-4fe7-4bdb-86cd-46dbf91c97d4",
"files": [
".jpg",
".json"
],
"subMetas": {
"6c48a": {
"importer": "texture",
"uuid": "dadcda60-4fe7-4bdb-86cd-46dbf91c97d4@6c48a",
"displayName": "20230816090210",
"id": "6c48a",
"name": "texture",
"userData": {
"wrapModeS": "clamp-to-edge",
"wrapModeT": "clamp-to-edge",
"imageUuidOrDatabaseUri": "dadcda60-4fe7-4bdb-86cd-46dbf91c97d4",
"isUuid": true,
"visible": false,
"minfilter": "linear",
"magfilter": "linear",
"mipfilter": "none",
"anisotropy": 0
},
"ver": "1.0.22",
"imported": true,
"files": [
".json"
],
"subMetas": {}
},
"f9941": {
"importer": "sprite-frame",
"uuid": "dadcda60-4fe7-4bdb-86cd-46dbf91c97d4@f9941",
"displayName": "20230816090210",
"id": "f9941",
"name": "spriteFrame",
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 900,
"height": 1100,
"rawWidth": 900,
"rawHeight": 1100,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"packable": true,
"pixelsToUnit": 100,
"pivotX": 0.5,
"pivotY": 0.5,
"meshType": 0,
"vertices": {
"rawPosition": [
-450,
-550,
0,
450,
-550,
0,
-450,
550,
0,
450,
550,
0
],
"indexes": [
0,
1,
2,
2,
1,
3
],
"uv": [
0,
1100,
900,
1100,
0,
0,
900,
0
],
"nuv": [
0,
0,
1,
0,
0,
1,
1,
1
],
"minPos": [
-450,
-550,
0
],
"maxPos": [
450,
550,
0
]
},
"isUuid": true,
"imageUuidOrDatabaseUri": "dadcda60-4fe7-4bdb-86cd-46dbf91c97d4@6c48a",
"atlasUuid": ""
},
"ver": "1.0.12",
"imported": true,
"files": [
".json"
],
"subMetas": {}
}
},
"userData": {
"type": "sprite-frame",
"fixAlphaTransparencyArtifacts": true,
"hasAlpha": false,
"redirect": "dadcda60-4fe7-4bdb-86cd-46dbf91c97d4@f9941"
}
}
Among all the information above, we only need to care about: UUID
UUID is the unique ID of each file. The Creator engine refers to files through UUID to implement game resource management.
2. .meta file update timing
(1) When opening the project
When opening a project, Creator will first scan the assets directory. If any file does not have a meta file, it will be generated at this time.
(2) When updating resources
- When modifying file names, changing directories, adding files, or deleting files to resources in the resource manager.
- After adding, deleting, or modifying files in the assets directory in the file manager of the operating system, switch to the editor interface.
If the meta file of a file or directory does not exist, the above two situations will trigger the engine to generate a new meta file.
3. Solutions to .meta file errors
(1), UUID changes problem
This situation usually occurs when multiple people collaborate. When the UUID changes, the resource corresponding to the old UUID cannot be found, and the editing interface may lose resources and pictures, and may also lose component attributes.
As shown in the picture:
Reason for UUID change:
The previous person added new resources to the project, but forgot to switch to the editor interface to generate meta files, and at the same time submitted the newly added files to version management (meta files were not included).
Another person in the back updates the resource submitted by the previous person, and switches to the editor interface for editing at the same time. Creator will check that the new resource has no meta file and will generate it immediately.
When the first person switches to the editor, a meta file will also be generated, so that the two people's computers are the same file, but the UUIDs in the generated meta files are different.
In this way, people who submit or update resources later will definitely encounter conflicts.
Solutions and precautions for UUID changes:
- Check whether there are new files before submitting. If there are new files, pay attention to whether there are meta files. If there is no meta file, you must reopen the cocos editor to generate a new meta file, and then submit it together.
- If you find only a new meta file when submitting, then this meta file must be generated by yourself, and you need to check whether the resources corresponding to this meta file have been used. If it has not been used, please submit the meta file as the earliest submitter. Never submit this meta file at this time. **
- When pulling files, pay attention to whether there are new files, and there are meta files in pairs. If not, remind the previous file submitters to submit the meta files together.
(2) UUID conflict problem
UUID is globally unique, and conflicts must be caused by different files with the same UUID. Once this problem occurs, the directory structure of the Cocos Creator Explorer will be incompletely loaded.
Cause of UUID conflict problem: UUID conflict is usually caused by misoperation.
For example, when moving files in the file manager of the operating system, cutting and pasting are accidentally changed to copy and paste, and the meta file is also copied. As a result, two identical meta files appear in the project at the same time.
You can see the conflicting UUID strings from the prompt above.
UUID conflict resolution:
The first step is to open the operating system file manager or code editor and search for conflicting UUIDs, as shown in the figure:
The second step is to close the Cocos Creator editor and delete any meta file.
The third step is to reopen the Creator editor to solve the problem.
The fourth step , although through the above three steps, solves the problem of incomplete loading of the directory structure. However, where the editor references this resource, the resource will be lost, so the resource needs to be re-edited or reconfigured.
In order to avoid UUID conflicts, it is best to add and move files in the engine resource management tool.
2. Library folder
library
It is assets
generated after importing the resources in . The structure of the file and the format of the resources will be processed into the form required when the final game is released.
When library
it is lost or damaged, just delete the entire library
folder and open the project again, and the resource library will be regenerated.
3. Build target (build)
After using the project in the main menu of the editor -> Build Publish to publish the project using the default release path, the editor will create build
a directory under the project path and store the build projects of all target platforms.
For example, we build a web mobile project.
4. Editor configuration directory (profiles)
profiles
The folder contains the configuration information of the editor, including the build configuration information and scene configuration information of each target platform, etc.
![Insert image description here](https://img-blog.csdnimg.cn/4d6d5a71f3a84272850ba180a6656d05.png)
5. Project settings directory (settings)
The settings folder saves project-related settings, such as configuration information in the project settings panel.
6. Temporary folder (temp)
temp
As the name suggests, it is a temporary folder used to cache Cocos Creator's local temporary data files. It can be deleted manually after closing Cocos Creator.
Seven, package.json
package.json
Files and assets
folders together are the signs to verify the legality of Cocos Creator projects, and only folders containing these two contents can be opened as Cocos Creator projects.
8. tsconfig.json
The tsconfig.json file has been touched before when we introduced the vs code configuration api smart prompt.
9. Extensions folder (extensions)
extensions
The folder is used to store custom extensions for the project. If you need to uninstall the extension, extensions
just delete the corresponding folder in .