private void StopAndDispose(AudioHandle handle, bool remove = false) { var stream = GetAudio(handle); if (stream == null) { return; } stream.Dispose(); Destroy(stream.gameObject); if (remove) { _audios.RemoveAll(c => c.Handle == handle); } }
private bool CanPlayAudio(AudioHandle handle, bool isStream) { //check if total count of playing audios and queued autostart audios exceeds limit bool canPlayAudio = StreamExists(handle) || _audios.Count(c => c.StreamableAudioComponent.IsPlaying) + _queuedAudio.Count(c => !StreamExists(c.Handle) && c.AutoStart) < MAX_CONCURRENT_AUDIOS_PER_SERVER; if (!isStream) { return(canPlayAudio); } //check if total count of streamed audios and queued streamed audios exceeds limit bool canPlayStream = StreamExists(handle) || _audios.Count(c => c.IsStream) + _queuedAudio.Count(c => c.IsStream && !StreamExists(c.Handle)) < MAX_CONCURRENT_STREAMS_PER_SERVER; return(canPlayAudio && canPlayStream); }
/// <summary> /// Sets the audio rolloff mode. Custom is not supported. /// </summary> /// <param name="target">The SteamCall target</param> /// <param name="handle">The audio handle</param> /// <param name="mode">The target audio rolloff mode</param> public void SetRolloffMode(ESteamCall target, AudioHandle handle, AudioRolloffMode mode) { channel.send(nameof(AudioSteamCall_SetRolloffMode), target, ESteamPacket.UPDATE_RELIABLE_BUFFER, (int)handle, (int)mode); }
/// <summary> /// Determines how much doppler effect will be applied to this audio source (if is set to 0, then no effect is applied /// </summary> /// <param name="target">The SteamCall target</param> /// <param name="handle">The audio handle</param> /// <param name="level">Doppler level</param> public void SetDopplerLevel(ESteamCall target, AudioHandle handle, float level) { channel.send(nameof(AudioSteamCall_SetDopplerLevel), target, ESteamPacket.UPDATE_RELIABLE_BUFFER, (int)handle, level); }
/// <summary> /// Sets the spread angle to 3D stereo or multichannel sound in speaker space. /// </summary> /// <param name="target">The SteamCall target</param> /// <param name="handle">The audio handle</param> /// <param name="spread">Spread amount</param> public void SetSpread(ESteamCall target, AudioHandle handle, float spread) { channel.send(nameof(AudioSteamCall_SetSpread), target, ESteamPacket.UPDATE_RELIABLE_BUFFER, (int)handle, spread); }
/// <summary> /// Sets how much the 3D engine has an effect on the audio source /// </summary> /// <param name="target">The SteamCall target</param> /// <param name="handle">The audio handle</param> /// <param name="blend">Spatial blend amount</param> public void SetSpatialBlend(CSteamID target, AudioHandle handle, float blend) { channel.send(nameof(AudioSteamCall_SetSpatialBlend), target, ESteamPacket.UPDATE_RELIABLE_BUFFER, (int)handle, blend); }
/// <summary> /// Mutes or unmutes an audio /// </summary> /// <param name="target">The SteamCall target</param> /// <param name="handle">The audio handle</param> /// <param name="mute">Mute audio?</param> public void SetMute(ESteamCall target, AudioHandle handle, bool mute) { channel.send(nameof(AudioSteamCall_SetMute), target, ESteamPacket.UPDATE_RELIABLE_BUFFER, (int)handle, mute); }
/// <summary> /// Sets if an audio should loop /// </summary> /// <param name="target">The SteamCall target</param> /// <param name="handle">The audio handle</param> /// <param name="loop">Loop audio?</param> public void SetLoop(ESteamCall target, AudioHandle handle, bool loop) { channel.send(nameof(AudioSteamCall_SetLoop), target, ESteamPacket.UPDATE_RELIABLE_BUFFER, (int)handle, loop); }
/// <summary> /// Sets the volume of an audio /// </summary> /// <param name="target">The SteamCall target</param> /// <param name="handle">The audio handle</param> /// <param name="volume">The volume to set</param> public void SetVolume(ESteamCall target, AudioHandle handle, float volume) { channel.send(nameof(AudioSteamCall_SetVolume), target, ESteamPacket.UPDATE_RELIABLE_BUFFER, (int)handle, volume); }
/// <summary> /// Pauses an audio /// </summary> /// <param name="target">The SteamCall target</param> /// <param name="handle">The audio handle</param> public void Pause(CSteamID target, AudioHandle handle) { channel.send(nameof(AudioSteamCall_Pause), target, ESteamPacket.UPDATE_RELIABLE_BUFFER, (int)handle); }
/// <summary> /// Sets the min distance of an audio /// </summary> /// <param name="target">The SteamCall target</param> /// <param name="handle">The audio handle</param> /// <param name="minDistance">The max distance of the audio</param> public void SetMinDistance(ESteamCall target, AudioHandle handle, float minDistance) { channel.send(nameof(AudioSteamCall_SetMinDistance), target, ESteamPacket.UPDATE_RELIABLE_BUFFER, (int)handle, minDistance); }
/// <summary> /// Sets the position of an audio /// </summary> /// <param name="target">The SteamCall target</param> /// <param name="handle">The audio handle</param> /// <param name="pos">The target position (local if attached; global if not)</param> public void SetPosition(ESteamCall target, AudioHandle handle, Vector3 pos) { channel.send(nameof(AudioSteamCall_SetPosition), target, ESteamPacket.UPDATE_RELIABLE_BUFFER, (int)handle, pos); }
/// <summary> /// Attaches an audio to a vehicle (position gets reset) /// </summary> /// <param name="target">The SteamCall target</param> /// <param name="handle">The audio handle</param> /// <param name="targetVehicle">The id of the vehicle to attach to</param> public void AttachToVehicle(ESteamCall target, AudioHandle handle, InteractableVehicle targetVehicle) { channel.send(nameof(AudioSteamCall_AttachToVehicle), target, ESteamPacket.UPDATE_RELIABLE_BUFFER, (int)handle, targetVehicle.instanceID); }
/// <summary> /// Attaches an audio to a player (position gets reset) /// </summary> /// <param name="target">The SteamCall target</param> /// <param name="handle">The audio handle</param> /// <param name="targetPlayer">The player to attach to</param> public void AttachToPlayer(ESteamCall target, AudioHandle handle, SteamPlayer targetPlayer) { channel.send(nameof(AudioSteamCall_AttachToPlayer), target, ESteamPacket.UPDATE_RELIABLE_BUFFER, (int)handle, targetPlayer.playerID.steamID); }
private bool StreamExists(AudioHandle handle) { return(_audios.Any(c => c.Handle == handle)); }
/// <summary> /// Sets the interval of when the audio should refresh stream /// </summary> /// <param name="target">The SteamCall target</param> /// <param name="handle">The audio handle</param> /// <param name="interval">The interval</param> public void SetInterval(ESteamCall target, AudioHandle handle, float interval) { channel.send(nameof(AudioSteamCall_SetInterval), target, ESteamPacket.UPDATE_RELIABLE_BUFFER, (int)handle, interval); }
/// <summary> /// Destroys an audio to free resources /// </summary> /// <param name="target">The SteamCall target</param> /// <param name="handle">The audio handle</param> public void Destroy(ESteamCall target, AudioHandle handle) { channel.send(nameof(AudioSteamCall_Destroy), target, ESteamPacket.UPDATE_RELIABLE_BUFFER, (int)handle); }
private StreamableAudioComponent GetAudio(AudioHandle handle) { return(_audios.FirstOrDefault(c => c.Handle == handle)?.StreamableAudioComponent); }