Version: 2022.1

AssetPostprocessor.OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths, bool didDomainReload)

切换到手册

参数

importedAssets Array of paths to imported assets.
deletedAssets Array of paths to deleted assets.
movedAssets Array of paths to moved assets.
movedFromAssetPaths Array of original paths for moved assets.
didDomainReload Boolean set to true if there has been a domain reload.

描述

在完成任意数量的资源导入后(当资源进度条到达末尾时)调用此函数。

此调用可以在手动重新导入后进行,也可以在您将资源或资源文件夹移动到 Project 窗口中的新位置后进行。每个字符串数组项都包含一个相对于 Project 根目录下的 Assets 文件夹的文件路径。importedAssets 包含操作中使用的所有资源的路径。movedAssetsmovedFromAssetPaths 的每个连续索引引用同一资源。

如果对多个单独的资源(而非包含这些资源的文件夹)执行批量操作,则系统会针对每个资源调用一次此函数,且每个单独的资源在各个数组中都是唯一项。

OnPostProcessAllAssets is called when the asset database finishes importing assets. You can safely perform any asset database operations from within this callback, such as loading, importing, moving or deleting assets.

OnPostProcessAllAssets should be used for initialization after a domain reload, if the initialization requires asset operations like loading of assets. didDomainReload parameter can be checked whether there has been a domain reload. All domain reloads will cause OnPostprocessAllAssets to be called.

Note: If your code causes any new asset imports during this callback, OnPostProcessAllAssets will be called again once those new imports are complete.

请注意,必须将此函数声明为 /static/,即,如果将其声明为实例函数,将无法正确调用此函数。

The order specified by GetPostprocessOrder does not affect this function, instead the order can be controlled by defining dependencies using the following attributes: RunAfterClassAttribute, RunBeforeClassAttribute RunAfterAssemblyAttribute, RunBeforeAssemblyAttribute RunAfterPackageAttribute, RunBeforePackageAttribute Note: A version of this callback without the didDomainReload parameter is also available (OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths))

using UnityEngine;
using UnityEditor;

class MyAllPostprocessor : AssetPostprocessor { static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths, bool didDomainReload) { foreach (string str in importedAssets) { Debug.Log("Reimported Asset: " + str); } foreach (string str in deletedAssets) { Debug.Log("Deleted Asset: " + str); }

for (int i = 0; i < movedAssets.Length; i++) { Debug.Log("Moved Asset: " + movedAssets[i] + " from: " + movedFromAssetPaths[i]); }

if (didDomainReload) { Debug.Log("Domain has been reloaded"); } } }