Skip to content

Commit

Permalink
📦 3.0.2 Release
Browse files Browse the repository at this point in the history
- [Community Report] - Fixed an issue where trying to call a music track to play could fail due to id changes behind the scenes.
- [Community Report] - Fixed an issue where the audio manager failed to initialize correctly in builds.
- [Community Report] - Attempted to fix an issue where missing audio clips were not cleaned up.
- [Community Report] - Fixed an issue where the preview button for clips wouldn't take dynamic time into account.
- [Community Report] - Fixed an issue where the music transitions didn't apply the duration to the volume edit correctly.
- Removed a bunch of Debug.Logs that were left in by mistake from testing the asset.
  • Loading branch information
JonathanMCarter committed Dec 27, 2023
1 parent 3666ada commit 938d7e4
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ private static SerializedProperty SelectedProperty

if (PerUserSettings.LastLibraryIndexShown > -1 && UtilEditor.LibraryObject.Fp("library").Fpr("list").arraySize > 0)
{
if (PerUserSettings.LastLibraryIndexShown >
UtilEditor.LibraryObject.Fp("library").Fpr("list").arraySize - 1)
{
PerUserSettings.LastLibraryIndexShown =
UtilEditor.LibraryObject.Fp("library").Fpr("list").arraySize - 1;
}

selectedPropertyCache = UtilEditor.LibraryObject.Fp("library").Fpr("list")
.GetIndex(PerUserSettings.LastLibraryIndexShown);
}
Expand Down Expand Up @@ -284,11 +291,20 @@ private void DrawSearchButton()
private static void DrawLibraryRow(SerializedProperty prop)
{
if (prop.Fpr("value") == null) return;

if (prop.Fpr("value").Fpr("value").objectReferenceValue == null)
{
AudioRemover.RemoveNullLibraryEntries();
selectedPropertyCache = null;
return;
}

EditorGUILayout.BeginHorizontal("HelpBox");
EditorGUILayout.BeginVertical();

var data = UtilEditor.Library.LibraryLookup[prop.Fpr("key").stringValue];

DrawPreviewButton((AudioClip)prop.Fpr("value").Fpr("value").objectReferenceValue);
DrawPreviewButton(data);

EditorGUILayout.Space();
UtilEditor.DrawHorizontalGUILine();
Expand All @@ -300,7 +316,6 @@ private static void DrawLibraryRow(SerializedProperty prop)
EditorGUILayout.LabelField("File", EditorStyles.boldLabel);
GUI.contentColor = Color.white;


LibraryEditorClip.DrawLibraryEditor(prop);

EditorGUILayout.EndVertical();
Expand Down Expand Up @@ -347,8 +362,8 @@ private void ShowSelected(SearchTreeEntry entry)
/// <summary>
/// Draws the preview button for the clip.
/// </summary>
/// <param name="clip">The clip to play if pressed.</param>
private static void DrawPreviewButton(AudioClip clip)
/// <param name="data">The clip to play if pressed.</param>
private static void DrawPreviewButton(AudioData data)
{
EditorGUILayout.Space(1.5f);

Expand All @@ -358,10 +373,10 @@ private static void DrawPreviewButton(AudioClip clip)

if (GUILayout.Button(PreviewButton, GUILayout.Height(20)))
{
EditorAudioClipPlayer.Play(clip);
EditorAudioClipPlayer.Play(data);
}
}
else if (EditorAudioClipPlayer.IsClipPlaying() && EditorAudioClipPlayer.CurrentClip == clip)
else if (EditorAudioClipPlayer.IsClipPlaying() && EditorAudioClipPlayer.CurrentClip == data.value)
{
GUI.backgroundColor = UtilEditor.Red;

Expand All @@ -376,7 +391,7 @@ private static void DrawPreviewButton(AudioClip clip)

if (GUILayout.Button(PreviewButton, GUILayout.Height(20)))
{
EditorAudioClipPlayer.Play(clip);
EditorAudioClipPlayer.Play(data);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ public static bool IsClipPlaying()
/// <summary>
/// Plays the entered clip.
/// </summary>
/// <param name="clip">The clip to play.</param>
public static void Play(AudioClip clip)
/// <param name="data">The clip to play.</param>
public static void Play(AudioData data)
{
StopAll();

CurrentClip = clip;
CurrentClip = data.value;

var method = AudioUtilClass.GetMethod
(
Expand All @@ -97,10 +97,16 @@ public static void Play(AudioClip clip)
new Type[] { typeof(AudioClip), typeof(int), typeof(bool) },
null
);

var samples = new float[data.value.samples * data.value.channels];
data.value.GetData(samples, 0);

method?.Invoke(null, new object[] { clip, 0, false });
var amountThrough = data.dynamicStartTime.time / data.value.length;
var startTime = Mathf.FloorToInt((samples.Length / 2f) * amountThrough);

method?.Invoke(null, new object[] { data.value, startTime, false });
}


/// <summary>
/// Stops any clip currently in play.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static class AssetVersionData
/// <summary>
/// The version number of the asset.
/// </summary>
public static string VersionNumber => "3.0.1";
public static string VersionNumber => "3.0.2";


/// <summary>
Expand All @@ -40,6 +40,6 @@ public static class AssetVersionData
/// <remarks>
/// Asset owner is in the UK, so its D/M/Y format.
/// </remarks>
public static string ReleaseDate => "22/12/2023";
public static string ReleaseDate => "27/12/2023";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public void ProcessLoopEdits()
/// </summary>
private void OnClipCompleted()
{
Debug.LogError("Completed");
// Debug.LogError("Completed");
Completed.Raise();
}

Expand Down Expand Up @@ -378,7 +378,7 @@ private void OnClipStateChanged()
private IEnumerator Co_ClipRuntimeRoutine()
{
yield return new WaitForSecondsRealtime(ClipTimeRemaining);
Debug.LogError(ClipTimeRemaining);
// Debug.LogError(ClipTimeRemaining);
OnClipCompleted();
}

Expand All @@ -387,14 +387,14 @@ private IEnumerator Co_PlayHandler()
{
if (EditParams.TryGetValue("delay", out DelayEdit edit))
{
Debug.LogError("Delayed");
// Debug.LogError("Delayed");
yield return new WaitForSeconds(edit.Delay);
Debug.LogError("Delay Completed");
// Debug.LogError("Delay Completed");
PlayerSource.Play();
yield break;
}

Debug.LogError("Played Normal");
// Debug.LogError("Played Normal");
PlayerSource.Play();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private void OnClipCompleted()
{
playerSequence.Players[0].EditParams.SetValue("delay", delayEdit);
hasDelayed = false;
Debug.Log("Reset Edit Removal");
// Debug.Log("Reset Edit Removal");
}

playerSequence.PlayerComplete();
Expand Down
33 changes: 25 additions & 8 deletions Carter Games/Audio Manager/Code/Runtime/Music/MusicManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,11 @@ public static IMusicPlayer Prepare(string id)
/// <returns>The player prepared for use.</returns>
public static IMusicPlayer Prepare(string id, string firstTrack)
{
if (AssetAccessor.GetAsset<AudioLibrary>().MusicTrackLookup.ContainsKey(id))
var trackList = AssetAccessor.GetAsset<AudioLibrary>().GetTrackList(id);

if (trackList != null)
{
ActiveTrackList = AssetAccessor.GetAsset<AudioLibrary>().MusicTrackLookup[id];
ActiveTrackList = trackList;
}
else
{
Expand All @@ -237,9 +239,11 @@ public static IMusicPlayer Prepare(string id, string firstTrack)
/// <returns>The player prepared for use.</returns>
public static IMusicPlayer Prepare(string id, int firstTrackIndex)
{
if (AssetAccessor.GetAsset<AudioLibrary>().MusicTrackLookup.ContainsKey(id))
var trackList = AssetAccessor.GetAsset<AudioLibrary>().GetTrackList(id);

if (trackList != null)
{
ActiveTrackList = AssetAccessor.GetAsset<AudioLibrary>().MusicTrackLookup[id];
ActiveTrackList = trackList;
}
else
{
Expand Down Expand Up @@ -269,13 +273,15 @@ public static void Play(string id, float volume = 1f)
AmLog.Error(AudioManagerErrorMessages.GetMessage(AudioManagerErrorCode.MusicDisabled));
return;
}

var trackList = AssetAccessor.GetAsset<AudioLibrary>().GetTrackList(id);

if (AssetAccessor.GetAsset<AudioLibrary>().MusicTrackLookup.ContainsKey(id))
if (trackList != null)
{
var player = Prepare(id);
player.Volume = volume;

Play(AssetAccessor.GetAsset<AudioLibrary>().MusicTrackLookup[id]);
Play(trackList);
}
else
{
Expand All @@ -297,6 +303,12 @@ private static void Play(MusicTrackList trackList, float volume = 1f)
return;
}

if (trackList == null)
{
AmLog.Error(AudioManagerErrorMessages.GetMessage(AudioManagerErrorCode.TrackListCannotBeFound));
return;
}

ActiveTrackList = trackList;

Player = ActiveTrackList.GetMusicPlayer();
Expand Down Expand Up @@ -390,9 +402,14 @@ public static void TransitionTo(string clip)
}

ActiveId = clip;

Player.Transition.Data.AddParam("musicClip", ActiveTrackList.GetTrack(clip));
Player.Transition.Data.AddParam("musicClipStartTime", ActiveTrackList.GetStartTime(clip));

Player.DefaultVolumeTransition.Data.AddParam("musicClip", ActiveTrackList.GetTrack(clip));
Player.DefaultVolumeTransition.Data.AddParam("musicClipStartTime", ActiveTrackList.GetStartTime(clip));
Player.DefaultVolumeTransition.Transition(TransitionDirection.InAndOut);

Player.Transition.Transition(TransitionDirection.InAndOut);
}


Expand All @@ -416,7 +433,7 @@ public static void TransitionTo(string clip, MusicTransition musicTransition, fl
/// <param name="duration">The duration for the transition. Def: 1f</param>
public static void TransitionTo(string clip, IMusicTransition musicTransition, float duration = 1f)
{
Debug.Log(Player);
// Debug.Log(Player);

if (!ActiveTrackList.HasTrack(clip))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public IMusicTransition Transition
get
{
if (customTransition != null) return customTransition;
if (TrackList.StartingTransition != null) return TrackList.StartingTransition;
return DefaultVolumeTransition;
}
}
Expand Down Expand Up @@ -126,6 +127,9 @@ private void SetToFirstTrack()
/// </summary>
public void Play()
{
Transition.Data.AddParam("musicClip", TrackList.GetTrack(0));
Transition.Data.AddParam("musicClipStartTime", TrackList.GetStartTime(0));

SetToFirstTrack();
TransitionIn();

Expand Down Expand Up @@ -210,6 +214,10 @@ public void SkipForwards(bool smoothTransition = true)
if (TrackList.TrackListLoops)
{
MusicManager.MusicSource.Standard.MainSource.time = TrackList.GetStartTime();

Transition.Data.AddParam("musicClip", TrackList.GetTrack(0));
Transition.Data.AddParam("musicClipStartTime", TrackList.GetStartTime(0));

Transition.Transition(TransitionDirection.InAndOut);
}
else
Expand Down Expand Up @@ -248,6 +256,10 @@ public void SkipBackwards(bool replayCurrentFirst = true, bool smoothTransition
}

if (!smoothTransition) return;

Transition.Data.AddParam("musicClip", TrackList.GetTrack(0));
Transition.Data.AddParam("musicClipStartTime", TrackList.GetStartTime(0));

TransitionIn();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,11 @@ private IEnumerator Co_TransitionStandard(TransitionDirection dir, float t, floa

if (dir == TransitionDirection.In)
{
MusicManager.MusicSource.Standard.MainSource.volume = Mathf.Clamp(t, 0f, startingVolume);
MusicManager.MusicSource.Standard.MainSource.volume = Mathf.Clamp((t / duration), 0f, startingVolume);
}
else
{
MusicManager.MusicSource.Standard.MainSource.volume = Mathf.Clamp(1 - t, 0f, startingVolume);
MusicManager.MusicSource.Standard.MainSource.volume = Mathf.Clamp(1 - (t / duration), 0f, startingVolume);
}

yield return null;
Expand Down Expand Up @@ -199,8 +199,8 @@ private IEnumerator Co_TransitionInOut(float t, float duration, bool unscaled)
{
t += unscaled ? Time.unscaledDeltaTime : Time.deltaTime;

MusicManager.MusicSource.Standard.MainSource.volume = Mathf.Clamp(1 - t, 0f, startingVolume);
MusicManager.MusicSource.Standard.TransitionSource.volume = Mathf.Clamp(t, 0f, startingVolume);
MusicManager.MusicSource.Standard.MainSource.volume = Mathf.Clamp(1 - (t / duration), 0f, startingVolume);
MusicManager.MusicSource.Standard.TransitionSource.volume = Mathf.Clamp((t / duration), 0f, startingVolume);

yield return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public sealed class Cut : IMusicTransition

public Cut()
{
Data = new TransitionData();
// Debug.LogError("dhjsfh");
IsComplete = false;
}

Expand Down Expand Up @@ -108,7 +110,11 @@ public IEnumerator Co_RunTransition()
yield return null;

MusicManager.MusicSource.Standard.MainSource.clip = Data.GetParam<AudioClip>(ClipId);

// Debug.LogError(Data.GetParam<AudioClip>(ClipId));

MusicManager.MusicSource.Standard.MainSource.time = Data.GetParam(ClipStartTimeId, 0f);
MusicManager.MusicSource.Standard.MainSource.volume = MusicManager.PlayerVolume;
MusicManager.MusicSource.Standard.MainSource.Play();

IsComplete = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public IEnumerator Co_RunTransition()
var unscaled = Data.GetParam<bool>(TimeScaleId);
var dir = Data.GetParam<TransitionDirection>(DirectionId);
var duration = Data.GetParam<float>(DurationId);

var t = 0f;


Expand Down Expand Up @@ -171,11 +172,11 @@ private IEnumerator Co_TransitionStandard(TransitionDirection dir, float t, floa

if (dir == TransitionDirection.In)
{
MusicManager.MusicSource.Standard.MainSource.volume = Mathf.Clamp(t, 0f, MusicManager.PlayerVolume);
MusicManager.MusicSource.Standard.MainSource.volume = Mathf.Clamp((t / duration), 0f, MusicManager.PlayerVolume);
}
else
{
MusicManager.MusicSource.Standard.MainSource.volume = Mathf.Clamp(1 - t, 0f, startingVolume);
MusicManager.MusicSource.Standard.MainSource.volume = Mathf.Clamp(1 - (t / duration), 0f, startingVolume);
}

yield return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
*/

using System;
#if UNITY_EDITOR
using UnityEditor;
#endif
// using UnityEditor;
using UnityEngine;
using UnityEngine.Audio;

Expand Down Expand Up @@ -80,9 +78,7 @@ public MixerData(string uuid, string key, AudioMixerGroup mixerGroup)
{
this.uuid = uuid;
this.key = key;
#if UNITY_EDITOR
path = AssetDatabase.GetAssetPath(mixerGroup);
#endif
// path = AssetDatabase.GetAssetPath(mixerGroup);
this.mixerGroup = mixerGroup;
}
}
Expand Down
Loading

0 comments on commit 938d7e4

Please sign in to comment.