Version: 5.3 (switch to 5.4b)
Аргументы командной строки
AssetDatabase

За кулисами

Unity автоматически импортирует ассеты и управляет различными видами дополнительной информации о них. Ниже идёт описание того как это происходит.

What happens when Unity imports an Asset?

1. A Unique ID is assigned

When you place an Asset such as a texture in the Assets folder, Unity will first detect that a new file has been added (the editor frequently checks the contents of the Assets folder against the list of assets it already knows about).

The first step Unity takes it to assign a unique ID to the asset. This ID is used internally by Unity to refer to the asset which means the asset can be moved or renamed without references to the asset breaking.

2. A .meta file is created

The relationship between the Assets Folder in your Unity Project on your computer, and the Project Window within Unity
The relationship between the Assets Folder in your Unity Project on your computer, and the Project Window within Unity

You’ll notice in the image above that there are .meta files listed in the file system for each asset and folder created within the Assets folder. These are not visible in Unity’s Project Window. Unity creates these files for each asset, but they are hidden by default, so you may not see them in your Explorer/Finder either. You can make them visible by selecting this option in Unity: Edit > Project Settings > Editor > Versions Control, Mode : Visible Meta Files.

The ID that Unity assigns to each asset is stored inside the .meta file which Unity creates alongside the asset file itself. This .meta file must stay with the asset file it relates to.

IMPORTANT: .meta files must match and stay with their respective asset files. 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 the Mac), 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. Unity would generate a new .meta file for the moved/renamed asset as if it were a brand new asset, and delete the old “orphaned” .meta file.

For example, 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.

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

3. The source asset is processed

Unity reads and processes any files that you add to the Assets folder, converting the contents of the file to internal game-ready versions of the data. The actual asset files remain unmodified, and the processed and converted versions of the data are stored in the project’s Library folder.

Использование внутреннего формата для ассетов позволяет Unity сохранять дополнительные данные, называемые метаданными (metadata), которые позволяют сделать работу с ассетами удобнее. Для примера, файлы формата Photoshop весьма удобны для работы, но они не поддерживает такую возможность как мипмап (mip maps). Внутренний формат Unity, однако, может добавить дополнительные возможности любым типам ассетов. Все метаданные ассетов хранятся в папке “Library”. Как пользователь, вы никогда не должны изменять папку Library вручную и попытка сделать это может повредить проект.

Sometimes multiple assets are created from an import

Some asset files can result in multiple assets being created. This can occur in the following situations:

  • A 3D file, such as an FBX, defines Materials and/or contains embedded Textures.
    In this case, the defined Materials and embedded textures are extracted and represented in Unity as separate assets.

  • An image file imported as multiple sprites.
    It’s possible to define multiple sprites from a single graphic image, by using Unity’s Sprite Editor. In this case, each sprite defined in the editor will appear as a separate Sprite asset in the Project window.

  • A 3D file contains multiple animation timelines, or has multiple separate clips defined within its animation import settings.
    In this situation, the multiple animation clips will appear as separate Animation Clip assets in the project window.

The import settings can alter the processing of the asset

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 when you have an asset selected in your project window. For a texture, this includes settings such as the Texture Type, Wrap Mode, Filter Mode and Aniso Level.

If you change the import settings for an asset, those changed settings are stored in the .meta file accompanying the asset. The asset will be re-imported according to your new settings, and the corresponding imported “game-ready” data will be updated in the project’s Library folder.

При создании резервной копии проекта, вам всегда следует копировать главную папку проекта Unity, содержащую и папку Assets и папку Library. Вся информация в подпапках имеет ключевое значение для работы Unity.

Note: Projects created in Unity 4.2 and earlier may not have .meta files if not explicitly enabled. Deleting the Library folder in these projects will lead to data loss and permanent project corruption because both the generated internal formats of your assets and the meta data were stored in the Library folder.

Аргументы командной строки
AssetDatabase