Version: 2022.3

SettingsProviderAttribute

class in UnityEditor

切换到手册

描述

用于注册新 SettingsProvider 的属性。使用此属性可以修饰返回 SettingsProvider 实例的函数。如果函数返回 null,则 Settings 窗口中不会显示 SettingsProvider。

using System.IO;
using System.Linq;
using UnityEditor;

class MyCustomSettingsProvider : SettingsProvider { const string k_MyCustomSettingsPath = "Resources/MyCustomSettings.asset"; public MyCustomSettingsProvider(string path, SettingsScope scope) : base(path, scope) {}

public static bool IsSettingsAvailable() { return File.Exists(k_MyCustomSettingsPath); }

[SettingsProvider] public static SettingsProvider CreateMyCustomSettingsProvider() { if (IsSettingsAvailable()) { return new MyCustomSettingsProvider("MyCustomSettings", SettingsScope.Project); }

// Settings Asset doesn't exist yet. No need to display anything in the Settings window. return null; } }

构造函数

SettingsProviderAttribute创建用于注册新 SettingsProvider 的 SettingsProviderAttribute。