使用此函数通知 SettingsService 有 SettingsProvider 发生更改。
当添加、移除或修改 SettingsProvider 并且需要刷新设置窗口时,管理 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(); } } }