Unity 将网址转成二维码(草料二维码api)

https://cli.im/api

 

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class WwwLoad : MonoBehaviour {
     RawImage image;
    string result;
    // Use this for initialization
    void Start () {
        image = GameObject.Find("RawImage").transform.GetComponent<RawImage>();
       StartCoroutine(LoadWWW());
       // result = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1532085463294&di=1a07de5d3f8486755097832543ee032e&imgtype=0&src=http%3A%2F%2Ff.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2F960a304e251f95cacc952852c5177f3e660952f5.jpg";
    }

    private IEnumerator LoadWWW()
    {
        WWW w = new WWW("https://cli.im/api/qrcode/code?text=http://www.egpchina.com/&mhid=1");

        yield return w;

        print(w.text);

        //获取'src=" //' 后所有的数据
        string s = w.text.Substring(w.text.IndexOf("<img src=") + 12, w.text.Length - (w.text.IndexOf("<img src=") + 12));

        //截取src="" 内部的链接地址,不包括'//'
        result = s.Substring(0, s.IndexOf("\""));

        print("-->"+result+"----<");
        StartCoroutine(downLoad(result));

    }

    private IEnumerator downLoad(string s)
    {
        WWW www = new WWW(s);
        yield return www;
        if (www.isDone && www.error == null)
        {
            print(www);
            Texture2D tt = www.texture;
            image.texture = tt;
        }
        else
        {
            print("buyaojinlai gouride ");
        }
        //  image.texture = www.texture;
    }
    float i = 0;
    // Update is called once per frame
    void Update () {
        //i += Time.deltaTime;
        //if (i > 3f)
        //{
           
        //}
    }
}
 

相关推荐
©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页