public IEnumerator LoadIcon(string fileName)
    {
        if (icon != null)
        {
            InitMaterial();
            ResGameObject resObj = new ResGameObject();
            resObj.resType = ResGameObject.TYPE_TEXTURE;
            yield return(StartCoroutine(ResManager.GetInstance().Load("Icon/" + fileName, resObj)));

            icon.material.mainTexture = (Texture2D)resObj.obj;
            icon.MarkAsChanged();
        }
        yield break;
    }
    public IEnumerator LoadPlayerIcon(uint pid, string iconName)
    {
        if (icon != null)
        {
            InitMaterial();
            ResGameObject resObj = new ResGameObject();
            resObj.resType = ResGameObject.TYPE_TEXTURE;
            yield return(StartCoroutine(ResManager.GetInstance().LoadPlayerIcon(pid, "default", resObj)));

            icon.material.mainTexture = (Texture2D)resObj.obj;
            yield return(StartCoroutine(ResManager.GetInstance().LoadPlayerIcon(pid, iconName, resObj)));

            icon.material.mainTexture = (Texture2D)resObj.obj;
            icon.MarkAsChanged();
        }
        yield break;
    }
Example #3
0
    /// <summary>
    /// 创建一个panel.
    /// </summary>
    /// <returns>
    /// The panel.
    /// </returns>
    /// <param name='panelName'>
    /// Panel name.
    /// </param>
    public IEnumerator CreatePanel(string panelName)
    {
        BasePanel panel = null;

        if (panels.TryGetValue(panelName, out panel))
        {
            //			NGUITools.SetActive(panel.gameObject, true);
        }
        else
        {
            ResGameObject obj = new ResGameObject();
            yield return(StartCoroutine(ResManager.GetInstance().Load(Config.PanelPath + panelName, obj)));

            GameObject gameObj = NGUITools.AddChild(baseWindow, obj.obj as GameObject);
            panel = gameObj.GetComponent <BasePanel>();
            yield return(StartCoroutine(panel.Init()));

            panels.Add(panelName, panel);
        }
    }
Example #4
0
//	Texture2D mTexture;
//	public void OnGUI(){
//		if(mTexture != null){
//			GUI.DrawTexture(new Rect(10,10,200,200),mTexture);
//		}
//	}
    public IEnumerator LoadPlayerIcon(uint pid, string iconName, ResGameObject target)
    {
        if (iconName.Equals("default") || iconName.Equals("nan1"))
        {
            yield return(StartCoroutine(Load("Icon/" + iconName, target)));
        }
        else
        {
            string url      = pid + "/" + iconName;
            string localUrl = FileWriteBaseUrl + "/img/" + url + ".png";
            try{
                Texture2D tex    = new Texture2D(1, 1);
                byte[]    rawJPG = File.ReadAllBytes(localUrl);
                tex.LoadImage(rawJPG);

                target.obj      = tex;
                m_IconList[url] = tex;
            }catch (Exception e) {
                Debug.Log(e);
                target.obj = null;
            }
            if (target.obj == null)
            {
                string netUrl = Config.FileServerURL + Config.FileUploadInterface + "" + url;
                WWW    www    = new WWW(netUrl);
                yield return(www);

                if (www.error != null)
                {
                    www = null;
                }
                else
                {
                    Debug.Log("download" + url + " succes!");
                    SavePlayerIcon(pid, iconName, www.bytes);
                    target.obj = www.texture;
                }
            }
        }
    }
Example #5
0
    public IEnumerator Load(string resUrl, ResGameObject target)
    {
//		WWW www = null;
//
//		if (m_Resources.ContainsKey(resUrl))
//        {
//			target.obj = m_Resources[resUrl];
//			yield break;
//        }
//        else
//        {
//			string filePath = FileWriteBaseUrl + resUrl;
        //res in Resources or assetBundle

        //1-------------www load assetBundle
//			if(target.resType == ResGameObject.TYPE_BOUNLD){
//				filePath += ".unity3d";
//			}else if(target.resType == ResGameObject.TYPE_TEXTURE){
//				filePath += ".png";
//			}
//			Debug.Log(filePath);
//
//			www = new WWW(filePath);
//
//			yield return www;
//			if (www == null || www.error != null)
//	        {
//				target.obj = Resources.Load(resUrl);
//			}else{
//				if(target.resType == ResGameObject.TYPE_BOUNLD){
//					AssetBundle bundle = www.assetBundle;
//					String[] name = resUrl.Split('/');
//
//					target.obj = bundle.Load(name[name.Length - 1]);
//				}else if(target.resType == ResGameObject.TYPE_TEXTURE){
//					target.obj = www.texture;
//				}
//			}

        //2-------------resources load res
//			target.obj = Resources.Load(resUrl);

        //3-------------assetBundle from file
        if (!isResourcesPath)
        {
            AssetBundleCreateRequest request = null;
            if (m_Resource_Requests.ContainsKey(resUrl))
            {
                if (m_Resource_Requests[resUrl] != null)
                {
                    while (!m_Resource_Requests[resUrl].isDone)
                    {
                        yield return(null);
                    }
                }
            }
            else
            {
                yield return(StartCoroutine(InitRes(resUrl)));
            }
            request = m_Resource_Requests[resUrl];
            if (request != null)
            {
                AssetBundle bundle = request.assetBundle;

                target.obj = bundle.mainAsset;
            }
            else
            {
                target.obj = null;
            }

            yield break;
        }
        else
        {
            target.obj = Resources.Load(resUrl);
        }
    }
    public IEnumerator LoadXml(string url)
    {
        //		Debug.Log("load xml:" + url);
        //		ResGameObject resObj = new ResGameObject();
        //		yield return StartCoroutine(ResManager.GetInstance().Load(url,resObj));
        ////		resObj.obj = Resources.Load(url);
        //		TextAsset ta = resObj.obj as TextAsset;
        //        xml = new XmlDocument();
        //		System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(ta.bytes);
        //
        ////		byte[] datas = ResManager.LoadXmlData(url);
        ////        XmlDocument xml = new XmlDocument();
        ////		System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(datas);
        //
        //		System.IO.StreamReader streamReader = new System.IO.StreamReader(memoryStream, true);
        //		string str = streamReader.ReadToEnd();
        //		streamReader.Close();
        //		memoryStream.Close();
        //        xml.LoadXml(str);

//        if (Application.isEditor || Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.Android)
//        {
//			Test1.log = "load xml:" + url;
//            Debug.Log("load xml:" + url);
        ResGameObject resObj = new ResGameObject();

        yield return(StartCoroutine(ResManager.GetInstance().Load(url, resObj)));

        if (resObj.obj != null)
        {
            TextAsset ta = resObj.obj as TextAsset;
            xml = new XmlDocument();
            System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(ta.bytes);

            System.IO.StreamReader streamReader = new System.IO.StreamReader(memoryStream, true);
            string str = streamReader.ReadToEnd();
            streamReader.Close();
            memoryStream.Close();
            xml.LoadXml(str);
        }
        else
        {
            Debug.Log("Not Find " + url + "!");
        }
//        }
//        else
//        {
//			Test1.log = "load xml:" + url;
//            Debug.Log("load xml by LoadXmlData:" + url);
//
//            byte[] datas = ResManager.LoadXmlData(url);
//            if (datas != null)
//            {
//                xml = new XmlDocument();
//                System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(datas);
//
//                System.IO.StreamReader streamReader = new System.IO.StreamReader(memoryStream, true);
//                string str = streamReader.ReadToEnd();
//                streamReader.Close();
//                memoryStream.Close();
//                xml.LoadXml(str);
//            }
//            else
//            {
//                Debug.Log("Not Find " + url + "!");
//            }
//        }
        yield break;
    }