コード例 #1
0
    /// <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));
        }
    }
コード例 #2
0
    public static PlaySoundMessage SendToNearbyPlayers(string sndName, Vector3 pos, float pitch,
                                                       bool polyphonic  = false,
                                                       bool shakeGround = false, byte shakeIntensity = 64, int shakeRange = 30, GameObject sourceObj = 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,
            Pitch          = pitch,
            ShakeGround    = shakeGround,
            ShakeIntensity = shakeIntensity,
            ShakeRange     = shakeRange,
            Polyphonic     = polyphonic,
            TargetNetId    = netId
        };

        msg.SendToNearbyPlayers(pos);
        return(msg);
    }
コード例 #3
0
 /// <summary>
 /// Serverside: Play sound at given position for all clients.
 /// Accepts "#" wildcards for sound variations. (Example: "Punch#")
 /// </summary>
 /// <param name="sndName">The name of the sound to be played</param>
 /// <param name="worldPos">The position at which the sound is played</param>
 /// <param name="polyphonic">Is the sound to be played polyphonic</param>
 /// <param name="audioSourceParameters">Extra parameters of the audio source.</param>
 /// <param name="Global">Does everyone will receive the sound our just nearby players</param>
 /// <param name="sourceObj">The object that is the source of the sound</param>
 /// <param name="shakeParameters">Camera shake effect associated with this sound</param>
 public static void PlayNetworkedAtPos(string sndName, Vector3 worldPos, AudioSourceParameters audioSourceParameters, bool polyphonic = false, bool Global = true, GameObject sourceObj = null, ShakeParameters shakeParameters = null)
 {
     sndName = Instance.ResolveSoundPattern(sndName);
     if (Global)
     {
         PlaySoundMessage.SendToAll(sndName, worldPos, polyphonic, sourceObj, shakeParameters, audioSourceParameters);
     }
     else
     {
         PlaySoundMessage.SendToNearbyPlayers(sndName, worldPos, polyphonic, sourceObj, shakeParameters, audioSourceParameters);
     }
 }
コード例 #4
0
 /// <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)
 {
     sndName = Instance.ResolveSoundPattern(sndName);
     if (Global)
     {
         PlaySoundMessage.SendToAll(sndName, worldPos, pitch, polyphonic, shakeGround, shakeIntensity, shakeRange);
     }
     else
     {
         PlaySoundMessage.SendToNearbyPlayers(sndName, worldPos, pitch, polyphonic, shakeGround, shakeIntensity, shakeRange);
     }
 }
コード例 #5
0
    /// <summary>
    /// Serverside: Play sound at given position for all clients.
    /// If more than one sound is specified, the sound will be chosen at random
    /// </summary>
    /// <param name="addressableAudioSources">The sound to be played.  If more than one is specified, a single one will be picked at random</param>
    /// <param name="worldPos">The position at which the sound is played</param>
    /// <param name="polyphonic">Is the sound to be played polyphonic</param>
    /// <param name="audioSourceParameters">Extra parameters of the audio source.</param>
    /// <param name="Global">Does everyone will receive the sound our just nearby players</param>
    /// <param name="sourceObj">The object that is the source of the sound</param>
    /// <param name="shakeParameters">Camera shake effect associated with this sound</param>
    /// <returns>The SoundSpawn Token generated that identifies the same sound spawn instance across server and clients</returns>
    public static async Task <string> PlayNetworkedAtPos(List <AddressableAudioSource> addressableAudioSources, Vector3 worldPos, AudioSourceParameters audioSourceParameters,
                                                         bool polyphonic = false, bool Global = true, GameObject sourceObj = null, ShakeParameters shakeParameters = null)
    {
        AddressableAudioSource addressableAudioSource = await GetAddressableAudioSourceFromCache(addressableAudioSources);

        if (Global)
        {
            return(PlaySoundMessage.SendToAll(addressableAudioSource, worldPos, polyphonic, sourceObj, shakeParameters, audioSourceParameters));
        }
        else
        {
            return(PlaySoundMessage.SendToNearbyPlayers(addressableAudioSource, worldPos, polyphonic, sourceObj, shakeParameters, audioSourceParameters));
        }
    }
コード例 #6
0
    public static PlaySoundMessage SendToNearbyPlayers(string sndName, Vector3 pos, float pitch,
                                                       bool polyphonic  = false,
                                                       bool shakeGround = false, byte shakeIntensity = 64, int shakeRange = 30)
    {
        PlaySoundMessage msg = new PlaySoundMessage
        {
            SoundName      = sndName,
            Position       = pos,
            Pitch          = pitch,
            ShakeGround    = shakeGround,
            ShakeIntensity = shakeIntensity,
            ShakeRange     = shakeRange,
            Polyphonic     = polyphonic
        };

        msg.SendToNearbyPlayers(pos);
        return(msg);
    }