示例#1
0
	IEnumerator GetPicture(string id, string url, FileIODelegate ioCallback)
	{
		WWW loader = new WWW(url);

		yield return loader;

#if UNITY_WEBPLAYER
		ioCallback(id, loader.texture);
#else
		string filePath = sourcePath + "/" + id;
		File.WriteAllBytes(filePath, loader.bytes);

		GetTexture(id, url, ioCallback);
#endif
	}
示例#2
0
	public void GetTexture(string id, string url, FileIODelegate ioCallback)
	{
		if (string.IsNullOrEmpty(sourcePath))
		{
			sourcePath = Application.persistentDataPath;
			Debug.Log("persistentDataPath " + sourcePath);
		}

		string filePath = sourcePath + "/" + id;
		if (File.Exists(filePath))
		{
			Debug.Log("Reading file for texture " + filePath);

#if !UNITY_WEBPLAYER	
			var bytes = File.ReadAllBytes(filePath);
			var tex = new Texture2D(1, 1);
			tex.LoadImage(bytes);
			ioCallback(id, tex);
#endif
		}
		else
			DownloadPicture(id, url, ioCallback);
	}
示例#3
0
	void DownloadPicture(string id, string url, FileIODelegate ioCallback)
	{
		this.StartCoroutine(GetPicture(id, url, ioCallback));
	}