Exemple #1
0
    public static byte[] CompressScreenshot(byte[] screenshotSerialized)
    {
        using (var memoryStreamInput = new System.IO.MemoryStream(screenshotSerialized))
            using (var memoryStreamOutout = new System.IO.MemoryStream())
            {
                using (var gZipStream = new Unity.IO.Compression.GZipStream(memoryStreamOutout, Unity.IO.Compression.CompressionMode.Compress))
                {
                    CopyTo(memoryStreamInput, gZipStream);
                }

                return(memoryStreamOutout.ToArray());
            }
    }
    void Update()
    {
        if (BodySourceManager == null)
        {
            return;
        }

        _BodyManager = BodySourceManager.GetComponent <BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }

        // 人数分の関節情報を送信
        SimpleBody simpleBody1 = new SimpleBody();              // Position, TrackingState
        SimpleBody simpleBody2 = new SimpleBody();              // Orientation

        byte[] sendData1;
        byte[] sendData2;
        for (int i = 0; i < Number; i++)
        {
            //if (data[i].IsTracked) {
            simpleBody1 = GenerateSimpleBody1(data[i]);
            simpleBody2 = GenerateSimpleBody2(data[i]);

            string serialisedMsg1 = JsonUtility.ToJson(simpleBody1);
            string serialisedMsg2 = JsonUtility.ToJson(simpleBody2);
            Debug.Log(serialisedMsg1 + serialisedMsg2);

            using (var memoryStream = new MemoryStream())
            {
                using (var gzipStream = new Unity.IO.Compression.GZipStream(memoryStream, Unity.IO.Compression.CompressionMode.Compress))
                    using (var writer = new StreamWriter(gzipStream))
                    {
                        writer.Write(serialisedMsg1);
                    }
                sendData1 = memoryStream.ToArray();
            }
            NetworkManager.SendPacketData(sendData1, UnityEngine.Networking.QosType.Unreliable);
            using (var memoryStream = new MemoryStream())
            {
                using (var gzipStream = new Unity.IO.Compression.GZipStream(memoryStream, Unity.IO.Compression.CompressionMode.Compress))
                    using (var writer = new StreamWriter(gzipStream))
                    {
                        writer.Write(serialisedMsg2);
                    }
                sendData2 = memoryStream.ToArray();
            }


            NetworkManager.SendPacketData(sendData2, UnityEngine.Networking.QosType.Unreliable);
            Debug.Log("sender update()");
            //}
        }
    }