Skip to main content

Class ScriptableObjectSettingsProvider<TSetting, C>

A helper class for displaying per-build-target ScriptableObject-based settings in the Unity Editor using the SettingsProvider interface.

public class ScriptableObjectSettingsProvider<TSetting, C> : SettingsProvider where TSetting : Settings<TSetting, C> where C : SettingsBuildTargetCollection<TSetting, C>

Type Parameters​

NameTypeDescription
TSettingThe specific settings type for each build target.
CThe settings collection type that holds settings for each build target.

Inheritance​

Constructors​

ScriptableObjectSettingsProvider(C, SettingsScope, string, IEnumerable<string>)​

Initializes a new instance of the ScriptableObjectSettingsProvider class.

public ScriptableObjectSettingsProvider(C settings, SettingsScope scope, string displayPath, IEnumerable<string> keywords = null)

Parameters​

NameTypeDescription
settingsCThe settings collection instance to display.
scopeSettingsScopeThe scope of the settings (User or Project).
displayPathstringThe display path for the settings in the Unity Settings window.
keywordsIEnumerable<string>Optional search keywords for filtering.

Fields​

BUILD_TARGET_NOT_SUPPORTED_TXT​

Message displayed when the settings are not applicable to the current build target.

protected const string BUILD_TARGET_NOT_SUPPORTED_TXT = "Settings currently not applicable to this platform."

Field Value​

string

m_SettingsWrapper​

Serialized object wrapper for the settings collection.

protected SerializedObject m_SettingsWrapper

Field Value​

SerializedObject

Methods​

GetBuildTargetSettings(BuildTargetGroup)​

Retrieves the settings associated with a specific build target group. If the settings do not exist, they are created and returned.

protected TSetting GetBuildTargetSettings(BuildTargetGroup buildTargetGroup)

Parameters​

NameTypeDescription
buildTargetGroupBuildTargetGroupThe build target group for which to retrieve settings.

Returns​

TSetting — The settings for the specified build target group, or null if not supported.

OnBuildTargetSettingsCollectionGUI()​

Draws the settings UI for the selected build target settings collection.

protected virtual void OnBuildTargetSettingsCollectionGUI()

OnGUI(string)​

Draws the settings UI for the selected build target in the Unity Editor.

public override void OnGUI(string searchContext)

Parameters​

NameTypeDescription
searchContextstringThe current search context in the settings window.

OnSelectedBuildTargetSettingsGUI(SerializedObject, BuildTargetGroup)​

Draws the inspector GUI for the selected build target setting asset.

protected virtual void OnSelectedBuildTargetSettingsGUI(SerializedObject serializedObject, BuildTargetGroup selectedBuildTarget)

Parameters​

NameTypeDescription
serializedObjectSerializedObjectThe serialized object representing the settings.
selectedBuildTargetBuildTargetGroupThe selected build target.

TryGetBuildTargetSettings(BuildTargetGroup, out TSetting)​

Tries to retrieve the settings for a specific build target group. If the settings exist, they are returned; otherwise, false is returned.

This is a safer version of GetBuildTargetSettings that avoids throwing errors if settings don't exist.

protected bool TryGetBuildTargetSettings(BuildTargetGroup buildTargetGroup, out TSetting settings)

Parameters​

NameTypeDescription
buildTargetGroupBuildTargetGroupThe build target group for which to try to retrieve settings.
settingsTSettingThe settings for the specified build target group, or null if not found.

Returns​

bool — True if settings were successfully retrieved, false if not.

  • Constructors
    • ScriptableObjectSettingsProvider(C, SettingsScope, string, IEnumerable<string>)
  • Fields
    • BUILD_TARGET_NOT_SUPPORTED_TXT
    • m_SettingsWrapper
  • Methods
    • GetBuildTargetSettings(BuildTargetGroup)
    • OnBuildTargetSettingsCollectionGUI()
    • OnGUI(string)
    • OnSelectedBuildTargetSettingsGUI(SerializedObject, BuildTargetGroup)
    • TryGetBuildTargetSettings(BuildTargetGroup, out TSetting)