Пример #1
0
    // サーバのQRコード表示
    private IEnumerator ShowQRImage()
    {
        var net = NetworkSender.Instance;

        while (!net.IsBegin)
        {
            yield return(null);
        }

        var qrText  = $"{net.IP.ToString()}:{net.Port}";
        var texture = QRCodeHelper.CreateQRCode(qrText, 256, 256);

        _image.sprite = Sprite.Create(texture,
                                      new Rect(0.0f, 0.0f, texture.width, texture.height),
                                      new Vector2(0.5f, 0.5f));
    }
Пример #2
0
    void OnGUI()
    {
        string savePath = Application.dataPath + "/qr.png";

        _content = GUILayout.TextArea(_content, GUILayout.Height(30f));
        _size    = (QRImageSize)EditorGUILayout.EnumPopup(_size);
        EditorGUI.BeginDisabledGroup(string.IsNullOrEmpty(_content));
        if (GUILayout.Button("Save"))
        {
            int size = (int)Mathf.Pow(2f, (int)_size);
            var tex  = QRCodeHelper.CreateQRCode(_content, size, size);
            using (var fs = new FileStream(savePath, FileMode.OpenOrCreate))
            {
                var b = tex.EncodeToPNG();
                fs.Write(b, 0, b.Length);
            }
            AssetDatabase.Refresh();
        }
        EditorGUI.EndDisabledGroup();
    }
Пример #3
0
    void QrDisplay(string text)
    {
        Popup  popup    = GetComponent <Popup>();
        int    size     = 256;
        string savePath = Application.dataPath + "QRCode.png";

        var tex      = QRCodeHelper.CreateQRCode(text, size, size);
        var _picture = Sprite.Create(tex, new Rect(0, 0, size, size), Vector2.zero);

        /*
         * using (var fs = new FileStream(savePath, FileMode.OpenOrCreate))
         *  {
         *      //var _picture = tex.EncodeToPNG();
         *      fs.Write(_picture, 0, _picture.Length);
         *  }
         */
        var image = GetComponent <Image>();

        image.sprite = _picture;
    }