void Start()
    {
        if (manager == null)
        {
            manager = KinectManager.Instance;
        }

        if (manager && manager.IsInitialized())
        {
            if (sensorTransform != null)
            {
                manager.SetKinectToWorldMatrix(sensorTransform.position, sensorTransform.rotation, Vector3.one);
            }

            if (backgroundImage)
            {
                Vector3 localScale = backgroundImage.transform.localScale;
                localScale.x = (float)manager.GetDepthImageWidth() * (float)Screen.height / ((float)manager.GetDepthImageHeight() * (float)Screen.width);
                localScale.y = -1f;

                backgroundImage.transform.localScale = localScale;
                backgroundImage.color = Color.white;
            }
        }

        // create lz4 compressor & decompressor
        compressor   = LZ4Sharp.LZ4CompressorFactory.CreateNew();
        decompressor = LZ4Sharp.LZ4DecompressorFactory.CreateNew();
    }
Exemple #2
0
        /// <summary>
        /// 进行多包的解析
        /// </summary>
        /// <param name="body"></param>
        /// <param name="compress"></param>
        /// <param name="len"></param>
        protected void ParseMutiPack(byte[] body, bool compress, int len)
        {
            // 多包整体解密
            if (mEncrypt != null)
            {
                mEncrypt.RecvDecode(body, len);
            }

            int decompress_size = 0;// 解压后的数据大小

            byte[] decompress_date = null;
            if (compress)
            {
                if (mDecompress == null)
                {
                    mDecompress = LZ4Sharp.LZ4DecompressorFactory.CreateNew();
                }

                decompress_size = mDecompress.Decompress(body, 0, mDecompressBuffer, 0, len);
                decompress_date = mDecompressBuffer;
            }
            else
            {
                decompress_size = len;
                decompress_date = body;
            }

            int remain_buf = decompress_size;
            int cur_idx    = 0;

            while (cur_idx < remain_buf)
            {
                ushort sinle_pack_len = Utils.BitConverter.ToUInt16(decompress_date, cur_idx);
                OnDataReply(decompress_date, cur_idx + sizeof(ushort), sinle_pack_len);

                cur_idx += (sinle_pack_len + sizeof(ushort));
            }
        }
Exemple #3
0
    void Start()
    {
        // get references to the needed components
        manager        = KinectManager.Instance;
        gestureManager = VisualGestureManager.Instance;
        speechManager  = SpeechManager.Instance;

        // create lz4 compressor & decompressor
        decompressor = LZ4Sharp.LZ4DecompressorFactory.CreateNew();
        compressor   = LZ4Sharp.LZ4CompressorFactory.CreateNew();

        try
        {
            if (serverHost != string.Empty && serverHost != "0.0.0.0" && serverPort != 0)
            {
                byte error = 0;
                clientConnId = NetworkTransport.Connect(clientHostId, serverHost, serverPort, 0, out error);

                if (error == (byte)NetworkError.Ok)
                {
                    Debug.Log("Connecting to the server - " + serverHost + ":" + serverPort);

                    if (statusText)
                    {
                        statusText.text = "Connecting to the server...";
                    }
                }
                else
                {
                    throw new UnityException("Error while connecting: " + (NetworkError)error);
                }
            }
            else if (broadcastPort > 0)
            {
                Debug.Log("Waiting for the server...");

                if (statusText)
                {
                    statusText.text = "Waiting for the server...";
                }
            }
            else
            {
                Debug.Log("Server settings are not set. Cannot connect.");

                if (statusText)
                {
                    statusText.text = "Server settings are not set. Cannot connect.";
                }
            }
        }
        catch (System.Exception ex)
        {
            Debug.LogError(ex.Message + "\n" + ex.StackTrace);

            if (statusText)
            {
                statusText.text = ex.Message;
            }
        }
    }