Пример #1
0
        private void completeHandle(EventX e)
        {
            isLoaded = true;
            AssetResource resource = e.target as AssetResource;

            AssetsManager.bindEventHandle(resource, completeHandle, false);
            if (e.type == EventX.FAILED)
            {
                return;
            }

            if (gameObject.activeSelf == false)
            {
                recycle();
                return;
            }

            AudioClip clip = resource.getMainAsset() as AudioClip;

            if (clip != null)
            {
                _source.clip   = clip;
                _source.loop   = loop;
                _source.volume = _soundValue;
                _source.Play();
                if (loop == false)
                {
                    CallLater.Add(recycle, _source.clip.length);
                }
            }
        }
Пример #2
0
        protected override void _loadImp(int priority = 0, bool progress = false, uint retryCount = 0)
        {
            this.isProgress = progress;
            string manifesURI = "/" + manifesKey + "/";
            int    len        = manifesURI.Length;

            if (string.IsNullOrEmpty(manifesKey))
            {
                throw new Exception("不正常:" + _url + "\tmanifesKey:" + manifesKey);
            }

            int index = _url.IndexOf(manifesURI);

            manifesPrefix = _url.Substring(0, index + len);
            dependKey     = url.Substring(index + len).ToLower();
            //prefab会被转换成小写的;
            this._url = manifesPrefix + dependKey;
            string manifesURL = manifesPrefix + manifesKey;

            //不做除引用操作;

            manifestResource = AssetsManager.getResource(manifesURL, LoaderXDataType.MANIFEST);
            manifestResource.initManifes(manifesPrefix, manifesKey);
            manifestResource.isForceRemote = isForceRemote;
            AssetsManager.bindEventHandle(manifestResource, manifesHandle);
            manifestResource.load();
        }
Пример #3
0
        public void load(string uri)
        {
            if (this.uri == uri)
            {
                return;
            }

            this.uri = uri;

            if (string.IsNullOrEmpty(uri))
            {
                return;
            }

            string url = getURL(uri);

            if (resource != null)
            {
                resource.release();
                AssetsManager.bindEventHandle(resource, resourceHandle, false);
            }

            resource = AssetsManager.getResource(url, LoaderXDataType.ASSETBUNDLE);
            resource.retain();
            AssetsManager.bindEventHandle(resource, resourceHandle);
            resource.load();
        }
Пример #4
0
        private void loadNext()
        {
            int hasCount = queue.Count;

            if (running == 0 && hasCount == 0)
            {
                this.simpleDispatch(EventX.COMPLETE);
                return;
            }

            while (running < threadCount && hasCount > 0)
            {
                AssetResource resource = queue.Dequeue();
                runningList.Add(resource);
                resource.addEventListener(EventX.COMPLETE, itemComplete);
                resource.addEventListener(EventX.FAILED, itemComplete);
                //resource.addEventListener(AssetEvent.PROGRESS, itemProgress);
                running++;
                hasCount--;
                newRunnigList.Add(resource);
            }
            int len = newRunnigList.Count;

            for (int i = 0; i < len; i++)
            {
                newRunnigList[i].load(0, false, retryCount);
            }
            newRunnigList.Clear();
        }
Пример #5
0
        private void _doNext()
        {
            if (isComplete)
            {
                return;
            }
            testCount++;
            if (queue.Count == 0 && running == 0 && isComplete == false)
            {
                isComplete = true;
                Log("QuComplete");
                this.simpleDispatch(EventX.COMPLETE);
                return;
            }

            while (queue.Count > 0 && running < threadCount)
            {
                AssetResource resource = queue.Dequeue();
                runningList.Add(resource);

                running++;
                Log("QuStart: {0} {1}", running, resource.url);

                AssetsManager.bindEventHandle(resource, itemComplete);
                resource.addEventListener(EventX.DISPOSE, itemComplete);
                resource.addEventListener(EventX.PROGRESS, itemProgress);
                resource.load(retryCount, false);
            }
        }
Пример #6
0
        private void itemComplete(EventX e)
        {
            AssetResource resource = e.target as AssetResource;

            resource.removeEventListener(EventX.COMPLETE, itemComplete);
            resource.removeEventListener(EventX.FAILED, itemComplete);
            //resource.removeEventListener(AssetEvent.PROGRESS, itemProgress);
            int index = runningList.IndexOf(resource);

            if (index != -1)
            {
                runningList.RemoveAt(index);
            }

            if (isStart == false)
            {
                return;
            }
            running--;

            loaded = total - queue.Count;
            this.dispatchEvent(new EventX(EventX.PROGRESS, (float)loaded / total));

            Action <EventX> action = null;

            if (resultActions.TryGetValue(resource.id, out action))
            {
                action(e);
            }

            CallLater.Add(loadNext);
        }
        protected override void _loadImp(int priority = 0, bool progress = false, uint retryCount = 0)
        {
            this.isProgress = progress;
            string manifesURI = "/" + manifesKey + "/";
            int    len        = manifesURI.Length;

            if (string.IsNullOrEmpty(manifesKey))
            {
                throw new Exception("不正常");
            }

            int index = url.IndexOf(manifesURI);

            manifesPrefix = url.Substring(0, index + len);

            dependKey = url.Substring(index + len);

            manifesURI = manifesKey + ".manifest";
            string        manifesURL = manifesPrefix + manifesKey;
            AssetResource resource   = AssetsManager.getResource(manifesURL, manifesURI, LoaderXDataType.MANIFEST);

            if (progress)
            {
                resource.addEventListener(EventX.PROGRESS, progressHandle);
            }
            AssetsManager.bindEventHandle(resource, manifesHandle);
            resource.load(3);

            return;
        }
Пример #8
0
        private AssetResource _getResource(string url, string uri = null, LoaderXDataType autoCreateType = LoaderXDataType.BYTES)
        {
            if (uri == null)
            {
                uri = url;
            }

            AssetResource res = findResource(uri);

            if (res == null)
            {
                Type cls = null;

                if (resourceTypeMapping.TryGetValue(autoCreateType, out cls) == false)
                {
                    res = new AssetResource(url, uri);
                }
                else
                {
                    res = (AssetResource)Activator.CreateInstance(cls, url, uri);
                }

                res.parserType = autoCreateType;
                res.addEventListener(EventX.DISPOSE, resourceDisposeHandle);

                string key = uri.ToLower();
                _resourceMap[key] = res;
            }
            return(res);
        }
Пример #9
0
        public void _release(string uri)
        {
            AssetResource res = null;

            //DebugX.Log("disposeAsset:"+uri);
            uri = uri.ToLower();
            if (_resourceMap.TryGetValue(uri, out res))
            {
                res.release();
            }
        }
Пример #10
0
        private void resourceDisposeHandle(EventX e)
        {
            AssetResource res = e.target as AssetResource;

            res.removeEventListener(EventX.DISPOSE, resourceDisposeHandle);

            string uri = res.id;

            if (_resourceMap.ContainsKey(uri))
            {
                _resourceMap.Remove(uri);
            }
        }
        private void manifesHandle(EventX e)
        {
            AssetResource resource = e.target as AssetResource;

            resource.removeEventListener(EventX.PROGRESS, progressHandle);
            AssetsManager.bindEventHandle(resource, manifesHandle, false);
            if (e.type != EventX.COMPLETE)
            {
                _data = null;
                resourceComplete(e.type);
                return;
            }
            QueueLoader queueLoader = new QueueLoader();

            queueLoader.retryCount = 3;
            queueLoader.addEventListener(EventX.COMPLETE, dependsHandle);
            if (isProgress)
            {
                queueLoader.addEventListener(EventX.PROGRESS, progressHandle);
            }
            assetBundleManifest = resource.data as AssetBundleManifest;
            string[] dependencies = assetBundleManifest.GetAllDependencies(dependKey);

            //Hash128 hash = assetBundleManifest.GetAssetBundleHash(dependKey);
            string        hashValue = null;
            string        hashKey   = null;
            AssetResource tempResource;

            foreach (string dependency in dependencies)
            {
                string url = manifesPrefix + dependency;
                string uri = manifesKey + "/" + dependency;
                //Debug.Log(dependency);
                hashValue = assetBundleManifest.GetAssetBundleHash(dependency).ToString();
                hashKey   = manifesKey + "_" + hashValue;
                if (resourceHash128Maping.TryGetValue(hashKey, out tempResource) == false)
                {
                    tempResource = AssetsManager.getResource(url, uri, LoaderXDataType.ASSETBUNDLE);
                    resourceHash128Maping.Add(hashKey, tempResource);
                }

                /*else if (url != tempResource.url)
                 * {
                 *  Debug.Log("redirect:" + url + " to:" + tempResource.url);
                 * }*/

                tempResource.retain();
                queueLoader.add(tempResource);
            }
            queueLoader.start();
        }
Пример #12
0
        private void innerAdd(string uri, AssetResource resource, Action <EventX> resultHandle)
        {
            urlMapping.Add(uri, resource);
            queue.Enqueue(resource);
            if (resultHandle != null && resultActions.ContainsKey(uri) == false)
            {
                resultActions.Add(uri, resultHandle);
            }

            if (running == 0 && isStart)
            {
                loadNext();
            }
        }
Пример #13
0
        private void resourceDisposeHandle(EventX e)
        {
            AssetResource res = e.target as AssetResource;

            res.removeEventListener(EventX.DISPOSE, resourceDisposeHandle);

            string uri = res.url.ToLower();

            //DebugX.Log("assetDisposeAsset:" + uri);
            if (_resourceMap.ContainsKey(uri))
            {
                _resourceMap.Remove(uri);
            }
        }
Пример #14
0
        public void add(AssetResource resource, Action <EventX> resultHandle = null)
        {
            if (resource == null)
            {
                return;
            }
            string uri = resource.id;

            if (urlMapping.ContainsKey(uri))
            {
                return;
            }
            innerAdd(uri, resource, resultHandle);
        }
Пример #15
0
        public void _dispose(string url)
        {
            AssetResource res = null;

            //DebugX.Log("disposeAsset:"+url);
            url = url.ToLower();
            if (_resourceMap.TryGetValue(url, out res))
            {
                _resourceMap.Remove(url);

                res.removeEventListener(EventX.DISPOSE, resourceDisposeHandle);
                res.__dispose();
            }
        }
Пример #16
0
        private void dependsHandle(EventX e)
        {
            currentProgress = 0.8f;
            float progress = (_totalDependCount - _needLoadedDependCount) / (float)_totalDependCount;

            simpleDispatch(EventX.PROGRESS, 0.7f * progress + 0.1f);

            AssetResource tempResource = e.target as AssetResource;

            AssetsManager.bindEventHandle(tempResource, dependsHandle, false);
            tempResource.removeEventListener(EventX.DEPEND_READY, dependsHandle);

            _needLoadedDependCount--;
            checkAllComplete();
        }
Пример #17
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="url"></param>
        /// <param name="uri"></param>
        /// <param name="type"></param>
        /// <param name="resultHandle">同url只返回一次回调</param>
        /// <returns></returns>
        public AssetResource add(string url, string uri, LoaderXDataType type, Action <EventX> resultHandle = null)
        {
            AssetResource resource = null;

            if (urlMapping.TryGetValue(uri, out resource))
            {
                return(resource);
            }
            resource = AssetsManager.getResource(url, uri, type);
            if (resource == null)
            {
                return(null);
            }
            innerAdd(uri, resource, resultHandle);
            return(resource);
        }
Пример #18
0
        public AssetResource findResource(string uri)
        {
            if (uri == null)
            {
                return(null);
            }
            AssetResource res = null;
            string        key = uri.ToLower();

            if (_resourceMap.TryGetValue(key, out res))
            {
                return(res);
            }

            return(null);
        }
Пример #19
0
        public void load(string url)
        {
            isLoaded = false;

            AssetResource resource = null;

            if (AssetsManager.routerResourceDelegate != null)
            {
                resource = AssetsManager.routerResourceDelegate(url, name, "sound");
            }
            if (resource == null)
            {
                resource = AssetsManager.getResource(url, LoaderXDataType.PREFAB);
            }
            AssetsManager.bindEventHandle(resource, completeHandle);
            resource.load();
        }
Пример #20
0
        private void resourceHandle(EventX e)
        {
            AssetResource resource = e.target as AssetResource;

            AssetsManager.bindEventHandle(resource, resourceHandle, false);

            if (e.type != EventX.COMPLETE)
            {
                return;
            }
            UpkAniVO o = resource.getMainAsset() as UpkAniVO;

            if (null == o)
            {
                return;
            }
            upkAniVo = o;
        }
Пример #21
0
        public void _dispose(string uri)
        {
            AssetResource res = null;

            if (_resourceMap.TryGetValue(uri, out res))
            {
                _resourceMap.Remove(uri);

                res.removeEventListener(EventX.DISPOSE, resourceDisposeHandle);
                res.__dispose();

                //trace("dispose",uri);
            }
            else
            {
                //RFTraceWarn(uri+" 不在AssetsManager里!");
            }
        }
        public RFLoader getLoader(AssetResource resource)
        {
            RFLoader        loader     = null;
            string          url        = resource.url;
            LoaderXDataType parserType = resource.parserType;

            if (_loadingPool.TryGetValue(resource.url, out loader))
            {
                return(loader);
            }

            string locaPath = versionLoaderFactory.getLocalPathByURL(url, true);

            if (resource.isForceRemote == false)
            {
                //先验证是否有热更新的资源
                string fullLocalPath = PathDefine.getPersistentLocal(locaPath);
                if (File.Exists(fullLocalPath) == true)
                {
                    loader = new FileStreamLoader(fullLocalPath, url, parserType);
                }
                else
                {
                    fullLocalPath = PathDefine.getStreamingAssetsLocal(locaPath, true);
                    ///ios强制使用WebRequest;
                    loader = new WebRequestLoader(fullLocalPath, parserType);
                }
            }

            if (loader == null)
            {
                loader             = new WebRequestLoader(url, parserType);
                loader.isLocalFile = false;
                if (resource.isForceRemote)
                {
                    loader.postData = resource.postData;
                    loader.timeout  = resource.timeout;
                }
            }

            _loadingPool[resource.url] = loader;
            return(loader);
        }
Пример #23
0
        private void itemComplete(EventX e)
        {
            AssetResource resource = e.target as AssetResource;

            AssetsManager.bindEventHandle(resource, itemComplete, false);
            resource.removeEventListener(EventX.PROGRESS, itemProgress);
            resource.removeEventListener(EventX.DISPOSE, itemComplete);

            runningList.Remove(resource);
            running--;
            Log("QuEnd: {0} {1},{2},{3}", running, e.type, resource.url, queue.Count);

            if (running < 0)
            {
                DebugX.LogError("queueLoader error runnig=" + running);
            }

            if (e.type != EventX.COMPLETE)
            {
                faildCount++;
                if (maxFailCount > 0 && faildCount > maxFailCount)
                {
                    this.simpleDispatch(EventX.FAILED, e);
                }
                DebugX.LogWarning("QuItemFailed:" + resource.url + ":" + e.type + " faildCount:" + faildCount + "/" + maxFailCount);
            }

            preProgress = 0.0f;
            loaded      = total - (queue.Count + running);
            //DebugX.Log("kk:" + (loaded) / (float)total);
            this.simpleDispatch(EventX.PROGRESS, loaded / (float)total);

            Action <EventX> action = null;

            string key = resource.url.ToLower();

            if (resultActions.TryGetValue(key, out action))
            {
                action(e);
            }

            _doNext();
        }
Пример #24
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="url"></param>
        /// <param name="uri"></param>
        /// <param name="type"></param>
        /// <param name="resultHandle">同url只返回一次回调</param>
        /// <returns></returns>
        public AssetResource add(string url, LoaderXDataType type, Action <EventX> resultHandle = null)
        {
            if (isStart)
            {
                DebugX.LogError("Qu不能在运行时加入:" + url);
            }

            AssetResource resource = null;

            if (string.IsNullOrEmpty(url))
            {
                return(resource);
            }

            string key = url.ToLower();

            if (urlMapping.TryGetValue(key, out resource))
            {
                return(resource);
            }
            resource = AssetsManager.getResource(url, type);
            if (resource == null)
            {
                return(null);
            }

            if (isUseRef)
            {
                resource.retain();
            }

            urlMapping.Add(key, resource);
            queue.Enqueue(resource);
            if (resultHandle != null && resultActions.ContainsKey(key) == false)
            {
                resultActions.Add(key, resultHandle);
            }

            return(resource);
        }
Пример #25
0
        private void manifesHandle(EventX e)
        {
            currentProgress = 0.1f;
            simpleDispatch(EventX.PROGRESS, currentProgress);
            if (dependenciesResource.Count > 0)
            {
                foreach (AssetResource assetResource in dependenciesResource)
                {
                    assetResource.removeEventListener(EventX.DEPEND_READY, dependsHandle);
                    AssetsManager.bindEventHandle(assetResource, dependsHandle, false);
                    assetResource.release();
                }
                dependenciesResource.Clear();
            }

            AssetResource resource = e.target as AssetResource;

            AssetsManager.bindEventHandle(resource, manifesHandle, false);
            if (e.type != EventX.COMPLETE)
            {
                _data = null;
                resourceComplete(EventX.FAILED);
                return;
            }
            assetBundleManifest = resource.data as AssetBundleManifest;

            string[]      dependencies = assetBundleManifest.GetDirectDependencies(dependKey);
            AssetResource tempResource;
            int           len = _needLoadedDependCount = dependencies.Length;

            //增加自身
            _needLoadedDependCount += 1;

            if (len > 0)
            {
                //DebugX.Log(dependKey + ":::::::::::::::::::::::::::::::::::::" + len);
                for (int i = 0; i < len; i++)
                {
                    string dependency = dependencies[i];
                    if (dependency == dependKey)
                    {
                        _needLoadedDependCount--;
                        continue;
                    }
                    string url = manifesPrefix + dependency;
                    //DebugX.Log(url);
                    tempResource = AssetsManager.getResource(url, LoaderXDataType.ASSETBUNDLE);
                    if (dependenciesResource.Contains(tempResource))
                    {
                        DebugX.Log("hasDuplicate:" + url);
                        _needLoadedDependCount--;
                        continue;
                    }
                    tempResource.retain();
                    dependenciesResource.Add(tempResource);

                    AssetBundle old;
                    string      key = url.ToLower();
                    RFLoader.assetBundleMapping.TryGetValue(key, out old);
                    if (old != null || tempResource.isLoaded)
                    {
                        //DebugX.LogWarning("has:"+url);
                        _needLoadedDependCount--;
                        continue;
                    }

                    tempResource.addEventListener(EventX.DEPEND_READY, dependsHandle);
                    AssetsManager.bindEventHandle(tempResource, dependsHandle);

                    tempResource.load();
                }
            }

            _totalDependCount = _needLoadedDependCount;

            base._loadImp(0, isProgress);
        }