Esempio n. 1
0
        public void Load(string id, AsyncLoaderCallback <Texture> callback)
        {
            Texture cashedTexture = _cache ? ImageCache.Get(id) : null;

            if (null != cashedTexture)
            {
                callback(cashedTexture);
            }
            else
            {
                Connector.Send(
                    new WebRequest(id),
                    new Responder(
                        delegate(object data)
                {
                    WWW www = (WWW)data;

                    var texture = new Texture2D(200, 150);
                    www.LoadImageIntoTexture(texture);
                    if (_cache)
                    {
                        ImageCache.Put(id, texture);
                    }
                    callback(texture);
                },
                        delegate(object data)
                {
                    Logger.Log("Image loading failed: " + id);
                    throw new Exception("Loading error:\n\n" + data);
                }
                        )
                    );
            }
        }
Esempio n. 2
0
        private void Search()
        {
            if (_newSearch)
            {
                _newSearch = false;
            }

            string url = string.Format(
                FlickrSearchUrl, FlickrAppKey,
                _txtSearch.Text.Replace(" ", "+"),
                _random.Next(1, 20), /*1*/ // just a random page
                20
                );

            // make a Flickr request
            GlobalLoadingMask.Show("Searching...");
            var cursor = CursorManager.Instance.SetCursor(CursorType.Wait);

            _httpConnector.Send(
                url,
                delegate(object data)
            {
                GlobalLoadingMask.Hide();
                CursorManager.Instance.RemoveCursor(cursor);
                _scroller.Visible = true;
                _list.SetFocus();
                DisplayData(data);
            }
                );
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes download
        /// </summary>
        /// <param name="path">The path to load from</param>
        /// <param name="callback">Fires when resource is loaded</param>
        /// <returns></returns>
        public AsyncToken Load(string path, ResultHandler callback)
        {
            //Debug.Log(string.Format(@"*** Loading texture ""{0}""", textureName));

            AsyncToken httpToken;

            if (_finished.ContainsKey(path)) // texture already loaded
            {
                /**
                 * Return null to signalize there's nothing for async loading
                 * */
                return(null);
            }

            /**
             * The texture not yet loaded, but loading
             * We need to return token (for displaying progress)
             * */
            if (_active.ContainsKey(path))
            {
                /**
                 * The token collection for this texture already exists
                 * We should grab the first token and clone it
                 * */
                httpToken = _active[path];
            }
            else
            {
                //Debug.Log("*** Downloading texture: " + texturePath);
                httpToken      = _connector.Send("~" + path, LoadCompleteHandler);
                httpToken.Data = path;

                _active.Add(path, httpToken);

                _tokenToTokens.Add(httpToken, new List <AsyncToken>());
            }

            AsyncToken token = (AsyncToken)httpToken.Clone();

            _tokenToTokens[httpToken].Add(token);

            _callbacks.Add(token, callback);

            return(token);
        }
Esempio n. 4
0
        private void StartLoading()
        {
            Configuration.Instance.Deserilized = false;
            //Configuration.Instance.Initialized = false;

#if DEBUG
            if (DebugMode)
            {
                Debug.Log("ConfigLoader: loading configuration.");
            }
#endif
            if (AsyncMode)
            {
                var url = UnityEngine.Application.isEditor ? EditorConfigUrl : ConfigUrl;

#if DEBUG
                if (DebugMode)
                {
                    Debug.Log(string.Format("ConfigLoader: loading in Async mode [{0}]", url));
                }
#endif
                _connector = new HttpConnector
                {
                    Url          = url,
                    CacheBuster  = CacheBuster,
                    FaultHandler = OnAsyncFault,
                    ResponseMode = ResponseMode.WWW,
                    Timeout      = 30,
                    //LogCalls = true
                };
                _connector.Send(new Responder(OnAsyncResult));
            }
            else
            {
#if DEBUG
                if (DebugMode)
                {
                    Debug.Log(string.Format("ConfigLoader: loading from Resources [{0}]", ConfigPath));
                }
#endif

                _config = Resources.Load(ConfigPath);

                if (null == _config)
                {
                    string msg = string.Format(ConfigurationException.LoadingError);
#if DEBUG
                    if (DebugMode)
                    {
                        Debug.Log(msg);
                    }
#endif
                    //Alert.Show(msg, "Configuration error");
                    if (null != ResultHandler)
                    {
                        ResultHandler(msg);
                    }
                }
                else
                {
                    Configuration.Instance.ProcessConfig(_config.ToString());
                    if (null != ResultHandler)
                    {
                        ResultHandler(Configuration.Instance.Application);
                    }
                }
            }
        }