示例#1
0
 void OnPacketReceived(IFMPacket packet)
 {
     lock (queue)
     {
         queue.Enqueue(packet);
     }
 }
示例#2
0
 public static void ApplyBlendshapes(IFMPacket packet, SkinnedMeshRenderer[] smrs)
 {
     foreach (BlendshapeData data in packet.Blendshapes)
     {
         data.SetBlendshapeForRenderers(smrs);
     }
 }
示例#3
0
        /**
         * Gets any recent data from udpClient on port 49983.
         * - If data is received from a remote IP and not previously connected, send handshake confirmation to client
         * - Process data in Packet
         * - When succesfully Parsed add to  queue.
         */
        private void ReceiveCycle()
        {
            try
            {
                IPEndPoint remoteIP = null;
                byte[]     data     = udpClient.Receive(ref remoteIP);

                // TODO: Allow for multiple inputs?
                if (remoteIP != null)
                {
                    if (!connected)
                    {
                        Debug.Log("IFMServer: Got connection from IFM compatible app Confirming connection");
                        udpClient.Send(handShake, handShake.Length, remoteIP.Address.ToString(), 49983);
                        connected = true;
                    }

                    string    message = Encoding.ASCII.GetString(data);
                    IFMPacket packet  = IFMPacket.Parse(message);

                    PacketReceivedEvent(packet);
                }
            }
            catch (System.Threading.ThreadAbortException)
            {
                Debug.Log("IFMServer: IMF Receiver shutting down");
                connected = false;
            }catch (SocketException e)
            {
                if (connected)
                {
                    Debug.LogWarning("IFMServer: SocketException occurred: " + e.Message);
                }
                connected = false;
                // Wait 5 seconds before trying again
                Thread.Sleep(retryTimeout);
            }
            catch (Exception e)
            {
                throw new Exception(String.Format("IFMServer:  Can't create server at port {0} - {1}", localPort, e));
            }
        }
示例#4
0
 private IEnumerator ProcessIFMPackets()
 {
     Debug.Log("Monitoring Packet Queue.");
     while (true)
     {
         while (receiver.HasWaitingPackets())
         {
             IFMPacket packet = receiver.GetNextPacket();
             foreach (IFMEventHandler handler in handlers)
             {
                 try
                 {
                     handler.ifmMessageHandler.Invoke(packet);
                 }
                 catch (Exception e) {
                     Debug.LogError("Message Handler not properly set, check IFMManager: " + e.Message);
                 }
             }
         }
         yield return(new WaitForSeconds(0.01f));
     }
 }
示例#5
0
        public static IFMPacket Parse(String payloadString)
        {
            IFMPacket packet = new IFMPacket();


            string[] payload = payloadString.Split('=');

            if (payload.Length != 2)
            {
                throw IMFException("Got Invalid Length of IMFPacket");
            }

            string[] blendshapes = payload[0].Split('|');
            string[] transforms  = payload[1].Split('|');

            foreach (string blendshapeTuples in blendshapes)
            {
                if (blendshapeTuples.Length > 0)
                {
                    string[] tuple = blendshapeTuples.Split('-');
                    if (tuple.Length == 2)
                    {
                        packet.Blendshapes.Add(new BlendshapeData(tuple));
                    }
                    else
                    {
                        throw IMFException("Got Invalid tuple for Blendshapes");
                    }
                }
            }

            foreach (string transformTuples in transforms)
            {
                if (transformTuples.Length > 0)
                {
                    string[] tuple = transformTuples.Split('#');

                    string bone = tuple[0];

                    switch (bone)
                    {
                    case "head":
                        packet.Head.SetWithPayload(tuple[1]);
                        break;

                    case "leftEye":
                        packet.LeftEye.SetWithPayload(tuple[1]);
                        break;

                    case "rightEye":
                        packet.RightEye.SetWithPayload(tuple[1]);
                        break;

                    default:
                        break;
                    }
                }
            }

            return(packet);
        }
示例#6
0
#pragma warning restore IDE0051 // Remove unused private members

        public void DefaultHandler(IFMPacket packet)
        {
            Debug.Log(string.Format("Packet Received {0}", packet.ToString()));
        }