Version: 2022.3

SettingsProviderGroupAttribute

class in UnityEditor

切换到手册

描述

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

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

class XRSettings : SettingsProvider { const string k_XRSettingsFolder = "Assets/Editor/XRSettings"; public XRSettings(string path, SettingsScope scope = SettingsScope.Project) : base(path, scope) { }

[SettingsProviderGroup] public static SettingsProvider[] CreateProviders() { var files = Directory.GetFileSystemEntries(k_XRSettingsFolder, "*.json"); return files.Select(entry => { // First parameter is the path of the settings in the Settings window. return new XRSettings("Project/XRSettings/" + Path.GetFileNameWithoutExtension(entry)); }).ToArray(); } }

构造函数

SettingsProviderGroupAttribute创建用于注册多个 SettingsProvider 的 SettingsProviderGroupAttribute。