/// <summary> /// Send a Music to be played to a specific client /// </summary> /// <returns>The MusicSpawn Token generated that identifies the same Music spawn instance across server and clients</returns> public static void Send(GameObject recipient, AddressableAudioSource addressableAudioSource, Vector3 pos, GameObject sourceObj = null, AudioSourceParameters audioSourceParameters = new AudioSourceParameters()) { var netId = NetId.Empty; if (sourceObj != null) { var netB = sourceObj.GetComponent <NetworkBehaviour>(); if (netB != null) { netId = netB.netId; } } NetMessage msg = new NetMessage { MusicAddressablePath = addressableAudioSource.AssetAddress, TargetNetId = netId, AudioParameters = audioSourceParameters }; SendTo(recipient, msg); }
/// <summary> /// Send a sound to be played to all nearby players /// </summary> /// <returns>The SoundSpawn Token generated that identifies the same sound spawn instance across server and clients</returns> public static string SendToNearbyPlayers(AddressableAudioSource addressableAudioSource, Vector3 pos, bool polyphonic = false, GameObject sourceObj = null, ShakeParameters shakeParameters = new ShakeParameters(), AudioSourceParameters audioSourceParameters = new AudioSourceParameters()) { var netId = NetId.Empty; if (sourceObj != null) { var netB = sourceObj.GetComponent <NetworkBehaviour>(); if (netB != null) { netId = netB.netId; } } string soundSpawnToken = Guid.NewGuid().ToString(); NetMessage msg = new NetMessage { SoundAddressablePath = addressableAudioSource.AssetAddress, Position = pos, Polyphonic = polyphonic, TargetNetId = netId, ShakeParameters = shakeParameters, AudioParameters = audioSourceParameters, SoundSpawnToken = soundSpawnToken }; SendToNearbyPlayers(pos, msg); return(soundSpawnToken); }
/// <summary> /// Send a Music to be played to all clients /// </summary> /// <returns>The MusicSpawn Token generated that identifies the same Music spawn instance across server and clients</returns> public static void SendToAll(AddressableAudioSource addressableAudioSource, AudioSourceParameters audioSourceParameters = new AudioSourceParameters()) { NetMessage msg = new NetMessage { MusicAddressablePath = addressableAudioSource.AssetAddress, AudioParameters = audioSourceParameters, }; SendToAll(msg); }
/// <summary> /// Send to all client to change the mixer of a playing sound /// </summary> /// <param name="soundSpawnToken">The token that identifies the SoundSpawn uniquely among the server and all clients </param> /// <param name="audioSourceParameters">The Audio Source Parameters to apply.</param> /// <returns>The sent message</returns> public static NetMessage SendToAll(string soundSpawnToken, AudioSourceParameters audioSourceParameters) { NetMessage msg = new NetMessage { SoundSpawnToken = soundSpawnToken, AudioSourceParameters = audioSourceParameters }; SendToAll(msg); return(msg); }
/// <summary> /// Send to a specific client to change the Audio Source Parameters of a playing sound /// </summary> /// <param name="recipient">The recipient of the message to be sent.</param> /// <param name="soundSpawnToken">The token that identifies the SoundSpawn uniquely among the server and all clients </param> /// <param name="audioSourceParameters">The Audio Source Parameters to apply.</param> /// <returns>The sent message</returns> public static NetMessage Send(GameObject recipient, string soundSpawnToken, AudioSourceParameters audioSourceParameters) { NetMessage msg = new NetMessage { SoundSpawnToken = soundSpawnToken, AudioSourceParameters = audioSourceParameters }; SendTo(recipient, msg); return(msg); }