public async Task Play() { // Too much damage stops the jukebox from being able to play if (integrity.integrity > integrity.initialIntegrity / 2) { SoundManager.StopNetworked(guid); IsPlaying = true; spriteHandler.SetSpriteSO(SpritePlaying); AudioSourceParameters audioSourceParameters = new AudioSourceParameters { MixerType = MixerType.Muffled, SpatialBlend = 1, // 3D, we need it to attenuate with distance Volume = Volume, MinDistance = MinSoundDistance, MaxDistance = MaxSoundDistance, VolumeRolloffType = VolumeRolloffType.EaseInAndOut, Spread = Spread }; guid = await SoundManager.PlayNetworkedAtPos(musics[currentSongTrackIndex], registerTile.WorldPositionServer, audioSourceParameters, false, true, gameObject); startPlayTime = Time.time; UpdateGUI(); } }
public void ServerSlip(bool slipWhileWalking = false) { if (this == null) { return; } // Don't slip while walking unless its enabled with "slipWhileWalking". // Don't slip while player's consious state is crit, soft crit, or dead. // Don't slip while the players hunger state is Strarving if (IsSlippingServer || !slipWhileWalking && playerScript.PlayerSync.SpeedServer <= playerScript.playerMove.WalkSpeed || playerScript.playerHealth.IsCrit || playerScript.playerHealth.IsSoftCrit || playerScript.playerHealth.IsDead || playerScript.playerHealth.Metabolism.HungerState == HungerState.Starving) { return; } ServerStun(); AudioSourceParameters audioSourceParameters = new AudioSourceParameters(pitch: Random.Range(0.9f, 1.1f)); SoundManager.PlayNetworkedAtPos(SingletonSOSounds.Instance.Slip, WorldPositionServer, audioSourceParameters, sourceObj: gameObject); // Let go of pulled items. playerScript.pushPull.ServerStopPulling(); }
public override void ServerBehaviour(AimApply interaction, bool isSuicide) { AudioSourceParameters hornParameters = new AudioSourceParameters(pitch: UnityEngine.Random.Range(0.7f, 1.2f)); SoundManager.PlayNetworkedAtPos(CommonSounds.Instance.ClownHonk, interaction.Performer.AssumedWorldPosServer(), hornParameters, true, sourceObj: interaction.Performer); }
protected void PinRemoval(InventoryApply interaction) { void ProgressFinishAction() { Chat.AddActionMsgToChat(interaction.Performer, $"You remove the {FiringPin.gameObject.ExpensiveName()} from {gameObject.ExpensiveName()}", $"{interaction.Performer.ExpensiveName()} removes the {FiringPin.gameObject.ExpensiveName()} from {gameObject.ExpensiveName()}."); SyncPredictionCanFire(predictionCanFire, false); Inventory.ServerDrop(pinSlot); } var bar = StandardProgressAction.Create(ProgressConfig, ProgressFinishAction) .ServerStartProgress(interaction.Performer.RegisterTile(), PinRemoveTime, interaction.Performer); if (bar != null) { Chat.AddActionMsgToChat(interaction.Performer, $"You begin removing the {FiringPin.gameObject.ExpensiveName()} from {gameObject.ExpensiveName()}", $"{interaction.Performer.ExpensiveName()} begins removing the {FiringPin.gameObject.ExpensiveName()} from {gameObject.ExpensiveName()}."); AudioSourceParameters audioSourceParameters = new AudioSourceParameters(UnityEngine.Random.Range(0.8f, 1.2f)); SoundManager.PlayNetworkedAtPos(SingletonSOSounds.Instance.WireCutter, interaction.Performer.AssumedWorldPosServer(), audioSourceParameters, sourceObj: serverHolder); } }
/// <summary> /// Hit for thrown (non-tile-snapped) items /// </summary> private void OnHit(Vector3Int pos, ThrowInfo info, IReadOnlyCollection <LivingHealthMasterBase> hitCreatures) { if (ItemAttributes == null) { return; } if (hitCreatures == null || hitCreatures.Count <= 0) { return; } foreach (var creature in hitCreatures) { if (creature.gameObject == info.ThrownBy) { continue; } //Remove cast to int when moving health values to float var damage = (int)(ItemAttributes.ServerThrowDamage); var hitZone = info.Aim.Randomize(); creature.ApplyDamageToBodyPart(info.ThrownBy, damage, AttackType.Melee, DamageType.Brute, hitZone); Chat.AddThrowHitMsgToChat(gameObject, creature.gameObject, hitZone); AudioSourceParameters audioSourceParameters = new AudioSourceParameters(pitch: 1f); SoundManager.PlayNetworkedAtPos(CommonSounds.Instance.GenericHit, transform.position, audioSourceParameters, sourceObj: gameObject); } }
/// <summary> /// Play sound for all clients. /// If more than one sound is specified, one will be picked at random. /// </summary> /// <param name="addressableAudioSources">List of sounds to be played. If more than one sound is specified, one will be picked at random</param> public static async Task PlayNetworked(List <AddressableAudioSource> addressableAudioSources, float pitch = -1, bool polyphonic = false, bool shakeGround = false, byte shakeIntensity = 64, int shakeRange = 30) { ShakeParameters shakeParameters = null; if (shakeGround == true) { shakeParameters = new ShakeParameters { ShakeGround = shakeGround, ShakeIntensity = shakeIntensity, ShakeRange = shakeRange }; } AudioSourceParameters audioSourceParameters = null; if (pitch > 0) { audioSourceParameters = new AudioSourceParameters { Pitch = pitch }; } AddressableAudioSource addressableAudioSource = await GetAddressableAudioSourceFromCache(addressableAudioSources); PlaySoundMessage.SendToAll(addressableAudioSource, TransformState.HiddenPos, polyphonic, null, shakeParameters, audioSourceParameters); }
/// <summary> /// Serverside: Play sound for all clients. /// Accepts "#" wildcards for sound variations. (Example: "Punch#") /// </summary> public static void PlayNetworked(string sndName, float pitch = -1, bool polyphonic = false, bool shakeGround = false, byte shakeIntensity = 64, int shakeRange = 30) { ShakeParameters shakeParameters = null; if (shakeGround == true) { shakeParameters = new ShakeParameters { ShakeGround = shakeGround, ShakeIntensity = shakeIntensity, ShakeRange = shakeRange }; } AudioSourceParameters audioSourceParameters = null; if (pitch > 0) { audioSourceParameters = new AudioSourceParameters { Pitch = pitch }; } sndName = Instance.ResolveSoundPattern(sndName); PlaySoundMessage.SendToAll(sndName, TransformState.HiddenPos, polyphonic, null, shakeParameters, audioSourceParameters); }
public void ServerPerformInteraction(HandApply interaction) { GameObject target = interaction.TargetObject; GameObject performer = interaction.Performer; void ProgressFinishAction() { if (performer.GetComponent <PlayerScript>()?.IsGameObjectReachable(target, true) ?? false) { target.GetComponent <PlayerMove>().Cuff(interaction); Chat.AddActionMsgToChat(performer, $"You successfully restrain {target.ExpensiveName()}.", $"{performer.ExpensiveName()} successfully restrains {target.ExpensiveName()}."); } } var bar = StandardProgressAction.Create(ProgressConfig, ProgressFinishAction) .ServerStartProgress(target.RegisterTile(), applyTime, performer); if (bar != null) { AudioSourceParameters soundParameters = new AudioSourceParameters(pitch: randomPitch); SoundManager.PlayNetworkedAtPos(applySound, target.transform.position, soundParameters, sourceObj: target.gameObject); Chat.AddActionMsgToChat(performer, $"You begin restraining {target.ExpensiveName()}...", $"{performer.ExpensiveName()} begins restraining {target.ExpensiveName()}..."); } }
/// <summary> /// Serverside: Play sound at given position for all clients. /// </summary> /// <param name="addressableAudioSource">The sound to be played.</param> /// <param name="worldPos">The position at which the sound is played</param> /// <param name="audioSourceParameters">Extra parameters of the audio source.</param> /// <param name="polyphonic">Is the sound to be played polyphonic</param> /// <param name="global">Does everyone will receive the sound our just nearby players</param> /// <param name="shakeParameters">Camera shake effect associated with this sound</param> /// <param name="sourceObj">The object that is the source of the sound</param> /// <returns>The SoundSpawn Token generated that identifies the same sound spawn instance across server and clients</returns> public static async Task <string> PlayNetworkedAtPosAsync(AddressableAudioSource addressableAudioSource, Vector3 worldPos, AudioSourceParameters audioSourceParameters = new AudioSourceParameters(), bool polyphonic = false, bool global = true, ShakeParameters shakeParameters = new ShakeParameters(), GameObject sourceObj = null) { if (addressableAudioSource == null || string.IsNullOrEmpty(addressableAudioSource.AssetAddress) || addressableAudioSource.AssetAddress == "null") { Logger.LogWarning($"SoundManager received a null AudioSource to be played at World Position: {worldPos}", Category.Audio); return(null); } addressableAudioSource = await AudioManager.GetAddressableAudioSourceFromCache(addressableAudioSource); if (global) { return(PlaySoundMessage.SendToAll(addressableAudioSource, worldPos, polyphonic, sourceObj, shakeParameters, audioSourceParameters)); } else { return(PlaySoundMessage.SendToNearbyPlayers(addressableAudioSource, worldPos, polyphonic, sourceObj, shakeParameters, audioSourceParameters)); } }
/// <summary> /// Play footsteps at given position. It will handle all the logic to determine /// the proper sound to use. /// </summary> /// <param name="worldPos">Where in the world is this sound coming from. Also used to get the type of tile</param> /// <param name="stepType">What kind of step does the creature walking have</param> /// <param name="performer">The creature making the sound</param> public static void FootstepAtPosition(Vector3 worldPos, StepType stepType, GameObject performer) { MatrixInfo matrix = MatrixManager.AtPoint(worldPos.NormalizeToInt(), false); var locPos = matrix.ObjectParent.transform.InverseTransformPoint(worldPos).RoundToInt(); var tile = matrix.MetaTileMap.GetTile(locPos) as BasicTile; if (tile != null) { if (step) { AudioSourceParameters audioSourceParameters = new AudioSourceParameters { Pitch = Random.Range(0.7f, 1.2f) }; PlayNetworkedAtPos( Instance.stepSounds[stepType][tile.floorTileType].PickRandom(), worldPos, audioSourceParameters, polyphonic: true, Global: false, sourceObj: performer ); } step = !step; } }
/// <summary> /// Play a sound locally /// If more than one is specified, one will be picked at random. /// </summary> /// <param name="addressableAudioSources">The sound to be played. If more than one is specified, one will be picked at random.</param> /// <param name="soundSpawnToken">The SoundSpawn Token that identifies the same sound spawn instance across server and clients</returns> /// <param name="audioSourceParameters">Parameters for how to play the sound</param> /// <param name="polyphonic">Should the sound be played polyphonically</param> public static async Task Play(List <AddressableAudioSource> addressableAudioSources, string soundSpawnToken = "", AudioSourceParameters audioSourceParameters = new AudioSourceParameters(), bool polyphonic = false) { AddressableAudioSource addressableAudioSource = addressableAudioSources.PickRandom(); await Play(addressableAudioSource, soundSpawnToken, audioSourceParameters, polyphonic); }
/// <summary> /// Serverside: Play sound at given position for particular player. /// ("Doctor, there are voices in my head!") /// If more than one is specified, one will be picked at random. /// </summary> /// <param name="addressableAudioSources">The sound to be played. If more than one is specified, one will be picked at random.</param> public static async Task PlayNetworkedForPlayerAtPos(GameObject recipient, Vector3 worldPos, List <AddressableAudioSource> addressableAudioSources, float pitch = -1, bool polyphonic = false, bool shakeGround = false, byte shakeIntensity = 64, int shakeRange = 30, GameObject sourceObj = null) { ShakeParameters shakeParameters = null; if (shakeGround) { shakeParameters = new ShakeParameters { ShakeGround = shakeGround, ShakeIntensity = shakeIntensity, ShakeRange = shakeRange }; } AudioSourceParameters audioSourceParameters = null; if (pitch > 0) { audioSourceParameters = new AudioSourceParameters { Pitch = pitch }; } AddressableAudioSource addressableAudioSource = await GetAddressableAudioSourceFromCache(addressableAudioSources); PlaySoundMessage.Send(recipient, addressableAudioSource, worldPos, polyphonic, sourceObj, shakeParameters, audioSourceParameters); }
/// <summary> /// Changes the Audio Source Parameters of a sound /// </summary> /// <param name="soundName">The name of the sound to change the mixer</param> /// <param name="audioSourceParameters">The Audio Source Parameters to apply</param> public static void ChangeAudioSourceParameters(string soundName, AudioSourceParameters audioSourceParameters) { if (Instance.sounds.ContainsKey(soundName)) { AudioSource sound = Instance.sounds[soundName]; for (int i = Instance.pooledSources.Count - 1; i > 0; i--) { if (Instance.pooledSources[i] == null) { continue; } if (Instance.pooledSources[i].isPlaying && Instance.pooledSources[i].audioSource.clip == sound.clip) { ApplyAudioSourceParameters(audioSourceParameters, Instance.pooledSources[i].audioSource); } } if (sound != null) { ApplyAudioSourceParameters(audioSourceParameters, sound); } } }
/// <summary> /// Play footsteps at given position. It will handle all the logic to determine /// the proper sound to use. /// </summary> /// <param name="worldPos">Where in the world is this sound coming from. Also used to get the type of tile</param> /// <param name="stepType">What kind of step does the creature walking have</param> /// <param name="performer">The creature making the sound</param> public static void FootstepAtPosition(Vector3 worldPos, StepType stepType, FloorSounds Override = null) { MatrixInfo matrix = MatrixManager.AtPoint(worldPos.RoundToInt(), false); if (matrix == null) { return; } var locPos = matrix.ObjectParent.transform.InverseTransformPoint(worldPos).RoundToInt(); var tile = matrix.MetaTileMap.GetTile(locPos) as BasicTile; if (tile != null) { FloorSounds FloorTileSounds = tile.floorTileSounds; List <AddressableAudioSource> AddressableAudioSource = null; if (Override != null && tile.CanSoundOverride == false) { FloorTileSounds = Override; } switch (stepType) { case StepType.None: return; case StepType.Barefoot: AddressableAudioSource = FloorTileSounds?.Barefoot; if (FloorTileSounds == null || AddressableAudioSource.Count > 0) { AddressableAudioSource = Instant.DefaultFloorSound.Barefoot; } break; case StepType.Shoes: AddressableAudioSource = FloorTileSounds?.Shoes; if (FloorTileSounds == null || AddressableAudioSource.Count > 0) { AddressableAudioSource = Instant.DefaultFloorSound.Shoes; } break; case StepType.Claw: AddressableAudioSource = FloorTileSounds?.Claw; if (FloorTileSounds == null || AddressableAudioSource.Count > 0) { AddressableAudioSource = Instant.DefaultFloorSound.Claw; } break; } if (AddressableAudioSource == null) { return; } AudioSourceParameters audioSourceParameters = new AudioSourceParameters(pitch: Random.Range(0.7f, 1.2f)); SoundManager.PlayNetworkedAtPos(AddressableAudioSource.PickRandom(), worldPos, audioSourceParameters, polyphonic: true); } }
/// <summary> /// Serverside: Play sound at given position for all clients. /// Accepts "#" wildcards for sound variations. (Example: "Punch#") /// </summary> public static void PlayNetworkedAtPos(string sndName, Vector3 worldPos, float pitch = -1, bool polyphonic = false, bool shakeGround = false, byte shakeIntensity = 64, int shakeRange = 30, bool global = true, GameObject sourceObj = null) { ShakeParameters shakeParameters = null; if (shakeGround == true) { shakeParameters = new ShakeParameters { ShakeGround = shakeGround, ShakeIntensity = shakeIntensity, ShakeRange = shakeRange }; } AudioSourceParameters audioSourceParameters = null; if (pitch > 0) { audioSourceParameters = new AudioSourceParameters { Pitch = pitch }; } PlayNetworkedAtPos(sndName, worldPos, audioSourceParameters, polyphonic, global, sourceObj, shakeParameters); }
public void ServerPerformInteraction(AimApply interaction) { //just in case if (reagentContainer == null) { return; } if (reagentContainer.ReagentMixTotal < reagentsPerUse) { return; } Vector2 startPos = gameObject.AssumedWorldPosServer(); Vector2 targetPos = new Vector2(Mathf.RoundToInt(interaction.WorldPositionTarget.x), Mathf.RoundToInt(interaction.WorldPositionTarget.y)); List <Vector3Int> positionList = CheckPassableTiles(startPos, targetPos); StartCoroutine(Fire(positionList)); Effect.PlayParticleDirectional(this.gameObject, interaction.TargetVector); AudioSourceParameters audioSourceParameters = new AudioSourceParameters(pitch: 1); SoundManager.PlayNetworkedAtPos(Spray2, startPos, audioSourceParameters, sourceObj: interaction.Performer); interaction.Performer.Pushable()?.NewtonianMove((-interaction.TargetVector).NormalizeToInt(), speed: 1f); }
/// <summary> /// Play explosion sound and shake ground /// </summary> /// <param name="worldPosition">position explosion is centered at</param> /// <param name="shakeIntensity">intensity of shaking</param> /// <param name="shakeDistance">how far away the shaking can be felt</param> public static void PlaySoundAndShake(Vector3Int worldPosition, byte shakeIntensity, int shakeDistance) { AddressableAudioSource explosionSound = EXPLOSION_SOUNDS.PickRandom(); AddressableAudioSource groanSound = STATION_GROAN_SOUNDS.PickRandom(); AddressableAudioSource distantSound = DISTANT_EXPLOSION_SOUNDS.PickRandom(); AudioSourceParameters audioSourceParameters = new AudioSourceParameters(0f, 100f); ShakeParameters shakeParameters = new ShakeParameters(true, shakeIntensity, shakeDistance); //Closet sound _ = SoundManager.PlayNetworkedAtPosAsync(explosionSound, worldPosition, audioSourceParameters, true, false, shakeParameters); //Next sound if (distantSound != null) { AudioSourceParameters distantSoundAudioSourceParameters = new AudioSourceParameters(0f, 100f, minDistance: 29, maxDistance: 63); _ = SoundManager.PlayNetworkedAtPosAsync(distantSound, worldPosition, distantSoundAudioSourceParameters); } //Furthest away sound if (groanSound != null) { AudioSourceParameters groanSoundAudioSourceParameters = new AudioSourceParameters(0f, 100f, minDistance: 63, maxDistance: 200); _ = SoundManager.PlayNetworkedAtPosAsync(groanSound, worldPosition, groanSoundAudioSourceParameters); } }
public static void DoReport() { if (CustomNetworkManager.IsServer == false) { return; } foreach (ConnectedPlayer player in PlayerList.Instance.InGamePlayers) { var ps = player.Script; if (ps.IsDeadOrGhost) { continue; } if (ps.PlayerSync.IsMovingServer) { var plantPos = ps.WorldPos + ps.CurrentDirection.Vector; Spawn.ServerPrefab("Banana peel", plantPos, cancelIfImpassable: true); } foreach (var pos in ps.WorldPos.BoundsAround().allPositionsWithin) { var matrixInfo = MatrixManager.AtPoint(pos, true); var localPos = MatrixManager.WorldToLocalInt(pos, matrixInfo); matrixInfo.MetaDataLayer.Clean(pos, localPos, true); } } AudioSourceParameters audioSourceParameters = new AudioSourceParameters(pitch: Random.Range(0.2f, 0.5f)); ShakeParameters shakeParameters = new ShakeParameters(true, 64, 30); _ = SoundManager.PlayNetworked(CommonSounds.Instance.ClownHonk, audioSourceParameters, true, shakeParameters); }
/// <Summary> /// Completely overwrites AudioSourceParameters of a Sound to any value. /// Only use this if you have a known entry for all parameters, otherwise the sound will /// not play properly (eg, having no entry for pitch will make the sound never start or finish) /// </Summary> private static void ForceAudioSourceParameters(AudioSourceParameters audioSourceParameters, SoundSpawn soundSpawn) { AudioSource audioSource = soundSpawn.AudioSource; audioSource.volume = audioSourceParameters.Volume; audioSource.pitch = audioSourceParameters.Pitch; audioSource.time = audioSourceParameters.Time; audioSource.panStereo = audioSourceParameters.Pan; audioSource.spatialBlend = audioSourceParameters.SpatialBlend; audioSource.minDistance = audioSourceParameters.MinDistance; audioSource.maxDistance = audioSourceParameters.MaxDistance; audioSource.spread = audioSourceParameters.Spread; audioSource.outputAudioMixerGroup = Instance.CalcAudioMixerGroup(audioSourceParameters.MixerType); switch (audioSourceParameters.VolumeRolloffType) { case VolumeRolloffType.EaseInAndOut: audioSource.rolloffMode = AudioRolloffMode.Custom; audioSource.SetCustomCurve(AudioSourceCurveType.CustomRolloff, AnimationCurve.EaseInOut(0, 1, 1, 0)); break; case VolumeRolloffType.Linear: audioSource.rolloffMode = AudioRolloffMode.Linear; break; case VolumeRolloffType.Logarithmic: audioSource.rolloffMode = AudioRolloffMode.Logarithmic; break; } }
public void ServerPerformInteraction(HandApply interaction) { panelopen = !panelopen; if (panelopen) { DoorAnimatorV2.AddPanelOverlay(); Chat.AddActionMsgToChat(interaction.Performer, $"You unscrews the {gameObject.ExpensiveName()}'s cable panel.", $"{interaction.Performer.ExpensiveName()} unscrews {gameObject.ExpensiveName()}'s cable panel."); } else { DoorAnimatorV2.RemovePanelOverlay(); Chat.AddActionMsgToChat(interaction.Performer, $"You screw in the {gameObject.ExpensiveName()}'s cable panel.", $"{interaction.Performer.ExpensiveName()} screws in {gameObject.ExpensiveName()}'s cable panel."); //Force close net tab when panel is closed TabUpdateMessage.SendToPeepers(gameObject, NetTabType.HackingPanel, TabAction.Close); } AudioSourceParameters audioSourceParameters = new AudioSourceParameters(pitch: UnityEngine.Random.Range(0.8f, 1.2f)); SoundManager.PlayNetworkedAtPos(CommonSounds.Instance.screwdriver, interaction.Performer.AssumedWorldPosServer(), audioSourceParameters, sourceObj: gameObject); }
public void ServerPerformInteraction(PositionalHandApply interaction) { var interactableTiles = interaction.TargetObject.GetComponent <InteractableTiles>(); var wallTile = interactableTiles.MetaTileMap.GetTileAtWorldPos(interaction.WorldPositionTarget, LayerType.Walls) as BasicTile; var calculatedMineTime = wallTile.MiningTime * timeMultiplier; void FinishMine() { if (interactableTiles == null) { Logger.LogError("No interactable tiles found, mining cannot be finished", Category.TileMaps); } else { AudioSourceParameters parameters = new AudioSourceParameters(0, 100f); _ = SoundManager.PlayNetworkedAtPosAsync(CommonSounds.Instance.BreakStone, interaction.WorldPositionTarget, parameters); var cellPos = interactableTiles.MetaTileMap.WorldToCell(interaction.WorldPositionTarget); var tile = interactableTiles.LayerTileAt(interaction.WorldPositionTarget) as BasicTile; Spawn.ServerPrefab(tile.SpawnOnDeconstruct, interaction.WorldPositionTarget, count: tile.SpawnAmountOnDeconstruct); interactableTiles.TileChangeManager.MetaTileMap.RemoveTileWithlayer(cellPos, LayerType.Walls); interactableTiles.TileChangeManager.MetaTileMap.RemoveOverlaysOfType(cellPos, LayerType.Effects, OverlayType.Mining); } } objectName = wallTile.DisplayName; SoundManager.PlayNetworkedAtPos(pickaxeSound, interaction.WorldPositionTarget); ToolUtils.ServerUseToolWithActionMessages( interaction, calculatedMineTime, $"You start mining the {objectName}...", $"{interaction.Performer.ExpensiveName()} starts mining the {objectName}...",
public void ServerPerformInteraction(AimApply interaction) { if (reagentContainer.ReagentMixTotal < reagentsPerUse || safety) { return; } Vector2 startPos = gameObject.AssumedWorldPosServer(); Vector2 targetPos = interaction.WorldPositionTarget.To2Int(); List <Vector3Int> positionList = CheckPassableTiles(startPos, targetPos); StartCoroutine(Fire(positionList)); var points = GetParallelPoints(startPos, targetPos, true); positionList = CheckPassableTiles(points[0], points[1]); StartCoroutine(Fire(positionList)); points = GetParallelPoints(startPos, targetPos, false); positionList = CheckPassableTiles(points[0], points[1]); StartCoroutine(Fire(positionList)); Effect.PlayParticleDirectional(this.gameObject, interaction.TargetVector); AudioSourceParameters audioSourceParameters = new AudioSourceParameters(pitch: 1); SoundManager.PlayNetworkedAtPos(SpraySound, startPos, audioSourceParameters, sourceObj: interaction.Performer); interaction.Performer.Pushable()?.NewtonianMove((-interaction.TargetVector).NormalizeToInt()); }
/// <summary> /// Serverside: Play sound at given position for all clients. /// Please use PlayNetworkedAtPosAsync if possible. /// </summary> /// <param name="addressableAudioSource">The sound to be played.</param> /// <param name="worldPos">The position at which the sound is played</param> /// <param name="audioSourceParameters">Extra parameters of the audio source.</param> /// <param name="polyphonic">Is the sound to be played polyphonic</param> /// <param name="global">Does everyone will receive the sound our just nearby players</param> /// <param name="shakeParameters">Camera shake effect associated with this sound</param> /// <param name="sourceObj">The object that is the source of the sound</param> /// <returns>The SoundSpawn Token generated that identifies the same sound spawn instance across server and clients</returns> public static void PlayNetworkedAtPos(AddressableAudioSource addressableAudioSource, Vector3 worldPos, AudioSourceParameters audioSourceParameters = new AudioSourceParameters(), bool polyphonic = false, bool global = true, ShakeParameters shakeParameters = new ShakeParameters(), GameObject sourceObj = null) { _ = PlayNetworkedAtPosAsync(addressableAudioSource, worldPos, audioSourceParameters, polyphonic, global, shakeParameters, sourceObj); }
/// <summary> /// Serverside: Play sound at given position for particular player. /// ("Doctor, there are voices in my head!") /// Accepts "#" wildcards for sound variations. (Example: "Punch#") /// </summary> public static void PlayNetworkedForPlayerAtPos(GameObject recipient, Vector3 worldPos, string sndName, float pitch = -1, bool polyphonic = false, bool shakeGround = false, byte shakeIntensity = 64, int shakeRange = 30, GameObject sourceObj = null) { ShakeParameters shakeParameters = null; if (shakeGround) { shakeParameters = new ShakeParameters { ShakeGround = shakeGround, ShakeIntensity = shakeIntensity, ShakeRange = shakeRange }; } AudioSourceParameters audioSourceParameters = null; if (pitch > 0) { audioSourceParameters = new AudioSourceParameters { Pitch = pitch }; } sndName = Instance.ResolveSoundPattern(sndName); PlaySoundMessage.Send(recipient, sndName, worldPos, polyphonic, sourceObj, shakeParameters, audioSourceParameters); }
/// <summary> /// Play footsteps at given position. It will handle all the logic to determine /// the proper sound to use. /// </summary> /// <param name="worldPos">Where in the world is this sound coming from. Also used to get the type of tile</param> /// <param name="stepType">What kind of step does the creature walking have</param> /// <param name="override">if assigned, it will override the default footstep sound.</param> private static void FootstepAtPosition(Vector3 worldPos, StepType stepType, FloorSounds @override = null, GameObject footstepSource = null) { var matrix = MatrixManager.AtPoint(worldPos.RoundToInt(), false); if (matrix == null) { return; } var locPos = matrix.ObjectParent.transform.InverseTransformPoint(worldPos).RoundToInt(); var tile = matrix.MetaTileMap.GetTile(locPos) as BasicTile; if (tile == null) { return; } var floorTileSounds = @override ? @override : tile.floorTileSounds; List <AddressableAudioSource> addressableAudioSource; switch (stepType) { case StepType.None: return; case StepType.Barefoot: addressableAudioSource = floorTileSounds.OrNull()?.Barefoot; if (addressableAudioSource is null || addressableAudioSource.Count == 0) { addressableAudioSource = instance.defaultFloorSound.Barefoot; } break; case StepType.Shoes: addressableAudioSource = floorTileSounds.OrNull()?.Shoes; if (addressableAudioSource is null || addressableAudioSource.Count == 0) { addressableAudioSource = instance.defaultFloorSound.Shoes; } break; case StepType.Claw: addressableAudioSource = floorTileSounds.OrNull()?.Claw; if (addressableAudioSource is null || addressableAudioSource.Count == 0) { addressableAudioSource = instance.defaultFloorSound.Claw; } break; default: addressableAudioSource = instance.defaultFloorSound.Shoes; break; } var audioSourceParameters = new AudioSourceParameters(pitch: Random.Range(0.7f, 1.2f)); SoundManager.PlayNetworkedAtPos(addressableAudioSource.PickRandom(), worldPos, audioSourceParameters, true, false, default, footstepSource);
public static string PlayNetworkedAtPos(string addressableAudioSource, Vector3 worldPos, AudioSourceParameters audioSourceParameters, bool polyphonic = false, bool Global = true, GameObject sourceObj = null, ShakeParameters shakeParameters = null) { Logger.LogWarning("Sound needs to be converted to addressables " + addressableAudioSource); return(""); }
public void ServerToggleClosed(bool?nowClosed = null) { AudioSourceParameters audioSourceParameters = new AudioSourceParameters(pitch: 1f); SoundManager.PlayNetworkedAtPos(IsClosed ? soundOnOpen : soundOnClose, registerTile.WorldPositionServer, audioSourceParameters, sourceObj: gameObject); ServerSetIsClosed(nowClosed.GetValueOrDefault(!IsClosed)); }
private void Disassemble(HandApply interaction) { Spawn.ServerPrefab(matsOnDeconstruct, registerObject.WorldPositionServer, count: countOfMatsOnDissasemle); AudioSourceParameters audioSourceParameters = new AudioSourceParameters(pitch: 1f); SoundManager.PlayNetworkedAtPos(soundOnDeconstruct, gameObject.TileWorldPosition().To3Int(), audioSourceParameters, sourceObj: gameObject); _ = Despawn.ServerSingle(gameObject); }
/// <summary> /// Changes the Audio Source Parameters of a sound currently playing /// </summary> /// <param name="soundSpawnToken">The Token of the sound spawn to change the parameters</param> /// <param name="audioSourceParameters">The Audio Source Parameters to apply</param> public static void ChangeAudioSourceParameters(string soundSpawnToken, AudioSourceParameters audioSourceParameters) { if (Instance.SoundSpawns.ContainsKey(soundSpawnToken)) { SoundSpawn soundSpawn = Instance.SoundSpawns[soundSpawnToken]; ApplyAudioSourceParameters(audioSourceParameters, soundSpawn); } }
/// <summary> /// Play sound from a list for all clients. /// If more than one sound is specified, one will be picked at random. /// </summary> /// <param name="addressableAudioSources">A list of sounds. One will be played at random</param> /// <param name="audioSourceParameters">Extra parameters of the audio source</param> /// <param name="polyphonic">Is the sound to be played polyphonic</param> /// <param name="shakeParameters">Camera shake effect associated with this sound</param> public static string PlayNetworked(List <AddressableAudioSource> addressableAudioSources, AudioSourceParameters audioSourceParameters = new AudioSourceParameters(), bool polyphonic = false, ShakeParameters shakeParameters = new ShakeParameters()) { AddressableAudioSource addressableAudioSource = addressableAudioSources.PickRandom(); return(PlayNetworked(addressableAudioSource, audioSourceParameters, polyphonic, shakeParameters)); }