使用WWW方式读取StreamingAsset目录的图片
来源:互联网 发布:荆门网络作文大赛 编辑:程序博客网 时间:2024/06/05 06:59
using System.Collections;using System.Collections.Generic;using System.IO;using UnityEngine;using UnityEngine.UI;public class UI_Main : MonoBehaviour { private Hashtable ht = new Hashtable(); private Dictionary<string, Texture2D> dic = new Dictionary<string, Texture2D>();public GameObject Finish = null;void Start () {LoadPictures();Finish.GetComponent<Image>().sprite = Sprite.Create(dic[""], new Rect(0, 0, dic[""].width, dic[""].height), new Vector2(0.5f, 0.5f));} void LoadPictures() { StartCoroutine(LoadImages()); } IEnumerator LoadImages() { string streamingPath = Application.streamingAssetsPath; DirectoryInfo dir = new DirectoryInfo(streamingPath); GetAllFiles(dir); foreach (DictionaryEntry dic in ht) { WWW www = new WWW("file://" + streamingPath + dic.Key); yield return www; if (www != null && string.IsNullOrEmpty(www.error)) { ww.Add(dic.Key.ToString().Substring(1, dic.Key.ToString().Length - 5), www.texture); } if (www.isDone) { www.Dispose(); } } } public void GetAllFiles(DirectoryInfo dir) { FileSystemInfo[] fil = dir.GetFileSystemInfos(); foreach (FileSystemInfo i in fil) { if (i is DirectoryInfo) { GetAllFiles((DirectoryInfo)i); } else { string str = i.FullName; string path = Application.streamingAssetsPath; string strType = str.Substring(path.Length); if (strType.Substring(strType.Length - 3).ToLower() == "jpg") { if (ht.Contains(strType)) { ht[strType] = strType; } else { strType = strType.Replace("\\", "/"); ht.Add(strType, strType); } } } } }}
阅读全文
0 0
- 使用WWW方式读取StreamingAsset目录的图片
- 关于Android/IOS里边读取StreamingAsset目录 文件流
- WWW读取不同位置图片的区别
- 正确使用adb读取data目录下的文件方式
- unity 中使用 WWW 类读取 StreamingAssets 目录的路径问题
- python读取图片的方式
- 读取assets目录下的图片
- 读取assets目录下面的图片
- C++ 读取目录下的所有图片
- Unity中文件流和WWW的方式加载图片
- Java读取图片的三种方式
- jsp 通过流的方式读取图片
- www读取本地图片做微缩图
- 流的方式读取本地图片和网络图片
- android 存储图片到data目录和读取data目录下的图片
- android 存储图片到data目录和读取data目录下的图片
- tips:matlab读取一个目录下的所有图片
- matlab读取一个目录下的所有图片
- 什么是类
- windows10—Tensorboard命令行命令没有反应
- bzoj3171 [Tjoi2013]循环格
- 算法导论学习1--排序
- sc.next() 和 sc.nextLine 的区别
- 使用WWW方式读取StreamingAsset目录的图片
- 秦九昭算法
- 洛谷 P1969 [NOIP2013]积木大赛
- ASP.NET Core的身份认证框架IdentityServer4(3)-术语的解释
- 抽象类
- C#遍历类的所有属性
- c盘如何拓展内存
- Android 6.0 运行时权限管理最佳实践
- 技能冷却效果