Beispiel #1
0
        public bool Load(LoaderRequest request, System.Action <LoaderResponse> callback = null, object extraData = null)
        {
            if (request == null || request.urlList == null || request.urlList.Length == 0)
            {
                return(false);
            }

            Stop();

            response              = new LoaderResponse();
            responseIndex         = 0;
            response.responseList = new LoaderResponse[request.urlList.Length];

            int requestCount = request.urlList.Length;

            for (int i = 0; i < requestCount; ++i)
            {
                ExtraData data = new ExtraData();
                data.callback  = callback;
                data.extraData = extraData;
                loader.Load(new LoaderRequest(request.urlList[i], request.typeList[i]), CompleteCallback, data);
            }

            return(true);
        }
Beispiel #2
0
        public bool Load(LoaderRequest request, System.Action <LoaderResponse> callback = null, object extraData = null)
        {
            if (request == null || string.IsNullOrEmpty(request.url))
            {
                return(false);
            }
            else
            {
                LoaderResponse response = null;
                if (cacheMap.TryGetValue(request.url, out response))
                {
                    Debug.Log("CacheLoader complete:" + request.url);

                    if (callback != null)
                    {
                        response.extraData = extraData;
                        callback(response);
                    }
                    return(true);
                }
                else
                {
                    if (loader.Load(request, LoaderCallback, extraData))
                    {
                        this.callback = callback;
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
        }
Beispiel #3
0
        private void LoaderCallback(LoaderResponse response)
        {
            if (response.isSuccessful)
            {
                cacheMap.Add(response.request.url, response);
            }

            if (callback != null)
            {
                callback(response);
            }
        }
Beispiel #4
0
        private void LoaderCallback(LoaderResponse response)
        {
            ItemOfQueue item = (ItemOfQueue)response.extraData;

            if (item.callback != null)
            {
                response.extraData = item.extraData;
                item.callback(response);
            }

            working = false;
            requestList.RemoveFirst();
            LoadDo();
        }
Beispiel #5
0
 private static void DestroyCacheResponse(LoaderResponse response)
 {
     response.texture2D = null;
     if (response.assetBundle != null)
     {
         response.assetBundle.Unload(false);
     }
     if (response.responseList != null)
     {
         foreach (LoaderResponse subResponse in response.responseList)
         {
             DestroyCacheResponse(subResponse);
         }
         response.responseList = null;
     }
 }
Beispiel #6
0
 private static void DestroyCacheResponse(LoaderResponse response)
 {
     response.texture2D = null;
     if (response.assetBundle != null)
     {
         response.assetBundle.Unload(false);
     }
     if (response.responseList != null)
     {
         foreach (LoaderResponse subResponse in response.responseList)
         {
             DestroyCacheResponse(subResponse);
         }
         response.responseList = null;
     }
 }
Beispiel #7
0
        private void CompleteCallback(LoaderResponse response)
        {
            ExtraData data = (ExtraData)response.extraData;

            response.extraData = data.extraData;
            this.response.responseList[responseIndex++] = response;
            if (data.callback != null)
            {
                // Item Complete
                data.callback(response);

                // All Complete
                if (this.response.IsResponseListComplete())
                {
                    this.response.isSuccessful = true;
                    data.callback(this.response);
                }
            }
        }
Beispiel #8
0
        private static IEnumerator LoaderGlobalCoroutine()
        {
            while (true)
            {
                if (loaderList.Count > 0)
                {
                    foreach (Loader loader in loaderList)
                    {
                        if (loader.www.isDone)
                        {
                            loaderList.Remove(loader);

                            if (string.IsNullOrEmpty(loader.www.error))
                            {
                                Debug.Log("Loader complete:" + loader.request.url);

                                if (loader.callback != null)
                                {
                                    LoaderResponse response = new LoaderResponse();
                                    response.isSuccessful = true;
                                    response.request      = loader.request;
                                    response.extraData    = loader.extraData;

                                    LoaderType type = loader.request.type;
                                    if (type == LoaderType.Text)
                                    {
                                        response.text = loader.www.text;
                                    }
                                    else if (type == LoaderType.Byte)
                                    {
                                        response.bytes = loader.www.bytes;
                                    }
                                    else if (type == LoaderType.Texture)
                                    {
                                        response.texture2D = loader.www.texture;
                                    }
                                    else if (type == LoaderType.AssetBundle)
                                    {
                                        response.assetBundle = loader.www.assetBundle;
                                        garbageList.Add(response.assetBundle);
                                    }
                                    else
                                    {
                                        // Do nothing
                                    }

                                    loader.callback(response);
                                }
                            }
                            else
                            {
                                Debug.LogError("Loader error:" + loader.www.error);

                                if (loader.callback != null)
                                {
                                    LoaderResponse response = new LoaderResponse();
                                    response.isSuccessful = false;
                                    response.error        = loader.www.error;
                                    response.request      = loader.request;
                                    response.extraData    = loader.extraData;

                                    loader.callback(response);
                                }
                            }
                            break;
                        }
                    }
                }

                yield return(null);
            }
        }
Beispiel #9
0
        private void LoaderCallback(LoaderResponse response)
        {
            if (response.isSuccessful)
            {
                cacheMap.Add(response.request.url, response);
            }

            if (callback != null)
            {
                callback(response);
            }
        }
Beispiel #10
0
        private static IEnumerator LoaderGlobalCoroutine()
        {
            while (true)
            {
                if(loaderList.Count > 0)
                {
                    foreach(Loader loader in loaderList)
                    {
                        if (loader.www.isDone)
                        {
                            loaderList.Remove(loader);

                            if (string.IsNullOrEmpty(loader.www.error))
                            {
                                Debug.Log("Loader complete:" + loader.request.url);

                                if (loader.callback != null)
                                {
                                    LoaderResponse response = new LoaderResponse();
                                    response.isSuccessful = true;
                                    response.request = loader.request;
                                    response.extraData = loader.extraData;

                                    LoaderType type = loader.request.type;
                                    if (type == LoaderType.Text)
                                    {
                                        response.text = loader.www.text;
                                    }
                                    else if (type == LoaderType.Byte)
                                    {
                                        response.bytes = loader.www.bytes;
                                    }
                                    else if (type == LoaderType.Texture)
                                    {
                                        response.texture2D = loader.www.texture;
                                    }
                                    else if (type == LoaderType.AssetBundle)
                                    {
                                        response.assetBundle = loader.www.assetBundle;
                                        garbageList.Add(response.assetBundle);
                                    }
                                    else
                                    {
                                        // Do nothing
                                    }

                                    loader.callback(response);
                                }
                            }
                            else
                            {
                                Debug.LogError("Loader error:" + loader.www.error);

                                if (loader.callback != null)
                                {
                                    LoaderResponse response = new LoaderResponse();
                                    response.isSuccessful = false;
                                    response.error = loader.www.error;
                                    response.request = loader.request;
                                    response.extraData = loader.extraData;

                                    loader.callback(response);
                                }
                            }
                            break;
                        }
                    }
                }

                yield return null;
            }
        }