浏览代码

Added function to find a song by name and play it

James Peret 3 年之前
父节点
当前提交
b78e4aa3db
共有 1 个文件被更改,包括 14 次插入0 次删除
  1. 14 0
      Runtime/SoundtrackManager.cs

+ 14 - 0
Runtime/SoundtrackManager.cs

@@ -89,6 +89,20 @@ namespace KairoEngine.SoundtrackSystem
             PlayTrack(instance.playlist.soundtracks[instance.currentTrackIndex]);
         }
 
+        public static void PlayTrack(string soundtrackName)
+        {
+            if(instance == null) return;
+            for (int i = 0; i < instance.playlist.soundtracks.Count; i++)
+            {
+                if(instance.playlist.soundtracks[i].name == soundtrackName)
+                {
+                    PlayTrack(instance.playlist.soundtracks[i]);
+                    return;
+                }
+            }
+            Debug.LogWarning($"Could not find soundtrack \"{soundtrackName}\" in playlist", instance.gameObject);
+        }
+
         public static void PlayTrack(Soundtrack soundtrack)
         {
             if(instance == null) return;