private IEnumerator DownloadAndImportAllInBackground(string url) { string objString = null; string mtlString = null; Hashtable textures = null; GameObject importedObject = null; yield return(StartCoroutine(DownloadFile(url, retval => objString = retval))); yield return(StartCoroutine(DownloadFile(url.Substring(0, url.Length - 4) + ".mtl", retval => mtlString = retval))); if (mtlString != null && mtlString.Length > 0) { string path = url; int lastSlash = path.LastIndexOf('/', path.Length - 1); if (lastSlash >= 0) { path = path.Substring(0, lastSlash + 1); } Hashtable[] mtls = ObjImporter.ImportMaterialSpecs(mtlString); for (int i = 0; i < mtls.Length; i++) { if (mtls[i].ContainsKey("mainTexName")) { Texture2D texture = null; string texUrl = path + mtls[i]["mainTexName"]; yield return(StartCoroutine(DownloadTexture(texUrl, retval => texture = retval))); if (texture != null) { if (textures == null) { textures = new Hashtable(); } textures[mtls[i]["mainTexName"]] = texture; } } } } yield return(StartCoroutine(DownloadFile(url, retval => objString = retval))); if (objString != null && objString.Length > 0) { yield return(StartCoroutine(ObjImporter.ImportInBackground(objString, mtlString, textures, retval => importedObject = retval))); } }
private IEnumerator DownloadAndImportAllInBackground(string url, Action <float> progressCallback, Action <GameObject> result) { string objString = null; string mtlString = null; Hashtable textures = null; GameObject importedObject = null; Texture2D tex = null; progress_bar2.SetActive(true); objekt.transform.position = Vector3.zero; yield return(StartCoroutine(DownloadFile(url, retval => objString = retval))); //yield return StartCoroutine(DownloadFile(url.Substring(0, url.Length - 4) + ".mtl", retval => mtlString = retval)); yield return(StartCoroutine(DownloadFile(url + ".mtl", retval => mtlString = retval))); if (mtlString != null && mtlString.Length > 0) { string path = url; int lastSlash = path.LastIndexOf('/', path.Length - 1); if (lastSlash >= 0) { path = path.Substring(0, lastSlash + 1); } Hashtable[] mtls = ObjImporter.ImportMaterialSpecs(mtlString); for (int i = 0; i < mtls.Length; i++) { if (mtls[i].ContainsKey("mainTexName")) { Texture2D texture = null; string texUrl = path + mtls[i]["mainTexName"]; yield return(StartCoroutine(DownloadTexture(texUrl, retval => texture = retval))); if (texture != null) { if (textures == null) { textures = new Hashtable(); } textures[mtls[i]["mainTexName"]] = texture; tex = texture; } } } } //yield return StartCoroutine(DownloadFile(url, retval => objString = retval)); if (objString != null && objString.Length > 0) { yield return(StartCoroutine(ObjImporter.ImportInBackground(objString, mtlString, textures, r => importedObject = r, progressCallback))); } if (importedObject.transform.childCount == 0) { importedObject.GetComponent <Renderer>().material.shader = Shader.Find("Standard"); importedObject.GetComponent <Renderer>().material.SetTexture("_MainTex", tex); result(importedObject); importedObject.AddComponent <MeshCollider>(); importedObject.transform.localScale = new Vector3(-1, 1, 1); importedObject.transform.parent = objekt; GameObject.Find("Scene").GetComponent <UseShader>().init(); } else { var count = importedObject.transform.childCount; for (int i = 0; i < count; i++) { var obj = importedObject.transform.GetChild(0); obj.GetComponent <Renderer>().material.shader = Shader.Find("Standard"); obj.GetComponent <Renderer>().material.SetTexture("_MainTex", tex); obj.transform.localScale = new Vector3(-1, 1, 1); // Spiegelt das importierte Objekt, geändert obj.gameObject.AddComponent <MeshCollider>(); obj.gameObject.transform.parent = objekt; result(obj.gameObject); GameObject.Find("Scene").GetComponent <UseShader>().init(); } } Debug.Log("Done"); progress_bar.SetActive(false); progress_bar2.SetActive(false); progress_bar.GetComponent <Slider>().value = 0; progress_bar2.GetComponent <Slider>().value = 0; script.resetFront(); script.zentrum(); dist.setSize(); }