Beispiel #1
0
        void FixedUpdate()
        {
            if (this.identity.IsMine())
            {
                if (this.isTalking)
                {
                    if (notRecording)
                    {
                        notRecording = false;
                        sendingClip  = Microphone.Start(null, true, 10, FREQUENCY);
                        sending      = true;
                    }
                    else if (sending)
                    {
                        int pos  = Microphone.GetPosition(null);
                        int diff = pos - lastSample;

                        if (diff > 1000)
                        {
                            float[] samples = new float[diff * sendingClip.channels];
                            sendingClip.GetData(samples, lastSample);

                            byte[] ba = ToByteArray(samples);

                            VoicePacket packet = new VoicePacket(ba, sendingClip.channels, this.identity.GetNetworkID());

                            NetworkManager.instance.GetSocket().Emit("Packet::Voice", JSONObject.Create(JsonUtility.ToJson(packet)));

                            lastSample = pos;
                        }
                    }
                }
                else
                {
                    if (sending)
                    {
                        this.sending = false;
                        Microphone.End(null);
                        notRecording = true;
                        sendingClip  = null;
                        lastSample   = 0;
                    }
                }
            }
        }
Beispiel #2
0
 public void EntityTalk(VoicePacket packet)
 {
     this.networkVoices[packet.entityId].PlayVoiceSound(packet.data, packet.channels);
 }
Beispiel #3
0
        private void EntityTalk(SocketIOEvent e)
        {
            VoicePacket packet = JsonUtility.FromJson <VoicePacket>(e.data.ToString());

            GameManager.instance.EntityTalk(packet);
        }