Two small functions
From the server to download resources and resources to the local area ~
The following code
/// <summary>
/// Download and save resources to the local area
/// </summary>
/// <param name = "url"> </param>
/// <param name = "name"> </param>
/// <return> </retarns>
Public Static Ienmerator DownloadsAve (String URL, String name, Action <Bool, String> Finish = NULL)
{{
url = Uri.escapeuristring (url);
string loading = string.empty;
BOOL B = FALSE;
Www www = new www (url);
if (www.error! = Null)
{{
Print ("error:" + www.error);
}
While (! www.isdone)
{{
Loading = ((int) ((int) (www.progress * 100)) % 100) + " %";
If (Finish! = NULL)
{{
Finish (b, loading);
}
yield Return 1;
}
if (www.isdone)
{{
Loading = "100%";
byte [] bytes = www.bytes;
B = SaveasSETS (Application.PersistentDataPath, name, bytes);
If (Finish! = NULL)
{{
Finish (b, loading);
}
}
}
/// <summary>
/// Save resources to the local area
/// </summary>
/// <param name = "PATH"> </Param>
/// <param name = "name"> </param>
/// <param name = "info"> </param>
/// <param name = "length"> </param>
Public Static Bool Saveassets (String Path, String name, byte [] bytes)
{{
Stream SW;
Fileinfo t = new fileinfo (path + "//" + name);
if (! T.Exists)
{{
try
{{
sw = t.create ();
sw.write (bytes, 0, bytes.length);
sw.close ();
sw.dispose ();
Return true;
}
catch
{{
Return false;
}
}
else
{{
Return true;
}
}