コード例 #1
0
ファイル: LoaderBundleBase.cs プロジェクト: xxyzfd/unityLab
        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);
        }
コード例 #2
0
ファイル: CacheLoader.cs プロジェクト: xxyzfd/unityLab
        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);
                    }
                }
            }
        }
コード例 #3
0
ファイル: CacheLoader.cs プロジェクト: xxyzfd/unityLab
        private void LoaderCallback(LoaderResponse response)
        {
            if (response.isSuccessful)
            {
                cacheMap.Add(response.request.url, response);
            }

            if (callback != null)
            {
                callback(response);
            }
        }
コード例 #4
0
ファイル: LoaderQueueBase.cs プロジェクト: xxyzfd/unityLab
        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();
        }
コード例 #5
0
ファイル: CacheLoader.cs プロジェクト: xxyzfd/unityLab
 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;
     }
 }
コード例 #6
0
ファイル: CacheLoader.cs プロジェクト: moto2002/unityLab
 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;
     }
 }
コード例 #7
0
ファイル: LoaderBundleBase.cs プロジェクト: xxyzfd/unityLab
        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);
                }
            }
        }
コード例 #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);
            }
        }
コード例 #9
0
ファイル: CacheLoader.cs プロジェクト: moto2002/unityLab
        private void LoaderCallback(LoaderResponse response)
        {
            if (response.isSuccessful)
            {
                cacheMap.Add(response.request.url, response);
            }

            if (callback != null)
            {
                callback(response);
            }
        }
コード例 #10
0
ファイル: Loader.cs プロジェクト: moto2002/unityLab
        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;
            }
        }