예제 #1
0
            }                                                                                         //files requested and being processed or done

            public void Unload()
            {
                //unload requested resources
                foreach (KeyValuePair <string, ResourceLoader.Request> pair in processedRequests)
                {
                    ResourceLoader.Request req = pair.Value;
                    if (req.isDone && req.data != null)
                    {
                        loader.UnloadResource(req.data);
                    }
                }

                processedRequests.Clear();
            }
예제 #2
0
        public ResourceLoader.Request RequestResourceFrom(string group, string path, System.Type type)
        {
            List <Package> packageRefs;

            if (mGroups.TryGetValue(group, out packageRefs))
            {
                //check each package to see if this path is already processed
                for (int i = packageRefs.Count - 1; i >= 0; i--)
                {
                    Package pkg = packageRefs[i];

                    if (pkg.processedRequests.ContainsKey(path))
                    {
                        return(pkg.processedRequests[path]);
                    }
                }

                //check if already queued
                foreach (RequestProcess rp in mRequestQueue)
                {
                    if (rp.request.path == path && rp.group == group)
                    {
                        return(rp.request);
                    }
                }

                //add to process queue
                ResourceLoader.Request request = ResourceLoader.CreateRequest(path, type);
                mRequestQueue.Enqueue(new RequestProcess()
                {
                    group = group, request = request
                });

                if (mLoadAct == null)
                {
                    StartCoroutine(mLoadAct = DoLoading());
                }

                return(request);
            }
            else
            {
                Debug.LogError("Group not found: " + group);
            }

            return(null);
        }
예제 #3
0
        public ResourceLoader.Request RequestResource(string path, System.Type type)
        {
            //check each package to see if this path is already processed
            for (int i = mPackages.Count - 1; i >= 0; i--)
            {
                Package pkg = mPackages[i];

                if (pkg.processedRequests.ContainsKey(path))
                {
                    return(pkg.processedRequests[path]);
                }
            }

            //check if already queued
            foreach (RequestProcess rp in mRequestQueue)
            {
                if (rp.request.path == path)
                {
                    return(rp.request);
                }
            }

            //add to process queue
            ResourceLoader.Request request = ResourceLoader.CreateRequest(path, type);
            mRequestQueue.Enqueue(new RequestProcess()
            {
                group = "", request = request
            });

            if (mLoadAct == null)
            {
                StartCoroutine(mLoadAct = DoLoading());
            }

            return(request);
        }
예제 #4
0
        IEnumerator DoLoading()
        {
            while (mLoadPackageQueue.Count > 0 || mRequestQueue.Count > 0)
            {
                //load all packages
                if (mLoadPackageQueue.Count > 0)
                {
                    Package pkg = mLoadPackageQueue.Dequeue();

                    if (pkg.loadQueue)
                    {
                        pkg.loadQueue = false;

                        //wait loading
                        yield return(StartCoroutine(mLoadAct = pkg.loader.Load()));

                        //done loading
                        if (pkg.loader.status == ResourceLoader.Status.Error)
                        {
                            Debug.LogError("Error loading: " + pkg.loader.rootPath + " msg: " + pkg.loader.error);
                            mPackages.Remove(pkg);
                        }
                        else if (pkg.counter <= 0)
                        {
                            //must have been requested to be removed
                            pkg.Unload();
                            mPackages.Remove(pkg);
                        }
                    }
                }
                //load requests
                else if (mRequestQueue.Count > 0)
                {
                    RequestProcess         requestProc = mRequestQueue.Dequeue();
                    ResourceLoader.Request request     = requestProc.request;
                    bool processed = false;

                    //grab appropriate package
                    if (string.IsNullOrEmpty(requestProc.group))
                    {
                        int errorCount = 0;
                        for (int i = mPackages.Count - 1; i >= 0; i--)
                        {
                            Package pkg = mPackages[i];

                            //make sure package is loaded
                            if (pkg.loader.status == ResourceLoader.Status.Loaded)
                            {
                                if (pkg.loader.ProcessRequest(request))
                                {
                                    pkg.processedRequests.Add(request.path, request); //done
                                    processed = true;
                                    break;
                                }
                                else
                                {
                                    errorCount++;
                                }
                            }
                            else if (pkg.loader.status != ResourceLoader.Status.Loading)
                            {
                                errorCount++; //package is unloaded or is somewhat invalid
                            }
                        }

                        //not yet processed, try again later once everything is loaded
                        if (errorCount < mPackages.Count)
                        {
                            if (!processed)
                            {
                                mRequestQueue.Enqueue(requestProc);
                            }
                        }
                        else
                        {
                            Debug.LogError(request.error);
                        }
                    }
                    else
                    {
                        List <Package> packageRefs;
                        if (mGroups.TryGetValue(requestProc.group, out packageRefs))
                        {
                            int errorCount = 0;
                            for (int i = packageRefs.Count - 1; i >= 0; i--)
                            {
                                Package pkg = packageRefs[i];

                                //make sure package is loaded
                                if (pkg.loader.status == ResourceLoader.Status.Loaded)
                                {
                                    if (pkg.loader.ProcessRequest(request))
                                    {
                                        pkg.processedRequests.Add(request.path, request); //done
                                        processed = true;
                                        break;
                                    }
                                    else
                                    {
                                        errorCount++;
                                    }
                                }
                                else if (pkg.loader.status != ResourceLoader.Status.Loading)
                                {
                                    errorCount++; //package is unloaded or is somewhat invalid
                                }
                            }

                            //not yet processed, try again later once everything is loaded
                            if (errorCount < packageRefs.Count)
                            {
                                if (!processed)
                                {
                                    mRequestQueue.Enqueue(requestProc);
                                }
                            }
                            else
                            {
                                Debug.LogError(request.error);
                            }
                        }
                        else   //no longer exists??
                        {
                            Debug.LogError("Group not found: " + requestProc.group);
                            ResourceLoader.RequestError(request, ResourceLoader.ErrorCode.InvalidPackage);
                            Debug.LogError(request.error);
                        }
                    }
                }

                yield return(null);
            }

            mLoadAct = null;
        }