### Implementing Lobby Music (C#) Source: https://github.com/killers0992/audioplayerapi/blob/master/README.md Provides a comprehensive example for managing lobby music. It includes loading the music clip on plugin load, creating a global audio player with a looping clip when waiting for players, and stopping the music by removing all clips when the round starts. ```C# // Execute this method when plugin loads. public void OnPluginLoad() { AudioClipStorage.LoadClip("C:\\Users\\Kille\\Documents\\Serwer\\lobby_music.ogg", "lobby_music"); } // Execute this method via events when server is waiting for players. public void OnWaitingForPlayers() { AudioPlayer lobbyPlayer = AudioPlayer.CreateOrGet("Lobby", onIntialCreation: (p) => { p.AddSpeaker("Main", isSpatial: false, maxDistance: 5000f); }); lobbyPlayer.AddClip("lobby_music", loop: true); } // Execute this method via events when server started round. public void OnRoundStart() { if (!AudioPlayer.TryGet("Lobby", out AudioPlayer lobbyPlayer)) return; // Removes all playing clips. lobbyPlayer.RemoveAllClips(); } ``` -------------------------------- ### Adding Clip to Existing Audio Player (C#) Source: https://github.com/killers0992/audioplayerapi/blob/master/README.md Demonstrates how to retrieve an existing AudioPlayer by its name using AudioPlayer.TryGet and then add a previously loaded audio clip to it using the AddClip method. ```C# // Adding clips to audio players by using their name. public void AddClipOnAudioPlayer() { // Tries to get audio player with name "Spectator AudioPlayer", you need to make sure that audio player is already created. if (!AudioPlayer.TryGet("Spectator AudioPlayer", out AudioPlayer audioPlayer)) return; // Add shot clip and plays. audioPlayer.AddClip("shot"); } ``` -------------------------------- ### Creating Global Audio Player (C#) Source: https://github.com/killers0992/audioplayerapi/blob/master/README.md Illustrates how to create a global AudioPlayer that can be heard by all players regardless of their location. It uses CreateOrGet and adds a non-spatial speaker with a large max distance. ```C# // Creates global audio player which everyone can hear from any location. public void CreateGlobal() { AudioPlayer audioPlayer = AudioPlayer.CreateOrGet($"Global AudioPlayer", onIntialCreation: (p) => { // This created speaker will be in 2D space ( audio will be always playing directly on you not from specific location ) but make sure that max distance is set to some higher value. Speaker speaker = p.AddSpeaker("Main", isSpatial: false, maxDistance: 5000f); }); audioPlayer.AddClip("shot"); } ``` -------------------------------- ### Removing Clip by Name (C#) Source: https://github.com/killers0992/audioplayerapi/blob/master/README.md Shows how to retrieve an existing AudioPlayer by name and remove a specific clip from it using the clip's name with the RemoveClipByName method. ```C# public void RemoveClipInMyAudioPlayer() { // Replace MyAudioPlayer with name of your audioPlayer. if (!AudioPlayer.TryGet("MyAudioPlayer", out AudioPlayer player)) return; player.RemoveClipByName("shot"); } ``` -------------------------------- ### Removing a Clip from AudioPlayer (C#) Source: https://github.com/killers0992/audioplayerapi/blob/master/README.md This snippet demonstrates how to retrieve an existing AudioPlayer instance by name and remove a specific audio clip from it using its ID. It first attempts to get the player and then calls RemoveClipById if successful. ```C# if (!AudioPlayer.TryGet("Lobby", out AudioPlayer player)) return; player.RemoveClipById(lobbyClipId); ``` -------------------------------- ### Creating Player-Attached Audio Player (C#) Source: https://github.com/killers0992/audioplayerapi/blob/master/README.md Demonstrates creating an AudioPlayer that is attached to a specific player, making sounds originate from the player's position. It shows how to create a spatial speaker attached to the player and add a loaded audio clip. ```C# // Creating audio player which is attached to player which means any added clip to this audio player will be directly at player position. public void CreateForPlayer(Player player) { AudioPlayer audioPlayer = AudioPlayer.CreateOrGet($"Player {player.Nickname}", onIntialCreation: (p) => { // Attach created audio player to player. p.transform.parent = player.GameObject.transform; // This created speaker will be in 3D space. Speaker speaker = p.AddSpeaker("Main", isSpatial: true, minDistance: 5f, maxDistance: 15f); // Attach created speaker to player. speaker.transform.parent = player.GameObject.transform; // Set local positino to zero to make sure that speaker is in player. speaker.transform.localPosition = Vector3.zero; }); // As example we will add clip audioPlayer.AddClip("shot"); } ``` -------------------------------- ### Loading Audio Clips (C#) Source: https://github.com/killers0992/audioplayerapi/blob/master/README.md This snippet shows how to load an audio clip into the AudioClipStorage. The clip is loaded from a specified file path and assigned a name for later use. Ensure the OGG file is MONO and has a frequency of 48Khz. ```C# // This method should be called when plugin loads. public void OnPluginLoad() { // Specify path for your ogg file and name it, this name will be used later for adding clips to audio players. // // Make sure that ogg file is MONO and frequency is 48Khz // AudioClipStorage.LoadClip("C:\\Users\\Kille\\Documents\\Serwer\\com.ogg", "shot"); } ``` -------------------------------- ### Creating Spectator-Only Audio Player (C#) Source: https://github.com/killers0992/audioplayerapi/blob/master/README.md Shows how to create an AudioPlayer that is only audible to players with a specific role, in this case, spectators. It uses a custom condition function within CreateOrGet to filter listeners and adds a non-spatial speaker. ```C# // Creates audio player which only spectators can hear. public void CreateSpectatorOnly() { AudioPlayer audioPlayer = AudioPlayer.CreateOrGet($"Spectator AudioPlayer", condition: (hub) => { // Only players which have spectator role will hear this sound. return hub.roleManager.CurrentRole.RoleTypeId == PlayerRoles.RoleTypeId.Spectator; } , onIntialCreation: (p) => { // This created speaker will be in 2D space ( audio will be always playing directly on you not from specific location ) but make sure that max distance is set to some higher value. Speaker speaker = p.AddSpeaker("Main", isSpatial: false, maxDistance: 5000f); }); audioPlayer.AddClip("shot"); } ``` -------------------------------- ### Removing Clip by ID (C#) Source: https://github.com/killers0992/audioplayerapi/blob/master/README.md Demonstrates how to store the ID of a playing clip obtained from the AddClip method and later use this ID to remove that specific playback instance. Note: The removal method is not fully shown in the provided snippet. ```C# int lobbyClipId = 0; // Execute this method via events when server is waiting for players. public void OnWaitingForPlayers() { AudioPlayer lobbyPlayer = AudioPlayer.CreateOrGet("Lobby", onIntialCreation: (p) => { p.AddSpeaker("Main", isSpatial: false, maxDistance: 5000f); }); AudioClipPlayback playback = lobbyPlayer.AddClip("lobby_music", loop: true); lobbyClipId = playback.Id; } // Execute this later... public void RemoveClipInLobby() { } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.