Version: 2022.3

SettingsService.NotifySettingsProviderChanged

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

描述

使用此函数可向 SettingsService 通知有 SettingsProvider 更改。

在添加、删除或修改 SettingsProvider 并需要刷新 Settings 窗口时,负责管理 SettingsProvider 的客户端应调用此函数。

using System.Linq;
using UnityEditor;

class MyCustomSettingsProcessor : AssetPostprocessor { const string k_MyCustomSettingsPath = "Resources/MyCustomSettings.asset"; static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { var settingsTouched = importedAssets.Any(a => a.Contains(k_MyCustomSettingsPath)); settingsTouched = settingsTouched || deletedAssets.Any(a => a.Contains(k_MyCustomSettingsPath)); settingsTouched = settingsTouched || movedAssets.Any(a => a.Contains(k_MyCustomSettingsPath)); settingsTouched = settingsTouched || movedFromAssetPaths.Any(a => a.Contains(k_MyCustomSettingsPath));

if (settingsTouched) { // Notify the SettingsWindow that MyCustomSettings has been removed or added. This tells the SettingsWindow to Add/Remove // a new Settings section. SettingsService.NotifySettingsProviderChanged(); } } }