using System;
using System.Collections.Generic;
using UnityEngine;
#if ADDRESSABLES_ENABLED
using UnityEngine.AddressableAssets;
#endif
// ReSharper disable once CheckNamespace
namespace DarkTonic.MasterAudio {
///
/// This class is used to populate a song for a PlaylistController through code if necessary.
///
[Serializable]
// ReSharper disable once CheckNamespace
public class MusicSetting {
// ReSharper disable InconsistentNaming
///
/// The alias for the song
///
public string alias = string.Empty;
///
/// This setting allows you to choose Audio Clip, Resource File or Addressable
///
public MasterAudio.AudioLocation audLocation = MasterAudio.AudioLocation.Clip;
///
/// The Audio Clip for the song, if you're using AudioLocation of Clip
///
public AudioClip clip;
///
/// Do not set this. It is calculated from the clip's name or alias if it has one.
///
public string songName = string.Empty;
///
/// This is the path to the Resource File if you're using AudioLocation of Resource File
///
public string resourceFileName = string.Empty;
#if ADDRESSABLES_ENABLED
///
/// This is the AssetReference to the clip if you're using AudioLocation of Addressable
///
public AssetReference audioClipAddressable;
#endif
///
/// The volume to use when playing the song.
///
public float volume = 1f;
///
/// The pitch to play the song at.
///
public float pitch = 1f;
///
/// Do not set this. It is for Inspector only.
///
public bool isExpanded = true;
///
/// Whether to loop the song or not.
///
public bool isLoop;
///
/// Do not set this, it is for Inspector only
///
public bool isChecked = true;
///
/// Do not set this, it is for Inspector only
///
public List metadataStringValues = new List();
///
/// Do not set this, it is for Inspector only
///
public List metadataBoolValues = new List();
///
/// Do not set this, it is for Inspector only
///
public List metadataIntValues = new List();
///
/// Do not set this, it is for Inspector only
///
public List metadataFloatValues = new List();
///
/// Do not set this, it is for Inspector only
///
public bool metadataExpanded = true;
///
/// This controls where the song starts from.
///
public MasterAudio.CustomSongStartTimeMode songStartTimeMode = MasterAudio.CustomSongStartTimeMode.Beginning;
///
/// If you choose Random Time for Begin Song Time Node, it will start between customStartTime (min) and customStartTimeMax, randomly.
///
public float customStartTime;
///
/// If you choose Random Time for Begin Song Time Node, it will start between customStartTime (min) and customStartTimeMax, randomly.
///
public float customStartTimeMax;
///
/// Do not set this value, used by "New Clip From Last Known Position" mode of Song Transition Mode and set automatically.
///
public int lastKnownTimePoint = 0;
///
/// Do not set this value, used by "New Clip From Last Known Position" mode of Song Transition Mode and set automatically.
///
public bool wasLastKnownTimePointSet = false;
///
/// Set this uniquely for each song as consecutive integers, used to keep track of which songs haven't played yet.
///
public int songIndex = 0;
///
/// This is used for loopable section of a song.
///
public float sectionStartTime = 0f;
///
/// This is used for loopable section of a song.
///
public float sectionEndTime = 0f;
///
/// Set this to true if you are going to use songStartedCustomEvent
///
public bool songStartedEventExpanded;
///
/// This is the name of a Custom Event to fire when the song is started.
///
public string songStartedCustomEvent = string.Empty;
///
/// Set this to true if you are going to use songChangedCustomEvent
///
public bool songChangedEventExpanded;
///
/// This is the name of a Custom Event to fire when the song is changed to another.
///
public string songChangedCustomEvent = string.Empty;
public MusicSetting() {
songChangedEventExpanded = false;
}
/*! \cond PRIVATE */
public bool HasMetadataProperties {
get {
return MetadataPropertyCount > 0;
}
}
public int MetadataPropertyCount {
get {
return metadataStringValues.Count + metadataBoolValues.Count + metadataIntValues.Count + metadataFloatValues.Count;
}
}
public float SongStartTime {
get {
switch (songStartTimeMode) {
default:
case MasterAudio.CustomSongStartTimeMode.Beginning:
return 0f;
case MasterAudio.CustomSongStartTimeMode.SpecificTime:
return customStartTime;
case MasterAudio.CustomSongStartTimeMode.RandomTime:
return UnityEngine.Random.Range(customStartTime, customStartTimeMax);
case MasterAudio.CustomSongStartTimeMode.Section:
return sectionStartTime;
}
}
}
/*! \endcond */
/*! \cond PRIVATE */
public static MusicSetting Clone(MusicSetting mus, MasterAudio.Playlist aList) {
var clone = new MusicSetting {
alias = mus.alias,
audLocation = mus.audLocation,
clip = mus.clip,
songName = mus.songName,
resourceFileName = mus.resourceFileName,
volume = mus.volume,
pitch = mus.pitch,
isExpanded = mus.isExpanded,
isLoop = mus.isLoop,
isChecked = mus.isChecked,
customStartTime = mus.customStartTime,
songStartedEventExpanded = mus.songStartedEventExpanded,
songStartedCustomEvent = mus.songStartedCustomEvent,
songChangedEventExpanded = mus.songChangedEventExpanded,
songChangedCustomEvent = mus.songChangedCustomEvent,
metadataExpanded = mus.metadataExpanded
};
SongMetadataProperty prop = null;
for (var i = 0; i < mus.metadataStringValues.Count; i++) {
var valToClone = mus.metadataStringValues[i];
prop = aList.songMetadataProps.Find(delegate (SongMetadataProperty p) {
return p.PropertyName == valToClone.PropertyName;
});
var sVal = new SongMetadataStringValue(prop);
sVal.Value = valToClone.Value;
clone.metadataStringValues.Add(sVal);
}
for (var i = 0; i < mus.metadataFloatValues.Count; i++) {
var valToClone = mus.metadataFloatValues[i];
prop = aList.songMetadataProps.Find(delegate (SongMetadataProperty p) {
return p.PropertyName == valToClone.PropertyName;
});
var fVal = new SongMetadataFloatValue(prop);
fVal.Value = valToClone.Value;
clone.metadataFloatValues.Add(fVal);
}
for (var i = 0; i < mus.metadataBoolValues.Count; i++) {
var valToClone = mus.metadataBoolValues[i];
prop = aList.songMetadataProps.Find(delegate (SongMetadataProperty p) {
return p.PropertyName == valToClone.PropertyName;
});
var bVal = new SongMetadataBoolValue(prop);
bVal.Value = valToClone.Value;
clone.metadataBoolValues.Add(bVal);
}
for (var i = 0; i < mus.metadataIntValues.Count; i++) {
var valToClone = mus.metadataIntValues[i];
prop = aList.songMetadataProps.Find(delegate (SongMetadataProperty p) {
return p.PropertyName == valToClone.PropertyName;
});
var iVal = new SongMetadataIntValue(prop);
iVal.Value = valToClone.Value;
clone.metadataIntValues.Add(iVal);
}
return clone;
// ReSharper restore InconsistentNaming
}
/*! \endcond */
}
}