Hello
1- i want my game download a texture and save it in my harddisk
2- then Any time i need that texture , unity load that texture form my harddisk.
i wrote a cod which do the first part(download form net and save in hard disk) but i don't know how to use that fill in the game. please help me.
this flowing cod download texture form url and save it in my harddisk
IEnumerator DownloadPic()
{
UnityWebRequest wwwpic = UnityWebRequestTexture.GetTexture(textureUrl);
yield return wwwpic.Send();
if (wwwpic.isError)
{
print("Error " + wwwpic.error);
}
else
{
DownloadHandlerTexture picHandl = wwwpic.downloadHandler as DownloadHandlerTexture;
string fillName = "image";
string Tpath = Path.Combine(Application.persistentDataPath, "AssetData");
Tpath = Path.Combine(Tpath, fillName + ".unity3d");
Save(picHandl.data, Tpath);
}
}
public void Save(byte[] data,string path)
{
if (!Directory.Exists(Path.GetDirectoryName(path)))
{
Directory.CreateDirectory(Path.GetDirectoryName(path));
}
try
{
File.WriteAllBytes(path, data);
}
catch
{
Debug.LogWarning("Failed To Save Data to: " + path.Replace("/", "\\"));
}
}
}
↧