/// <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(); PlaySoundMessage msg = new PlaySoundMessage { SoundAddressablePath = addressableAudioSource.AssetAddress, Position = pos, Polyphonic = polyphonic, TargetNetId = netId, ShakeParameters = shakeParameters, AudioParameters = audioSourceParameters, SoundSpawnToken = soundSpawnToken }; msg.SendToNearbyPlayers(pos); return(soundSpawnToken); }
public static PlaySoundMessage SendToNearbyPlayers(string sndName, Vector3 pos, bool polyphonic = false, GameObject sourceObj = null, ShakeParameters shakeParameters = null, AudioSourceParameters audioSourceParameters = null) { var netId = NetId.Empty; if (sourceObj != null) { var netB = sourceObj.GetComponent <NetworkBehaviour>(); if (netB != null) { netId = netB.netId; } } PlaySoundMessage msg = new PlaySoundMessage { SoundName = sndName, Position = pos, Polyphonic = polyphonic, TargetNetId = netId, ShakeParameters = shakeParameters, AudioSourceParameters = audioSourceParameters }; msg.SendToNearbyPlayers(pos); return(msg); }