/// <summary>
        /// Send a sound to be played to a specific client
        /// </summary>
        /// <returns>The SoundSpawn Token generated that identifies the same sound spawn instance across server and clients</returns>
        public static string Send(GameObject recipient, 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.SendTo(recipient);

            return(soundSpawnToken);
        }
示例#2
0
        public static PlaySoundMessage Send(GameObject recipient, 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.SendTo(recipient);

            return(msg);
        }