logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Class RecipeSectionImporterBase

    Shared base for section importers. Centralises enum parsing and the idempotent create-or-update ("upsert") of a UnityEngine.ScriptableObject that carries Serenity's IFoundationSettings identity, so concrete importers only describe how to populate their fields.

    Inheritance
    object
    RecipeSectionImporterBase
    AudioClipRecipeImporter
    CutsceneRecipeImporter
    DeferredSectionImporter
    FeedbackRecipeImporter
    GenericAssetRecipeImporter
    MenuRecipeImporter
    ModalRecipeImporter
    MusicTrackRecipeImporter
    Implements
    ISerenityRecipeSectionImporter
    Inherited Members
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    Namespace: Serenity.ProjectRecipe.Infrastructure.Editor.Importers
    Assembly: Serenity.UnityProjectRecipe.Infrastructure.Editor.dll
    Syntax
    public abstract class RecipeSectionImporterBase : ISerenityRecipeSectionImporter

    Constructors

    RecipeSectionImporterBase()

    Declaration
    protected RecipeSectionImporterBase()

    Properties

    IsSupported

    Declaration
    public virtual bool IsSupported { get; }
    Property Value
    Type Description
    bool

    True when this section produces real assets; false for deferred/reported-only sections.

    Order

    Declaration
    public virtual int Order { get; }
    Property Value
    Type Description
    int

    Execution order (ascending). Typed sections run first, the generic assets section after them so its references to generated assets resolve, and the deferred reporter last. Importers are discovered by reflection and sorted by this value, so a new section just picks an order without touching the engine.

    SectionName

    Declaration
    public abstract string SectionName { get; }
    Property Value
    Type Description
    string

    The recipe section this importer handles (used for reporting), e.g. audioClips.

    Methods

    Import(SerenityRecipeImportContext)

    Creates or updates this section's assets. In a dry run the context suppresses writes, so this only resolves and records the would-be outcomes. Not called when the report has blockers.

    Declaration
    public abstract void Import(SerenityRecipeImportContext context)
    Parameters
    Type Name Description
    SerenityRecipeImportContext context

    The shared import context.

    TryParseEnum<TEnum>(string, TEnum, out TEnum)

    Parses an enum value from its name. An empty/whitespace string is treated as "not specified" and leaves value at the supplied fallback without error.

    Declaration
    protected static bool TryParseEnum<TEnum>(string raw, TEnum fallback, out TEnum value) where TEnum : struct
    Parameters
    Type Name Description
    string raw

    The enum name from the recipe.

    TEnum fallback

    The value to use when raw is empty.

    TEnum value

    The parsed value, or the fallback.

    Returns
    Type Description
    bool

    True when the value was empty (fallback) or parsed successfully; false on an invalid name.

    Type Parameters
    Name Description
    TEnum

    The enum type.

    TryUpsertByType(SerenityRecipeImportContext, string, string, Type, Action<ScriptableObject>, bool)

    Type-driven variant of TryUpsert<T>(SerenityRecipeImportContext, string, string, Action<T>, bool) for importers that resolve the asset type at runtime (the generic section). Same idempotency contract: wrong type → skip, existing → update with GUID preserved, absent → create; dry run records the outcome without touching assets.

    Declaration
    protected bool TryUpsertByType(SerenityRecipeImportContext context, string id, string relativeOutput, Type type, Action<ScriptableObject> applyFields, bool preserveExistingId = false)
    Parameters
    Type Name Description
    SerenityRecipeImportContext context

    The import context.

    string id

    The recipe id.

    string relativeOutput

    The recipe's relative output path.

    Type type

    The ScriptableObject type to create or expect.

    Action<ScriptableObject> applyFields

    Populates the asset's fields.

    bool preserveExistingId

    When true and the asset already exists, its current Id is kept instead of being overwritten with id. No effect on a freshly created asset.

    Returns
    Type Description
    bool

    True when an outcome (Created/Updated) was recorded; false on a skip/error.

    TryUpsert<T>(SerenityRecipeImportContext, string, string, Action<T>, bool)

    Idempotently creates or updates a ScriptableObject of type T at the recipe's resolved output path, applying applyFields to populate it.

    • Wrong type already at the path → error + skip (never overwritten).
    • Existing correct type → loaded, GUID preserved, fields applied (Updated).
    • Absent → created with a fresh GUID, fields applied (Created).

    In a dry run no asset is created/loaded/mutated; only the outcome is recorded.

    Declaration
    protected bool TryUpsert<T>(SerenityRecipeImportContext context, string id, string relativeOutput, Action<T> applyFields, bool preserveExistingId = false) where T : ScriptableObject
    Parameters
    Type Name Description
    SerenityRecipeImportContext context

    The import context.

    string id

    The recipe id (becomes the asset's Id).

    string relativeOutput

    The recipe's relative output path.

    Action<T> applyFields

    Populates the asset's section-specific fields.

    bool preserveExistingId

    When true and the asset already exists, its current Id is kept instead of being overwritten with id (an in-place patch by output path). No effect on a freshly created asset.

    Returns
    Type Description
    bool

    True when an outcome (Created/Updated) was recorded; false on a skip/error.

    Type Parameters
    Name Description
    T

    The asset type to upsert.

    Validate(SerenityRecipeImportContext)

    Validates this section against the recipe and project, reporting errors/warnings/info. Must not modify any asset. Called for every run mode.

    Declaration
    public abstract void Validate(SerenityRecipeImportContext context)
    Parameters
    Type Name Description
    SerenityRecipeImportContext context

    The shared import context.

    ValidateEnum<TEnum>(SerenityRecipeImportContext, string, string, string, string, TEnum, out TEnum)

    Reports an invalid enum value as an error and returns false; otherwise outputs the parsed value and returns true. Use during validation to surface "invalid enum values".

    Declaration
    protected static bool ValidateEnum<TEnum>(SerenityRecipeImportContext context, string section, string id, string fieldName, string raw, TEnum fallback, out TEnum value) where TEnum : struct
    Parameters
    Type Name Description
    SerenityRecipeImportContext context
    string section
    string id
    string fieldName
    string raw
    TEnum fallback
    TEnum value
    Returns
    Type Description
    bool
    Type Parameters
    Name Description
    TEnum

    Implements

    ISerenityRecipeSectionImporter
    In this article
    © 2026 Serenity. All Rights Reserved