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
BatchAudioAssetImportEngine<TItem, TInput, TResult, TAsset>
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
EmptyAssetNameFallback
Asset name used when a file name is empty (e.g. "NewAudioPlayerClip", "NewMusicTrack").
Declaration
protected abstract string EmptyAssetNameFallback { get; }
Property Value
EmptyBatchErrorMessage
Error returned by validation when the batch has no included items.
Declaration
protected abstract string EmptyBatchErrorMessage { get; }
Property Value
EmptyIdFallback
Id suggested when a file name sanitizes to nothing (e.g. "sfx", "track").
Declaration
protected abstract string EmptyIdFallback { get; }
Property Value
ModuleLabel
The Addressables module label stamped on created definitions and on registered clips.
Declaration
protected abstract string ModuleLabel { get; }
Property Value
Methods
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
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
Returns
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
CollectExistingIds()
Returns the ids of every existing TAsset in the project.
Declaration
public HashSet<string> CollectExistingIds()
Returns
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
FileNameSafe(string)
Declaration
public string FileNameSafe(string name)
Parameters
| Type |
Name |
Description |
| string |
name |
|
Returns
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
Returns
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
Returns
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
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
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
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
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
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
Validate(TInput)
Convenience overload that collects existing ids from the project.
Declaration
public string Validate(TInput input)
Parameters
| Type |
Name |
Description |
| TInput |
input |
|
Returns
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.
A folder inside the Serenity package passes UnityEditor.AssetDatabase.IsValidFolder(System.String) — it exists —
so the destination is also held to Serenity.Global.Infrastructure.Editor.SerenityProjectOutputFolderRules, the one rule
every creator uses for an output folder. Without it a batch import wrote its brand-new definitions
into shipped content, which the next package update overwrites.
Declaration
public string Validate(TInput input, HashSet<string> existingIds)
Parameters
Returns
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
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