using UnityEngine; using UnityEngine.Networking; using System.Collections; using UnityEngine.UI; using System.IO; public class AssetDownloader : MonoBehaviour { //public string url; public Text loadingText; IEnumerator LoadBundle(string textureName) { string catn= ""; print("--------------------------------------------------------------------AD---1-------------------------------------------------" + textureName); if (textureName.Substring(0, 1) == "m") { catn = "Door/"; } if (textureName.Substring(0, 1) == "w") { catn = "Floor/";print("ffffffffffffffffffffffff"); } if (textureName.Substring(0, 1) == "c") { catn = "Ceramic/"; } if (textureName.Substring(0, 1) == "g") { catn = "Granit/"; } UnityWebRequest wr = new UnityWebRequest("http://hb3d.ca/SoftLibrary/" + catn + textureName + ".png"); DownloadHandlerTexture texDl = new DownloadHandlerTexture(true); wr.downloadHandler = texDl; yield return wr.SendWebRequest(); print("--------------------------------------------------------------------AD---2-------------------------------------------------"); if (wr.result == UnityWebRequest.Result.ConnectionError) { print("=========================ERRRRRRRRRRRRRROOOOOOOOOOOORRRRRRRRRRRRRRRRRR=========NET===============================" + "http://hb3d.ca/SoftLibrary/" + catn + textureName + ".png"); } if (wr.result == UnityWebRequest.Result.ConnectionError) { print("=========================ERRRRRRRRRRRRRROOOOOOOOOOOORRRRRRRRRRRRRRRRRR==========HTP==============================" + "http://hb3d.ca/SoftLibrary/" + catn + textureName + ".png"); } if (!(wr.result == UnityWebRequest.Result.ConnectionError)) { print("--------------------------------------------------------------------AD---3------------------------------------------------"); Texture2D t = texDl.texture; if(catn == "Door/") { GameObject.Find(SceneModeManager.SelectedName).transform.Find("door").gameObject.GetComponent().material.mainTexture = t; GameObject.Find(SceneModeManager.SelectedName).transform.Find("door").GetComponent().material.mainTextureScale = new Vector2(1, 1); } if (catn == "Floor/") { GameObject.Find(SceneModeManager.SelectedName).transform.Find("bloc").gameObject.GetComponent().material.mainTexture = t; //GameObject.Find(SceneModeManager.SelectedName).transform.Find("bloc").GetComponent().material.mainTextureScale = new Vector2(1, 1); } //System.IO.File.WriteAllBytes("Resources/loaded", t); } yield break; } public void Load(string textureName) { loadingText.text = "Loading..."+ textureName; print("--------------------------------------------------------------------AD----------------------------------------------------"); // if(textureName) StartCoroutine(LoadBundle(textureName)); } }