/// <summary> /// 设置UITexture. /// </summary> /// <param name="Url"></param> /// <param name="varTexture"></param> /// <returns></returns> public static IEnumerator SetTextureToUrl(string Url, UITexture varTexture, UniGifTexture varTextureRJB) { Helper.Log(" Url = http://q.qlogo.cn/qqapp/1104827980/E866B8F7799C8F036AE3E85584B809A7/100 "); using (WWW www = new WWW(Url)) { //挂起程序段,等资源下载完成后,继续执行下去; yield return(www); if (string.IsNullOrEmpty(www.error)) { if (www.bytes[0] != 'G' || www.bytes[1] != 'I' || www.bytes[2] != 'F') { if (varTexture != null) { varTexture.mainTexture = www.texture; } } else { //if (varTextureRJB != null) //{ // yield return FXQ.FXQMainService.GetSingleton().StartCoroutine(varTextureRJB.SetGifFromUrlCoroutine(Url)); //} } } else { Helper.Log("ZQ www.error = " + www.error); } www.Dispose(); } }
//public static IEnumerator SetTextureToUrl(string url, UITexture varUITexture) //{ // if (string.IsNullOrEmpty(url)) yield break; // if (varUITexture == null) yield break; // WWW www = new WWW(url); // yield return www; // if (string.IsNullOrEmpty(www.error)) // { // string contentType = www.responseHeaders["CONTENT-TYPE"]; // var contents = contentType.Split('/'); // if (contents[0] == "image") // { // if (contents[1].ToLower() == "png" || contents[1].ToLower() == "jpeg") // { // varUITexture.mainTexture = www.textureNonReadable; // } // else // { // //写到文件中 // string fileName = Helper.GenerateId(); // string directory = Application.persistentDataPath + "/Resources/"; // if (!Directory.Exists(directory)) // { // Directory.CreateDirectory(directory); // } // string filePath = directory + fileName + "." + contents[1]; // File.WriteAllBytes(filePath, www.bytes); // //从文件加载 // Texture2D t = Resources.Load<Texture2D>(fileName); // varUITexture.mainTexture = t; // } // } // } // www.Dispose(); //} public static void SetTextureToUrl(Transform varTrans, string varPath1, string varPath2, string Url) { if (varTrans != null) { Transform tempTra1 = varTrans.Find(varPath1); Transform tempTra2 = varTrans.Find(varPath2); if (tempTra1 != null && tempTra2 != null) { UITexture tempTexture1 = tempTra1.GetComponent <UITexture>(); UniGifTexture tempTexture2 = tempTra2.GetComponent <UniGifTexture>(); if (tempTra1 != null && tempTra2 != null) { GameLogic.GameContext.GetInstance().StartCoroutine(SetTextureToUrl(Url, tempTexture1, tempTexture2)); } } } }
void Awake() { uniGifTexture = GetComponent <UniGifTexture> (); fixAspect = GetComponent <FixPlaneAspectRatio> (); }
void Awake () { uniGifTexture = GetComponent<UniGifTexture> (); fixAspect = GetComponent<FixPlaneAspectRatio> (); }