diff --git a/Runtime/Scripts/WorldAnalysisARFoundationHelper.cs b/Runtime/Scripts/WorldAnalysisARFoundationHelper.cs index d1b128c8968c36f07d4fef375c65dfd18aaa0b0c..f3bb1771cf1ad0a059b720e345c1272feca871a6 100644 --- a/Runtime/Scripts/WorldAnalysisARFoundationHelper.cs +++ b/Runtime/Scripts/WorldAnalysisARFoundationHelper.cs @@ -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); } diff --git a/Runtime/Scripts/WorldAnalysisARFoundationModuleImage.cs b/Runtime/Scripts/WorldAnalysisARFoundationModuleImage.cs index 60c1865888da512bdcc7f9a3fc888c9ae90b03b6..bba58d8e8bef7cf3644d12d5b5f66bd0c410674b 100644 --- a/Runtime/Scripts/WorldAnalysisARFoundationModuleImage.cs +++ b/Runtime/Scripts/WorldAnalysisARFoundationModuleImage.cs @@ -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); }