查看: 716|回复: 0
打印 上一主题 下一主题

[其他] 关于Unity3D 读取Android平台的配置文件和纹理

[复制链接]
may    

8830

主题

81

听众

7万

积分

首席设计师

Rank: 8Rank: 8

纳金币
52368
精华
343

最佳新人 热心会员 灌水之王 活跃会员 突出贡献 荣誉管理 论坛元老

跳转到指定楼层
楼主
发表于 2019-7-31 23:10:46 |只看该作者 |倒序浏览

来自:实践者
  1. #region   
  2. /// <summary>
  3.     /// 读取txt配置文件
  4.     /// </summary>
  5.     /// <param name="TXT_Path"></param>
  6.     private void WriteConfigToDic(string strFileName)
  7.     {
  8.         string strContent = System.IO.File.ReadAllText( "/storage/emulated/0/config/"+ strFileName);
  9.         Debug.Log("读取配置文件结束");
  10.     }

  11.     /// <summary>
  12.     /// 读取纹理
  13.     /// </summary>
  14.     private void ReadTextureToMaterial(string strTextureName)
  15.     {
  16.         double startTime = (double)Time.time;
  17.         //创建文件读取流
  18.         Debug.Log(strTexturePath + strTextureName);
  19.         FileStream fileStream = new FileStream( "/storage/emulated/0/config/"+ strTextureName, FileMode.Open, FileAccess.Read);
  20.         fileStream.Seek(0, SeekOrigin.Begin);
  21.         //创建文件长度缓冲区
  22.         byte[] bytes = new byte[fileStream.Length];
  23.         //读取文件
  24.         fileStream.Read(bytes, 0, (int)fileStream.Length);
  25.         //释放文件读取流
  26.         fileStream.Close();
  27.         fileStream.Dispose();
  28.         fileStream = null;

  29.         //创建Texture
  30.         int width = 2048;
  31.         int height = 1024;
  32.         Texture2D texture = new Texture2D(width, height);
  33.         texture.LoadImage(bytes);
  34.         //textureState = texture;

  35.         startTime = (double)Time.time - startTime;
  36.         Debug.Log("读取IO纹理加载用时:" + startTime);
  37.     }
  38.     #endregion
  39. }
复制代码
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2025-7-1 08:14 , Processed in 0.068400 second(s), 28 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部