Exemplo n.º 1
0
    public Loads Load(string url, Action <object> fun, Action <object> error = null, GLoader loader = null)
    {
        Loads lw = null;

        if (url == "" || url == null)
        {
            return(lw);
        }
        if (loader != null && loader.image.isDisposed)
        {
            return(lw);
        }
        if (source.ContainsKey(url) && loader == null)
        {
            if (fun != null)
            {
                if (url.LastIndexOf(".png") > -1 || url.LastIndexOf(".jpg") > -1 || url.LastIndexOf(".jpeg") > -1 || loader != null)
                {
                    fun((Dictionary <string, object>)sourceDic [url]);
                }
                else
                {
                    fun(source [url]);
                }
            }
            return(lw);
        }
        lw = Loads.Get();
        lw.LoadUrl(url, (object w) =>
        {
            Loads loadW;
            //Log.debug ("Load Complete - " + url);
            loadW      = w as Loads;
            bool isDis = false;
            if (loadW.url.LastIndexOf(".png") > -1 || loadW.url.LastIndexOf(".jpg") > -1 || loadW.url.LastIndexOf(".jpeg") > -1 || loadW.loader != null)
            {
                Texture2D t  = loadW.www.texture;
                source [url] = t;
                isDis        = loadW.www == null ? true : false;

                if (fun != null && !isDis)
                {
                    if (loadW.loader != null)
                    {
                        Dictionary <string, object> wwdic = new Dictionary <string, object>();
                        wwdic.Add("url", loadW.url);
                        wwdic.Add("loader", loadW.loader);
                        wwdic.Add("texture", t.EncodeToJPG());
//							if(loadW.loader!=null){
//								loadW.loader.texture = new NTexture(PhoneManager.inst.Base64ToTexter2d((string)wwdic["texture"], 100, 100));
//							}
                        sourceDic[url] = wwdic;
                        fun(wwdic);
                    }
                    else
                    {
                        fun(source [url]);
                    }
                }
                loadW.Clear();
            }
            else
            {
                loadW = w as Loads;
                isDis = loadW.www == null ? true : false;
                if (fun != null && !isDis)
                {
                    fun(loadW.www);
                }
                loadW.Clear();
            }
        }, (object xx) =>
        {
            if (error != null)
            {
                error(null);
            }
        }, loader);
        return(lw);
    }