logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Class BatchAudioAssetImportEngine<TItem, TInput, TResult, TAsset>

    Template-method engine shared by every "batch-import audio files into a ScriptableObject definition" wizard (sound effects, music tracks): file-type inference, id/asset-name suggestion, duplicate detection, folder-scoped validation, a UnityEditor.AssetDatabase.StartAssetEditing-batched creation with rollback on failure, Addressables registration, and external-file import. A concrete subclass supplies only what genuinely differs between modules: how one item becomes a definition asset (BuildAsset(TItem)), the Addressables module label, the empty-input fallbacks, any extra per-item validation (e.g. music's loop-region rules), and any extra defaults an item gets when built from an already-imported clip (e.g. music's suggested title).

    Inheritance
    object
    BatchAudioAssetImportEngine<TItem, TInput, TResult, TAsset>
    Inherited Members
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    Namespace: Serenity.AudioPlayer.Infrastructure.Settings.Editor.Builder
    Assembly: Serenity.UnityAudioPlayer.Infrastructure.Editor.dll
    Syntax
    public abstract class BatchAudioAssetImportEngine<TItem, TInput, TResult, TAsset> where TItem : BatchAudioImportItem, new() where TInput : BatchAudioImportInput<TItem> where TResult : BatchAudioImportResult<TAsset>, new() where TAsset : ScriptableObject, IFoundationSettings
    Type Parameters
    Name Description
    TItem

    The module's concrete row type.

    TInput

    The module's concrete batch-input type.

    TResult

    The module's concrete batch-result type.

    TAsset

    The module's concrete definition asset type.

    Constructors

    BatchAudioAssetImportEngine()

    Declaration
    protected BatchAudioAssetImportEngine()

    Properties

    AudioExtensions

    File extensions Unity can import as an UnityEngine.AudioClip.

    Declaration
    public IReadOnlyList<string> AudioExtensions { get; }
    Property Value
    Type Description
    IReadOnlyList<string>

    EmptyAssetNameFallback

    Asset name used when a file name is empty (e.g. "NewAudioPlayerClip", "NewMusicTrack").

    Declaration
    protected abstract string EmptyAssetNameFallback { get; }
    Property Value
    Type Description
    string

    EmptyBatchErrorMessage

    Error returned by validation when the batch has no included items.

    Declaration
    protected abstract string EmptyBatchErrorMessage { get; }
    Property Value
    Type Description
    string

    EmptyIdFallback

    Id suggested when a file name sanitizes to nothing (e.g. "sfx", "track").

    Declaration
    protected abstract string EmptyIdFallback { get; }
    Property Value
    Type Description
    string

    ModuleLabel

    The Addressables module label stamped on created definitions and on registered clips.

    Declaration
    protected abstract string ModuleLabel { get; }
    Property Value
    Type Description
    string

    Methods

    ApplyExtraDefaults(TItem, AudioClip, string)

    Extra defaults applied by ItemFromClip(AudioClip) beyond source/id/asset-name (e.g. music's suggested title and default loop-out point).

    Declaration
    protected virtual void ApplyExtraDefaults(TItem item, AudioClip clip, string seed)
    Parameters
    Type Name Description
    TItem item
    AudioClip clip
    string seed

    BuildAsset(TItem)

    Builds the definition asset for one included item, filling every type-specific field.

    Declaration
    protected abstract TAsset BuildAsset(TItem item)
    Parameters
    Type Name Description
    TItem item
    Returns
    Type Description
    TAsset

    BuildAssetPath(string, string)

    Project-relative asset path for an item in a destination folder (no uniqueness applied).

    Declaration
    public string BuildAssetPath(string folderPath, string assetName)
    Parameters
    Type Name Description
    string folderPath
    string assetName
    Returns
    Type Description
    string

    BuildExistingIdErrorMessage(string)

    Error returned by validation when an id collides with an existing definition.

    Declaration
    protected abstract string BuildExistingIdErrorMessage(string id)
    Parameters
    Type Name Description
    string id
    Returns
    Type Description
    string

    CollectExistingIds()

    Returns the ids of every existing TAsset in the project.

    Declaration
    public HashSet<string> CollectExistingIds()
    Returns
    Type Description
    HashSet<string>

    Create(TInput)

    Creates a definition asset per included item in a single batch, rolling back every created asset if any step throws. Re-validates first so the creator is safe to call independently of the window's live validation.

    Declaration
    public TResult Create(TInput input)
    Parameters
    Type Name Description
    TInput input
    Returns
    Type Description
    TResult

    FileNameSafe(string)

    Replaces characters illegal in a file name with '_', falling back to EmptyAssetNameFallback.

    Declaration
    public string FileNameSafe(string name)
    Parameters
    Type Name Description
    string name
    Returns
    Type Description
    string

    FindDuplicateAssetNames(IEnumerable<TItem>)

    Returns the file names that resolve to the same asset path among the included items.

    Declaration
    public List<string> FindDuplicateAssetNames(IEnumerable<TItem> items)
    Parameters
    Type Name Description
    IEnumerable<TItem> items
    Returns
    Type Description
    List<string>

    FindDuplicateIds(IEnumerable<TItem>)

    Returns the ids that appear more than once among the included items (ordinal).

    Declaration
    public List<string> FindDuplicateIds(IEnumerable<TItem> items)
    Parameters
    Type Name Description
    IEnumerable<TItem> items
    Returns
    Type Description
    List<string>

    ImportExternalAudioFile(string, string, out string)

    Copies an audio file from anywhere on disk into destinationFolder (a project folder), imports it, and returns the resulting UnityEngine.AudioClip. Files already inside the project are loaded in place. Returns null with error on failure.

    Declaration
    public AudioClip ImportExternalAudioFile(string osPath, string destinationFolder, out string error)
    Parameters
    Type Name Description
    string osPath
    string destinationFolder
    string error
    Returns
    Type Description
    AudioClip

    IsAudioFile(string)

    True when path ends with a known importable audio extension.

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

    ItemFromClip(AudioClip)

    Builds an item with inferred defaults for an already-imported project clip.

    Declaration
    public TItem ItemFromClip(AudioClip clip)
    Parameters
    Type Name Description
    AudioClip clip
    Returns
    Type Description
    TItem

    SuggestAssetName(string)

    Suggests an asset file name from a file name (the original name without extension).

    Declaration
    public string SuggestAssetName(string fileNameOrPath)
    Parameters
    Type Name Description
    string fileNameOrPath
    Returns
    Type Description
    string

    SuggestId(string)

    Suggests a runtime id from a file name: lower-cased, spaces and invalid characters collapsed to single underscores, trimmed. e.g. "Sword Hit 01.wav" -> "sword_hit_01".

    Declaration
    public string SuggestId(string fileNameOrPath)
    Parameters
    Type Name Description
    string fileNameOrPath
    Returns
    Type Description
    string

    ToProjectRelativePath(string)

    Returns the project-relative ("Assets/…") path for an absolute OS path that lives inside this project, or null when the path is outside the project.

    Declaration
    public string ToProjectRelativePath(string osPath)
    Parameters
    Type Name Description
    string osPath
    Returns
    Type Description
    string

    Validate(TInput)

    Convenience overload that collects existing ids from the project.

    Declaration
    public string Validate(TInput input)
    Parameters
    Type Name Description
    TInput input
    Returns
    Type Description
    string

    Validate(TInput, HashSet<string>)

    Full validation including destination folder, per-item rules, in-batch duplicate ids/names and collision with existing definitions. existingIds is injected so the rules are testable without the AssetDatabase; the single-argument overload collects them from the project.

    Declaration
    public string Validate(TInput input, HashSet<string> existingIds)
    Parameters
    Type Name Description
    TInput input
    HashSet<string> existingIds
    Returns
    Type Description
    string

    ValidateItem(TItem)

    Validates a single included item's identity and clip assignment, then any module-specific extra rules via ValidateItemExtra(TItem). Returns null when valid.

    Declaration
    public string ValidateItem(TItem item)
    Parameters
    Type Name Description
    TItem item
    Returns
    Type Description
    string

    ValidateItemExtra(TItem)

    Extra per-item validation beyond identity + clip (e.g. music's loop-region rules). Returns null when the item is otherwise valid.

    Declaration
    protected virtual string ValidateItemExtra(TItem item)
    Parameters
    Type Name Description
    TItem item
    Returns
    Type Description
    string
    In this article
    © 2026 Serenity. All Rights Reserved