其他分享
首页 > 其他分享> > Unity 批量动态添加图片,可后台替换

Unity 批量动态添加图片,可后台替换

作者:互联网

string filePath = Application.streamingAssetsPath + "/"+ str;
        if (Directory.Exists(filePath)) {//判断这个路径是否存在
            DirectoryInfo direction = new DirectoryInfo(filePath);
            floders = direction.GetFiles("*.png", SearchOption.AllDirectories);
        }

        Debug.Log(floders.Length);
  StartCoroutine(GetTexture(true, allPeople));

IEnumerator GetTexture(bool boo,GameObject myOJB) {
        for (int i = 0; i < pathList.Count; i++) {
            UnityWebRequest uwr = UnityWebRequest.Get(pathList[i]);
            DownloadHandlerTexture downloadTexture = new DownloadHandlerTexture(true);
            uwr.downloadHandler = downloadTexture;
            yield return uwr.SendWebRequest();
            if (uwr.isNetworkError || uwr.isHttpError) {
                print(uwr.error);
            } else {
                Texture2D t = downloadTexture.texture;
                myOJB.transform.GetChild(i).GetComponent<Image>().sprite = Sprite.Create(t, new Rect(0, 0, t.width, t.height), Vector2.one);

         
            }
        }
    }

 

标签:批量,filePath,uwr,GetTexture,Unity,downloadTexture,后台,new,DownloadHandlerTexture
来源: https://www.cnblogs.com/zqiang0803/p/16386482.html