logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Class SettingsAssetAuthoring

    Shared, engine-side (non-IMGUI) plumbing every single-settings-asset creation wizard needs: resolving the project-wide settings asset (explicit path, single existing asset, or none), Assets-path shape validation, recursive folder creation with a rollback-friendly created-paths trail, and a hardened asset-write check. Extracted from Serenity.GameProgress.Infrastructure.Editor.Builder.GameProgressCreator and Serenity.GameSave.Infrastructure.Editor.Builder.GameSaveCreator, which were byte-for-byte duplicating this exact logic. Serenity.Leaderboard.Infrastructure.Editor.Builder.LeaderboardCreator exposes ResolveSettingsContext publicly like every other adopter, and resolves-or-creates its settings asset through ResolveOrCreateAtPath<TSettings>(SettingsResolution<TSettings>, string, string, string, SerenityAssetCreationTransaction, out bool); its board-uniqueness and view/menu-option resolution live on top of both and this shared helper knows nothing about them.

    Inheritance
    object
    SettingsAssetAuthoring
    Inherited Members
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    Namespace: Serenity.StructuredPersistence.Infrastructure.Editor.Authoring
    Assembly: Serenity.UnityStructuredPersistence.Infrastructure.Editor.dll
    Syntax
    public static class SettingsAssetAuthoring

    Methods

    EnsureProjectFolderExists(string, ICollection<string>)

    Creates every missing segment of folderPath under the project's Assets folder, appending each newly created folder to createdPaths (shallowest first) so a caller's rollback can delete them in reverse order: assets first (appended last), then folders deepest-to-shallowest. A folder Unity's cache already reports as valid is left untouched. createdPaths takes any ICollection<T> — including Serenity.Global.Infrastructure.Editor.SerenityAssetCreationTransaction.FolderTracking — not just a concrete List<T>.

    Declaration
    public static void EnsureProjectFolderExists(string folderPath, ICollection<string> createdPaths)
    Parameters
    Type Name Description
    string folderPath
    ICollection<string> createdPaths

    IsWellFormedAssetsPath(string)

    Path-shape validation for a folder that will hold generated assets. A folder that does not exist yet is considered valid — EnsureProjectFolderExists(string, ICollection<string>) creates it during creation — this only rejects paths outside the project's Assets folder, or with empty/invalid segments.

    Declaration
    public static bool IsWellFormedAssetsPath(string path)
    Parameters
    Type Name Description
    string path
    Returns
    Type Description
    bool

    RequireProperty(SerializedObject, string)

    UnityEditor.SerializedObject.FindProperty(System.String) returns null — not an exception — for a field name that does not exist, so an unguarded chain like serializedObject.FindProperty("x").intValue = ... turns a renamed [SerializeField] into a NullReferenceException with no indication of which property or asset was involved. This resolves the property or throws a precise, self-diagnosing error instead.

    Declaration
    public static SerializedProperty RequireProperty(SerializedObject serializedObject, string propertyName)
    Parameters
    Type Name Description
    SerializedObject serializedObject
    string propertyName
    Returns
    Type Description
    SerializedProperty

    ResolveSettingsContext(string, string, string)

    Resolves the single project-wide settings asset of type settingsTypeName by its simple type name, for a caller whose assembly cannot reference the concrete settings type — the non-generic counterpart of ResolveSettingsContext<TSettings>(string, string). An explicit explicitSettingsAssetPath wins outright; otherwise a search — the whole project, or just searchRootFolder when given — returns the lone match, no match, or flags every path found when more than one exists. The resolved asset is loaded via UnityEditor.AssetDatabase.LoadMainAssetAtPath(System.String) since the concrete type is not known here.

    Declaration
    public static SettingsAssetAuthoring.SettingsResolution ResolveSettingsContext(string settingsTypeName, string explicitSettingsAssetPath, string searchRootFolder = null)
    Parameters
    Type Name Description
    string settingsTypeName
    string explicitSettingsAssetPath
    string searchRootFolder
    Returns
    Type Description
    SettingsResolution

    ResolveSettingsContext<TSettings>(string, string)

    Resolves the single project-wide TSettings asset: an explicit explicitSettingsAssetPath wins outright (a test seam and an already-known-asset fast path); otherwise a search — the whole project, or just searchRootFolder when given — returns the lone match, no match, or flags every path found when more than one exists (an ambiguity the caller must surface as an error). Delegates to the non-generic ResolveSettingsContext(string, string, string) overload by type name.

    Declaration
    public static SettingsAssetAuthoring.SettingsResolution<TSettings> ResolveSettingsContext<TSettings>(string explicitSettingsAssetPath, string searchRootFolder = null) where TSettings : Object
    Parameters
    Type Name Description
    string explicitSettingsAssetPath
    string searchRootFolder

    Test seam: narrows the scan to this single Assets-rooted folder instead of the whole project, so a test creating its own TSettings fixtures under a temp folder does not collide with a package-shipped singleton elsewhere in the project. Null (the default) scans the whole project, matching every caller before this parameter existed.

    Returns
    Type Description
    SettingsResolution<TSettings>
    Type Parameters
    Name Description
    TSettings

    ValidateResolution<TSettings>(SettingsResolution<TSettings>, string, string, string, SerenityCreationValidationResult, string)

    The validation pass every by-type settings wizard runs over its own ResolveSettingsContext<TSettings>(string, string) outcome: an ambiguous resolution is warned about and nothing else is checked, an already-resolved asset needs no target at all, and only a run that will genuinely create a new asset has its outputFolder shape validated.

    Extracted from the copy GameCameraSettingsCreator, SystemConfigurationSettingsCreator, GameGraphicsSettingsCreator, LocalizationSettingsAssetAuthoring, PrefetchPolicyCreator and LoggingProfileCreator each declare, which differ only in trivia: how the installer is named, whether it loads "every asset" or "every settings asset", and whether the reader is told which field to assign. The wording here is the most common of the six; the callers are migrated one by one, and their own tests adapt to it as they are.

    The ambiguity finding is a WARNING, not an error, in all six copies and here: more than one singleton is a project the author still has to sort out, but it does not stop this run from writing the asset it was asked for.

    Declaration
    public static void ValidateResolution<TSettings>(SettingsAssetAuthoring.SettingsResolution<TSettings> resolution, string moduleLabel, string displayName, string outputFolder, SerenityCreationValidationResult result, string explicitAssignmentHint = null) where TSettings : Object
    Parameters
    Type Name Description
    SettingsResolution<TSettings> resolution

    The outcome of this wizard's own ResolveSettingsContext<TSettings>(string, string) call.

    string moduleLabel

    The Addressables label the module's installer scans for, e.g. ModuleLabels.GAME_CAMERA.

    string displayName

    The module's name as an author reads it, e.g. "GameCamera" — it names both the installer and the asset the folder would hold.

    string outputFolder

    The folder a new asset would be created in, checked only when the run will actually create one.

    SerenityCreationValidationResult result

    The findings collector this pass reports into.

    string explicitAssignmentHint

    The name of the field an author would set to resolve the ambiguity, e.g. "SettingsAssetPath". Null (the default) keeps today's canonical sentence, which names no field.

    Type Parameters
    Name Description
    TSettings

    VerifyAssetWasWrittenToDisk(string)

    UnityEditor.AssetDatabase.CreateAsset(UnityEngine.Object,System.String) logs a native engine error rather than throwing when its destination folder is valid in Unity's cache but has actually been removed from disk. This turns that silent failure into a genuine, catchable exception so a caller's rollback triggers deterministically instead of reporting success over a half-written project.

    Declaration
    public static void VerifyAssetWasWrittenToDisk(string assetPath)
    Parameters
    Type Name Description
    string assetPath
    In this article
    © 2026 Serenity. All Rights Reserved