Version: 2021.3
public static void Refresh (ImportAssetOptions options= ImportAssetOptions.Default);

描述

导入所有更改的资源。

此函数将导入已更改其内容修改数据或已在项目文件夹中添加/删除的所有资源。

此方法会隐式触发资源垃圾回收(请参阅 Resources.UnloadUnusedAssets)。

另请参阅:ImportAssetOptions

using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;

public class AssetDatabaseExamples : MonoBehaviour { [MenuItem("AssetDatabase/Refresh Example")] public static void RefreshExample() { var folderList = new List<string>{"Textures", "Models", "Sounds"}; foreach (var folder in folderList) { Directory.CreateDirectory($"Assets/{folder}"); }

foreach (var folder in folderList) { //Output will be false Debug.Log(AssetDatabase.IsValidFolder($"Assets/{folder}")); }

AssetDatabase.Refresh(); foreach (var folder in folderList) { //Output will be true Debug.Log(AssetDatabase.IsValidFolder($"Assets/{folder}")); } } }