void LoadAsset() { if (!string.IsNullOrEmpty(OBJUrl)) { Destroy(loadedOBJGameObject); asyncOp = Environment.i.platform.webRequest.Get( url: OBJUrl, OnSuccess: (webRequestResult) => { loadedOBJGameObject = OBJLoader.LoadOBJFile(webRequestResult.downloadHandler.text, true); loadedOBJGameObject.name = "LoadedOBJ"; loadedOBJGameObject.transform.SetParent(transform); loadedOBJGameObject.transform.localPosition = Vector3.zero; OnFinishedLoadingAsset?.Invoke(); alreadyLoadedAsset = true; }, OnFail: (webRequestResult) => { Debug.Log("Couldn't get OBJ, error: " + webRequestResult.error + " ... " + OBJUrl); }); } else { Debug.Log("couldn't load OBJ because url is empty"); } if (loadingPlaceholder != null) { loadingPlaceholder.SetActive(false); } }
IEnumerator LoadAssetCoroutine() { if (!string.IsNullOrEmpty(OBJUrl)) { Destroy(loadedOBJGameObject); UnityWebRequest webRequest = UnityWebRequest.Get(OBJUrl); yield return(webRequest.SendWebRequest()); if (webRequest.isNetworkError || webRequest.isHttpError) { Debug.Log("Couldn't get OBJ, error: " + webRequest.error + " ... " + OBJUrl); } else { loadedOBJGameObject = OBJLoader.LoadOBJFile(webRequest.downloadHandler.text, true); loadedOBJGameObject.name = "LoadedOBJ"; loadedOBJGameObject.transform.SetParent(transform); loadedOBJGameObject.transform.localPosition = Vector3.zero; OnFinishedLoadingAsset?.Invoke(); alreadyLoadedAsset = true; } } else { Debug.Log("couldn't load OBJ because url is empty"); } if (loadingPlaceholder != null) { loadingPlaceholder.SetActive(false); } loadingRoutine = null; }