Ejemplo n.º 1
0
    public void OnTrackablesUpdated()
    {
        try
        {
            if (!isFrameFormatSet)
            {
                isFrameFormatSet = CameraDevice.Instance.SetFrameFormat(Image.PIXEL_FORMAT.GRAYSCALE, true);
            }

            cameraFeed = CameraDevice.Instance.GetCameraImage(Image.PIXEL_FORMAT.GRAYSCALE);
            UpdateCamTex(cameraFeed);

            tempText = "";
            tempText = new QRCodeReader().decode(cameraFeed.Pixels, cameraFeed.BufferWidth, cameraFeed.BufferHeight).Text;

            //tempText = new QRCodeReader().decode(vDecodeBytes, UnityCamTex.width, UnityCamTex.height).Text;

        }
        catch(Exception e)
        {
            // Fail to detect QR Code!
            // vDebugText = "Failed: " + e.InnerException.Message ;
        }
        finally
        {
            if (!string.IsNullOrEmpty(tempText))
            {
                //http://www.unet.univie.ac.at/~a0701760/terrorzwerg/TerrorzwergClient.apk?Zwegdata=127.0.0.1:666,ASD-A080a-d080a8d-0ad;0
                if( GameData.instance.ipAdress == ""){
                    qrText = tempText.Split(new string[]{"Zwegdata="}, StringSplitOptions.None)[1];
                    string AddressPart = qrText.Split(';')[0];
                    GameData.instance.ipAdress = AddressPart.Split(':')[0];

                    AddressPart = AddressPart.Split(':')[1];
                    GameData.instance.port = int.Parse(AddressPart.Split(',')[0]);
                    GameData.instance.networkGUID = AddressPart.Split(',')[1];
                    GameData.instance.playerId = int.Parse(qrText.Split(';')[1]);
                    // connect

                    Application.LoadLevel("Client_noMinimap");
                    qrText = null;
                }

                qrText = null;
            }
            else{
                GameData.instance.ipAdress = "";
            }
        }
    }