Version: 2022.3

AssetDatabase.StopAssetEditing

切换到手册
public static void StopAssetEditing ();

描述

停止将资源导入到资源数据库中。这可用于将多个资源导入组合成一个更大的导入。

**注意:**
调用 AssetDatabase.StartAssetEditing() 会将资源数据库置于阻止导入的状态,直到调用 AssetDatabase.StopAssetEditing()。 这意味着如果在两个函数调用之间发生异常,则 AssetDatabase 会无响应。 因此,强烈建议根据需要将对 AssetDatabase.StartAssetEditing() 和 AssetDatabase.StopAssetEditing() 的调用置于 try..catch 代码块或 try..finally 代码块中。

using UnityEngine;
using UnityEditor;

public class StartStopAssetEditingExample : MonoBehaviour { [MenuItem("APIExamples/StartStopAssetEditing")] static void CallAssetDatabaseAPIsBetweenStartStopAssetEditing() { try { //Place the Asset Database in a state where //importing is suspended for most APIs AssetDatabase.StartAssetEditing();

AssetDatabase.CopyAsset("Assets/CopyAsset.txt", "Assets/Text/CopyAsset.txt"); AssetDatabase.MoveAsset("Assets/MoveAsset.txt", "Assets/Text/MoveAsset.txt"); } finally { //By adding a call to StopAssetEditing inside //a "finally" block, we ensure the AssetDatabase //state will be reset when leaving this function AssetDatabase.StopAssetEditing(); } } }