Class UnityMusicTrackDefinition
Unity ScriptableObject implementation of music track definition.
Defines a single music track with metadata including title, artist, and audio clip reference.
Provides Unity-specific audio clip handling while implementing the foundation's IMusicTrackDefinition interface.
Can be created as an asset through Unity's CreateAssetMenu system for easy music library management.
Namespace: Serenity.MusicPlayer.Infrastructure.Settings
Assembly: Serenity.UnityMusicPlayer.Infrastructure.dll
Syntax
public class UnityMusicTrackDefinition : ScriptableObject, IMusicTrackDefinition, IFoundationSettings
Constructors
UnityMusicTrackDefinition()
Declaration
public UnityMusicTrackDefinition()
Fields
Artist
Declaration
public string Artist
Field Value
| Type | Description |
|---|---|
| string | Artist or composer name for the music track. |
AudioClip
Declaration
public AudioClip AudioClip
Field Value
| Type | Description |
|---|---|
| AudioClip | Unity AudioClip asset containing the actual audio data for playback. |
AudioClipPath
Declaration
public string AudioClipPath
Field Value
| Type | Description |
|---|---|
| string | File path to the audio clip asset for reference and loading purposes. |
BeatUnit
Declaration
public int BeatUnit
Field Value
| Type | Description |
|---|---|
| int | Time signature denominator (note value that gets one beat). Authoritative when LoopInputMode is Bars. |
BeatsPerBar
Declaration
public int BeatsPerBar
Field Value
| Type | Description |
|---|---|
| int | Time signature numerator (beats per bar). Authoritative when LoopInputMode is Bars. |
Bpm
Declaration
public float Bpm
Field Value
| Type | Description |
|---|---|
| float | Tempo in quarter-note beats per minute. Authoritative when LoopInputMode is Bars. |
EndBar
Declaration
public int EndBar
Field Value
| Type | Description |
|---|---|
| int | 1-indexed bar where the loop restarts (exclusive). Authoritative when LoopInputMode is Bars. |
EndTimeSeconds
Declaration
public float EndTimeSeconds
Field Value
| Type | Description |
|---|---|
| float | Loop-out point in seconds. Authoritative when LoopInputMode is Time. |
Guid
Declaration
public string Guid
Field Value
| Type | Description |
|---|---|
| string | Globally unique identifier for this music track definition. |
Id
Declaration
public string Id
Field Value
| Type | Description |
|---|---|
| string | Unique identifier for this music track definition. |
LoopInputMode
Declaration
public MusicLoopInputMode LoopInputMode
Field Value
| Type | Description |
|---|---|
| MusicLoopInputMode | Authoring mode that decides whether the loop region is expressed as time codes or musical bars. |
StartBar
Declaration
public int StartBar
Field Value
| Type | Description |
|---|---|
| int | 1-indexed bar the loop returns to. Authoritative when LoopInputMode is Bars. |
StartTimeSeconds
Declaration
public float StartTimeSeconds
Field Value
| Type | Description |
|---|---|
| float | Loop-return point in seconds. Authoritative when LoopInputMode is Time. |
TailFadeOutCurve
Declaration
public MusicFadeCurve TailFadeOutCurve
Field Value
| Type | Description |
|---|---|
| MusicFadeCurve | Shape of the tail fade-out curve. |
TailFadeOutCustomCurve
Declaration
public AnimationCurve TailFadeOutCustomCurve
Field Value
| Type | Description |
|---|---|
| AnimationCurve | Author-drawn fade-out curve used when TailFadeOutCurve is Custom. Runs from 1 (full volume) at the start of the fade to 0 (silence) at the end. |
TailFadeOutDuration
Declaration
public float TailFadeOutDuration
Field Value
| Type | Description |
|---|---|
| float | Duration in seconds over which the outgoing tail voice fades to silence once the loop-out point is reached. Zero cuts the tail at the loop point (no tail). |
TailPreservingLoop
Declaration
public bool TailPreservingLoop
Field Value
| Type | Description |
|---|---|
| bool | Whether the track loops with a tail-preserving (dual-source) seam so reverb tails are not cut. |
Title
Declaration
public string Title
Field Value
| Type | Description |
|---|---|
| string | Display title of the music track. |
Methods
GetEffectiveEndTimeSeconds()
Resolves the effective loop-out point in seconds, deriving it from the musical fields when the track is authored in bar mode, otherwise returning the directly entered time code. When the time code is unset it falls back to the assigned audio clip's full duration, so a track loops over its whole length by default.
Declaration
public float GetEffectiveEndTimeSeconds()
Returns
| Type | Description |
|---|---|
| float | The loop-out point in seconds. |
GetEffectiveStartTimeSeconds()
Resolves the effective loop-return point in seconds, deriving it from the musical fields when the track is authored in bar mode, otherwise returning the directly entered time code.
Declaration
public float GetEffectiveStartTimeSeconds()
Returns
| Type | Description |
|---|---|
| float | The loop-return point in seconds. |
SampleTailFadeOutCurve()
Samples the custom tail fade-out UnityEngine.AnimationCurve into a uniform gain table over [0, 1], providing a platform-agnostic representation the runtime can evaluate without referencing Unity types.
Declaration
public float[] SampleTailFadeOutCurve()
Returns
| Type | Description |
|---|---|
| float[] | The sampled gain table, or null when a preset curve is selected or no custom curve is set. |