Skip to content
Snippets Groups Projects
Commit e02fee32 authored by lacoche's avatar lacoche
Browse files

File download safe multiple download at the same time, prevent images from the...

File download safe multiple download at the same time, prevent images from the same url to be downloaded several times
parent 25a53c50
No related branches found
No related tags found
1 merge request!2WA now supports multiple trackable modules, add module mesh for iOS,...
......@@ -18,13 +18,14 @@ public class WorldAnalysisARFoundationHelper
string fileName = "";
#if UNITY_EDITOR
string folder = Application.streamingAssetsPath;
#else
#else
string folder = Application.persistentDataPath;
#endif
#endif
string uniqueFileName = "/Temp"+ System.Guid.NewGuid()+".data";
using (var client = new WebClient())
{
await client.DownloadFileTaskAsync(toLoad, folder + "/Temp.data");
await client.DownloadFileTaskAsync(toLoad, folder + uniqueFileName);
string header_contentDisposition = client.ResponseHeaders["content-disposition"];
if (header_contentDisposition == null)
{
......@@ -40,7 +41,7 @@ public class WorldAnalysisARFoundationHelper
{
File.Delete(filePath);
}
File.Move(folder + "/Temp.data", filePath);
File.Move(folder + uniqueFileName, filePath);
}
return new KeyValuePair<string, string>(filePath , fileName);
}
......
......@@ -17,7 +17,11 @@ public class WorldAnalysisARFoundationModuleImage : WorldAnalysisARFoundationMod
/// <summary>
/// Name of all images that have been added to the library
/// </summary>
private List<string> m_trackedImageInLibrary;
private List<string> m_trackedImageInLibrary;
/// <summary>
/// All url of images that have allready been downloaded
/// </summary>
private List<string> m_allDownloadedImages;
/// <summary>
/// List of tracked images with tracking infos
/// </summary>
......@@ -35,6 +39,7 @@ public class WorldAnalysisARFoundationModuleImage : WorldAnalysisARFoundationMod
XROrigin origin = UnityEngine.Object.FindAnyObjectByType<XROrigin>();
m_trackedImageManager = origin.gameObject.AddComponent<ARTrackedImageManager>();
m_trackedImageInLibrary = new List<string>();
m_allDownloadedImages = new List<string>();
m_trackedImageManager.trackedImagePrefab = (GameObject)Resources.Load("ARFImageTrackingPrefab");
m_trackedImageManager.trackedImagesChanged += OnTrackedImagesChanged;
}
......@@ -172,8 +177,12 @@ public class WorldAnalysisARFoundationModuleImage : WorldAnalysisARFoundationMod
if (!found)
{
// Here we don't check if url exists and still return true: could be improve
LoadTextureFromURL(url, fileName, imageWidthInMeters);
// Do not download the same image twice
if (!m_allDownloadedImages.Contains(url))
{
// Here we don't check if url exists and still return true: could be improve
LoadTextureFromURL(url, fileName, imageWidthInMeters);
}
}
else
{
......@@ -206,6 +215,7 @@ public class WorldAnalysisARFoundationModuleImage : WorldAnalysisARFoundationMod
public async void LoadTextureFromURL(string url, string fileName, float imageWidthInMeters)
{
Debug.Log("Download image from url "+ url);
m_allDownloadedImages.Add(url);
KeyValuePair<string , string> downloaded = await WorldAnalysisARFoundationHelper.DownloadFileHTTP(url);
LoadTextureFromMemory(downloaded.Key, fileName, imageWidthInMeters);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment