纳金网
标题:
关于Unity3D 读取Android平台的配置文件和纹理
[打印本页]
作者:
may
时间:
2019-7-31 23:10
标题:
关于Unity3D 读取Android平台的配置文件和纹理
来自:实践者
#region
/// <summary>
/// 读取txt配置文件
/// </summary>
/// <param name="TXT_Path"></param>
private void WriteConfigToDic(string strFileName)
{
string strContent = System.IO.File.ReadAllText( "/storage/emulated/0/config/"+ strFileName);
Debug.Log("读取配置文件结束");
}
/// <summary>
/// 读取纹理
/// </summary>
private void ReadTextureToMaterial(string strTextureName)
{
double startTime = (double)Time.time;
//创建文件读取流
Debug.Log(strTexturePath + strTextureName);
FileStream fileStream = new FileStream( "/storage/emulated/0/config/"+ strTextureName, FileMode.Open, FileAccess.Read);
fileStream.Seek(0, SeekOrigin.Begin);
//创建文件长度缓冲区
byte[] bytes = new byte[fileStream.Length];
//读取文件
fileStream.Read(bytes, 0, (int)fileStream.Length);
//释放文件读取流
fileStream.Close();
fileStream.Dispose();
fileStream = null;
//创建Texture
int width = 2048;
int height = 1024;
Texture2D texture = new Texture2D(width, height);
texture.LoadImage(bytes);
//textureState = texture;
startTime = (double)Time.time - startTime;
Debug.Log("读取IO纹理加载用时:" + startTime);
}
#endregion
}
复制代码
欢迎光临 纳金网 (http://go.narkii.com/club/)
Powered by Discuz! X2.5