/// <summary> /// this will download image from server and add to our dynamic image libraty using addimageJob ienum /// </summary> /// <param name="imageUrl"></param> /// <returns></returns> IEnumerator DownloadImageFromServer(string imageUrl, ImageTargetVideoUrlTemplate t) { // loadingGameObj.SetActive(true); downloadUrls.Add(imageUrl); Debug.Log("what the hell"); Debug.Log("image url " + imageUrl); UnityWebRequest webRequest = UnityWebRequestTexture.GetTexture(imageUrl); yield return(webRequest.SendWebRequest()); Debug.Log("what the hell1"); if (webRequest.isNetworkError || webRequest.isHttpError) { Debug.Log("network error"); // networkPanel.SetActive(true); webRequest.Dispose(); } else { currentDownloadedTexture = null; Resources.UnloadUnusedAssets(); GC.Collect(); currentDownloadedTexture = DownloadHandlerTexture.GetContent(webRequest); // networkPanel.SetActive(false); webRequest.Dispose(); StartCoroutine(AddImageJob(t)); } webRequest = null; //UnityEngine.SceneManagement.SceneManager }
public void OnReferenceImageAdded(XRReferenceImage img, ImageTargetVideoUrlTemplate template) { Debug.Log("on reference image " + template.targetVideoUrl); var instantiatedGameObject = Instantiate(videoPrefab); instantiatedGameObject.name = img.name; //todo videoPrefabList.Add(instantiatedGameObject); //instantiatedGameObject.GetComponentInChildren<ARFoundationVIdeoPlayer>().url = template.targetVideoUrl; //todo bharath uncomment the following all lines var t = instantiatedGameObject.GetComponentInChildren <ARFoundationYoutubePlayer>(); t.VideoURL = template.targetVideoUrl; t.description = template.adsInfo; t.buttonName = template.adsButtonName; t.redirectUrl = template.adsRedirectUrl; //t.Init(); //we already added t to the list so initialiatize all includes t InitializeAllVideoPrefabs(); //refImgNameWithObj.Add(instantiatedGameObject, img.name); //Debug.Log("dictionary count" + refImgNameWithObj.Count); }
/// <summary> /// this addes images target runtime to the xrreference library through unity job system /// </summary> /// <param name="texture2D"></param> /// <returns></returns> public IEnumerator AddImageJob(ImageTargetVideoUrlTemplate t) { yield return(null); print("Adding image\n"); print("Job Starting..."); var firstGuid = new SerializableGuid(0, 0); var secondGuid = new SerializableGuid(0, 0); // XRReferenceImage newImage = new XRReferenceImage(firstGuid, secondGuid, new Vector2(0.1f, 0.1f), Guid.NewGuid().ToString(), texture2D); addedImageCount++; XRReferenceImage newImage = new XRReferenceImage(firstGuid, secondGuid, new Vector2(0.1f, 0.1f), addedImageCount.ToString(), currentDownloadedTexture); try { loadingGameObj.SetActive(true); Debug.Log("new image naame" + newImage.ToString()); MutableRuntimeReferenceImageLibrary mutableRuntimeReferenceImageLibrary = trackImageManager.referenceLibrary as MutableRuntimeReferenceImageLibrary; var jobHandle = mutableRuntimeReferenceImageLibrary.ScheduleAddImageJob(currentDownloadedTexture, addedImageCount.ToString(), 0.1f); while (!jobHandle.IsCompleted) { print("Job Running..."); } loadingGameObj.SetActive(false); Debug.Log("job finsihed added to dictionary"); // referenceImageAddedEvent?.Invoke(newImage,t); GetComponent <DynamicImgVideoSpawner>().OnReferenceImageAdded(newImage, t); currentDownloadedTexture = null; Resources.UnloadUnusedAssets(); GC.Collect(); //image downloaded and added to library // imageTargetUrlGetter.OnUnityEntered(); print("image downloaded and added to library"); print("image count" + mutableRuntimeReferenceImageLibrary.count); //print("name da mame " + newImage.name); } catch (Exception e) { print(e.ToString()); } }
public void DownloadImageFromServerFunc(ImageTargetVideoUrlTemplate t) { // StartCoroutine(DownloadImageFromServer(t.targetImageUrl, t)); if (!downloadUrls.Contains(t.targetImageUrl)) { Debug.Log("download initiated"); StartCoroutine(DownloadImageFromServer(t.targetImageUrl, t)); } else { Debug.Log("Already "); Debug.Log(GameObject.FindObjectOfType <DynamicImgVideoSpawner>() + "val"); GameObject.FindObjectOfType <DynamicImgVideoSpawner>().InitializeAllVideoPrefabs(); Debug.Log("Already downloaded"); } }
/// <summary> /// this function will be call once imageurlgetter got video and image url from server /// </summary> /// <param name="t"></param> public void OnUrlRetrieved(ImageTargetVideoUrlTemplate t) { Debug.Log("url " + t.targetImageUrl); currentTemplate = t; StartCoroutine(DownloadImageFromServer(t.targetImageUrl, t)); }