|
Post by artaka on Jan 13, 2015 22:42:44 GMT
Hey Brian,
What is the best way to check if a playlistController exists. I can simply check if a gameObject with a specific name exists but that won't be very efficient. I tried the following but I get an error:
if (PlaylistController.InstanceByName(playlistControllerName) != null) MasterAudio.TriggerNextPlaylistClip(playlistControllerName);
Could not find Playlist Controller 'AmbientPlaylistController'. UnityEngine.Debug:LogError(Object) PlaylistController:InstanceByName(String) (at Assets/DarkTonic/MasterAudio/Scripts/Utility/PlaylistController.cs:370) ...
Changing LogError() to LogWarning() solves my problem but I'm not sure if you had LogError() for a specific reason. Or is there a better way to check if a playlistController exists?
|
|
|
Post by DarkTonic Dev on Jan 13, 2015 23:41:58 GMT
It shows an error because I think you should know if a PlaylistController exists. It's either in the Scene because you put it there or it's not.
What's the Scenario where you wouldn't know if it exists? You could iterate through the PlaylistController.Instances list and look at the names, or I could add a helper method. But I suspect you're probably doing things "not best practice" if you don't know if the Controller exists or not.
|
|
|
Post by artaka on Jan 13, 2015 23:52:55 GMT
The scenario is, I have multiple scenes that have a 3 different playlists controllers. These playlists are triggered by a prefab that exists in all of these scenes. The prefab needs determines which playlists are present in the scene and trigger them accordingly.
|
|
|
Post by DarkTonic Dev on Jan 14, 2015 0:58:12 GMT
Are you using layered music? I just wanted to confirm that you really need 3 Controllers. The most I could see needing for non-layered music is 2. That's because one could be on shuffle and the other could have shuffle off.
Here's a modified version of that method that you can pass 2nd parameter as false for your needs. I'll add this to the next update.
public static PlaylistController InstanceByName(string playlistControllerName, bool errorIfNotFound = true) { var match = Instances.Find(delegate(PlaylistController obj) { return obj != null && obj.ControllerName == playlistControllerName; });
if (match != null) { return match; } if (errorIfNotFound) { Debug.LogError("Could not find Playlist Controller '" + playlistControllerName + "'."); } return null; }
|
|
|
Post by artaka on Jan 14, 2015 1:16:02 GMT
Yes, I am using layered music. And depending on the scenes these layers fade in and out at specific points. MasterAudio has been essential in making everything work flawlessly. Thank you for the modification.
|
|
|
Post by DarkTonic Dev on Jan 14, 2015 2:01:26 GMT
That sounds really cool!
|
|