Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        /// <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 ChangeAudioSourceParametersMessage SendToAll(string soundSpawnToken, AudioSourceParameters audioSourceParameters)
        {
            ChangeAudioSourceParametersMessage msg = new ChangeAudioSourceParametersMessage
            {
                SoundSpawnToken       = soundSpawnToken,
                AudioSourceParameters = audioSourceParameters
            };

            msg.SendToAll();

            return(msg);
        }
Ejemplo n.º 3
0
        /// <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 ChangeAudioSourceParametersMessage Send(GameObject recipient, string soundSpawnToken, AudioSourceParameters audioSourceParameters)
        {
            ChangeAudioSourceParametersMessage msg = new ChangeAudioSourceParametersMessage
            {
                SoundSpawnToken       = soundSpawnToken,
                AudioSourceParameters = audioSourceParameters
            };

            msg.SendTo(recipient);
            return(msg);
        }