unity 把本地图片批量添加到 物体的脚本上 Texture 类型

 private void Awake() {
        string filePath = System.Environment.CurrentDirectory + "/专利/";
        if(Directory.Exists(filePath)) {//判断这个路径是否存在
            DirectoryInfo direction = new DirectoryInfo(filePath);
            floders = direction.GetFiles("*",SearchOption.AllDirectories);
        }

        for(int i = 0;i < floders.Length;i++) {
            pathList.Add(floders[i].ToString());
        }
        StartCoroutine(DownloadTexture(filePath));
    }
   
    IEnumerator DownloadTexture(string url) {
        for(int i = 0;i < pathList.Count;i++) {
            url = pathList[i];
            WWW www = new WWW(url);
            yield return www;
            if(www.isDone) {
                texture = www.texture;
                photoTextures.Add(texture);
            }
        }
    }

 

posted on 2023-04-28 16:54  zqiang0803  阅读(69)  评论(0编辑  收藏  举报

导航