Version: 2020.3
导入器一致性
资源数据库

Asset Metadata

When Unity imports assets, it also stores and manages additional data about the asset for you, such as what import settings should be used to import the asset, and where the asset is used throughout your project. Below is a description of how this process works:

  1. Unity assigns the asset a unique ID.
  2. Unity creates a .meta file to accompany the asset file.
  3. Unity processes the asset.

The Import settings for any given asset affects how Unity processes the asset. If you modifying the asset file, or any of the asset’s import settings, Unity will reimport the asset. For more information, see Assets and their import settings.

唯一 ID

Assets 文件夹中放置诸如纹理之类的资源时,Unity 将检测到已添加新文件,因为 Editor 经常根据已知的资源列表来检查 Assets 文件夹的内容。

Unity 找到新文件时会向此资源分配唯一 ID。这是 Unity 在内部使用的 ID,用于引用资源,以便 Unity 可以移动或重命名此资源而不会破坏任何内容。

The IDs are not normally visible in the Editor,

Meta files

The image below shows .meta files that Unity creates for each item in your project’s Assets folder. Unity creates meta files for asset files and folders.

They are hidden in Unity’s Project window, and you may also find they are hidden in your file system by default, so you may not see them in Windows Explorer or Finder unless you make your hidden files visible on your computer.

The relationship between the Assets folder in your Unity project on your computer, meta files, and the Project window in Unity
The relationship between the Assets folder in your Unity project on your computer, meta files, and the Project window in Unity

此示例表明,Unity 为项目的 Assets 文件夹中的每个资源或文件夹创建了一个 .meta 文件,就像它们出现在系统文件浏览器中一样。然而,这些 .meta 文件在 Project 窗口中不可见,因为默认情况下,它们会被隐藏。您可以显示这些文件,方法是从 Mode 项目设置中选择 Visible Meta Files

When Unity creates a .meta file for an asset, it writes the asset’s ID inside the .meta file and stores the .meta file in the same location as the asset file.

As well as the unique ID assigned to the asset, the .meta files contain values for all the import settings you see in the Inspector window when you select an asset in your Project window. For example, for a Texture, this includes the Texture Type, Wrap Mode, Filter Mode and Aniso Level import settings.

如果更改资源的导入设置,则这些新设置将保存到资源附带的 .meta 文件中。随后,Unity 将根据更新的设置来重新导入资源,并在项目的 Library 文件夹中更新相应导入的“游戏就绪”数据。

Important: Meta files contain important information about how the asset is used in the Project and they must stay with the asset file they relate to. If you move or rename an asset within Unity’s own Project window, Unity will also automatically move or rename the corresponding .meta file. If you move or rename an asset outside of Unity (i.e. in Windows Explorer, or Finder on macOS), you must move or rename the .meta file to match.

If an asset loses its meta file (for example, if you moved or renamed the asset outside of Unity, without moving/renaming the corresponding .meta file), any reference to that asset will be broken in your project. In this situation, Unity would notice the asset does not have a corresponding meta file and generate a new one for the moved/renamed asset as if it were a brand new asset, and delete the old “orphaned” .meta file.

As an example of the types of problems this could cause, in the case of a texture asset losing its .meta file, any materials which used that texture will now have no reference to that texture. To fix it you would have to manually re-assign that texture to any materials which required it.

Or, in the case of a script asset losing its .meta file, any GameObjects or Prefabs which had that script assigned would end up with an “unassigned script” component, and would lose their functionality. You would have to manually re-assign the script to these objects to fix this.

Empty folders, meta files, and version control

在 Unity 中,项目 Assets 文件夹中的文件夹分配有自己的 .meta 文件 - 但是一些版本控制系统 (VCS) 不能存储空文件夹。这意味着当您从项目中添加或删除一个空文件夹时,您的 VCS 会将 .meta 文件存储为添加或删除,但不会存储添加或删除文件夹本身的更改,这可能会造成混淆或产生问题。

为帮助解决此问题,Unity 针对空文件夹采用以下特定方式:

如果 Unity 检测到一个空文件夹不再含有相应的元文件,如果该文件夹以前有元文件,Unity 会假设元文件被另一个用户通过在 VCS 中删除该文件夹时删除,并在本地删除该空文件夹。

如果 Unity 检测到文件夹有一个新的元文件,但该文件夹在本地不存在,则 Unity 会假设新元文件是被另一个用户通过在 VCS 中添加文件夹而创建,并在本地创建相应的空文件夹。

导入器一致性
资源数据库