Exemplo n.º 1
0
        public void BeginLoad(CRequest req)
        {
            this.isFree = false;
            this._req = req;
            this.enabled = true;
            string url = req.url;
            if (url.IndexOf("://") == -1)
            {
                url = "file://" + url;
            }
            if (req.head is WWWForm)
            {
                www = new WWW(url, (WWWForm)req.head);
            }
            else if (req.head is byte[])
            {
                www = new WWW(url, (byte[])req.head);
            }
            else
            {
                //			if (url.StartsWith ("http")) {
                //				if(CResLoader.assetBundleManifest!=null)
                //					www = WWW.LoadFromCacheOrDownload (url, CResLoader.assetBundleManifest.GetAssetBundleHash (req.assetBundleName), 0);
                //				else
                //					www = WWW.LoadFromCacheOrDownload (url, 0);
                //			}
                //            else
                www = new WWW(url);
            }

            //Debug.LogFormat("<color=green> begin load {0} </color>", url);
        }
Exemplo n.º 2
0
 /// <summary>
 /// �жϵ�0����Դ�Ƿ����
 /// </summary>
 /// <returns><c>true</c>, if exists was check0ed, <c>false</c> otherwise.</returns>
 /// <param name="req">Req.</param>
 public static void CheckUri0Exists(CRequest req)
 {
     if (req.index == 0 && !req.url.StartsWith(Common.HTTP_STRING) && !File.Exists(req.url))
     { //���û�и���
         SetRequestUri(req, 1);
     }
 }
Exemplo n.º 3
0
 static public int set_OnComplete(IntPtr l)
 {
     try {
         Hugula.Loader.CRequest self = (Hugula.Loader.CRequest)checkSelf(l);
         System.Action <Hugula.Loader.CRequest> v;
         int op = LuaDelegation.checkDelegate(l, 2, out v);
         if (op == 0)
         {
             self.OnComplete = v;
         }
         else if (op == 1)
         {
             self.OnComplete += v;
         }
         else if (op == 2)
         {
             self.OnComplete -= v;
         }
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 4
0
 public static string OverrideRequestUrlByCrc(CRequest req)
 {
     string url = req.url;
     uint crc = Hugula.Update.CrcCheck.GetCrc(req.assetBundleName);
     if(crc>0)
     {
         url = CUtils.InsertAssetBundleName(url, "_" + crc.ToString());
     }
     return url;
 }
Exemplo n.º 5
0
 static public int get_uris(IntPtr l)
 {
     try {
         Hugula.Loader.CRequest self = (Hugula.Loader.CRequest)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.uris);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 6
0
 static public int get_isLoadFromCacheOrDownload(IntPtr l)
 {
     try {
         Hugula.Loader.CRequest self = (Hugula.Loader.CRequest)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.isLoadFromCacheOrDownload);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 7
0
 static public int DispatchEnd(IntPtr l)
 {
     try {
         Hugula.Loader.CRequest self = (Hugula.Loader.CRequest)checkSelf(l);
         self.DispatchEnd();
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 8
0
 static public int set_uris(IntPtr l)
 {
     try {
         Hugula.Loader.CRequest self = (Hugula.Loader.CRequest)checkSelf(l);
         Hugula.Loader.UriGroup v;
         checkType(l, 2, out v);
         self.uris = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 9
0
 static public int set_udAssetKey(IntPtr l)
 {
     try {
         Hugula.Loader.CRequest self = (Hugula.Loader.CRequest)checkSelf(l);
         string v;
         checkType(l, 2, out v);
         self.udAssetKey = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 10
0
 static public int set_index(IntPtr l)
 {
     try {
         Hugula.Loader.CRequest self = (Hugula.Loader.CRequest)checkSelf(l);
         System.Int32           v;
         checkType(l, 2, out v);
         self.index = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 11
0
        /// <summary>
        /// real load assetbundle
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        static protected AssetBundleDownloadOperation LoadAssetBundleInternal(CRequest req)
        {
            AssetBundleDownloadOperation abDownloadOp = null;

            if (!downloadingBundles.TryGetValue(req.key, out abDownloadOp))
            {
#if HUGULA_PROFILER_DEBUG
                Profiler.BeginSample(string.Format("LoadAssetBundleInternal ({0},{1},{2})", req.assetName, req.key, req.isShared));
#endif
                if (!UriGroup.CheckRequestCurrentIndexCrc(req)) //crc
                {
                    abDownloadOp       = new AssetBundleDownloadErrorOperation();
                    abDownloadOp.error = string.Format("assetbundle({0}) crc check wrong ", req.key);
                }
                else if (req.url.StartsWith(Common.HTTP_STRING))  //load assetbunlde
                {
                    abDownloadOp = AssetBundleDownloadFromWebOperation.Get();
                }
                else
                {
                    abDownloadOp = AssetBundleDownloadFromDiskOperation.Get();
                }
                abDownloadOp.SetRequest(req);
                downloadingBundles.Add(req.key, abDownloadOp);

                //load now
                if (bundleMax - inProgressBundleOperations.Count > 0)
                {
                    inProgressBundleOperations.Add(abDownloadOp);
                    abDownloadOp.BeginDownload();
                }
                else
                {
                    bundleQueue.Enqueue(abDownloadOp);
                }
#if HUGULA_LOADER_DEBUG
                HugulaDebug.FilterLogFormat(req.key, "<color=#10f010>1.2 LoadAssetBundleInternal Request(key={0},isShared={1},assetname={2},dependencies.count={4})keyHashCode{3}, frameCount{5}</color>", req.key, req.isShared, req.assetName, req.keyHashCode, req.dependencies == null ? 0 : req.dependencies.Length, Time.frameCount);
#endif

#if HUGULA_PROFILER_DEBUG
                Profiler.EndSample();
#endif
            }
            else if (req.isShared)
            {
                req.ReleaseToPool();
            }

            return(abDownloadOp);
        }
Exemplo n.º 12
0
        public static bool CheckRequestUrlIsAssetbundle(CRequest req)
        {
            string suffix = CUtils.GetSuffix(req.url);

            if ((suffix == Common.ASSETBUNDLE_SUFFIX ||
                 (HugulaSetting.instance != null && HugulaSetting.instance.ContainsVariant(suffix))) &&
                !typeof(string).Equals(req.assetType)
                )
            {
                req.isAssetBundle = true;
            }

            return(req.isAssetBundle);
        }
Exemplo n.º 13
0
 static public int set_isLoadFromCacheOrDownload(IntPtr l)
 {
     try {
         Hugula.Loader.CRequest self = (Hugula.Loader.CRequest)checkSelf(l);
         System.Boolean         v;
         checkType(l, 2, out v);
         self.isLoadFromCacheOrDownload = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 14
0
        /// <summary>
        /// 判断加载
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        static protected bool CheckLoadAssetBundle(CRequest req)
        {
            if (CacheManager.Contains(req.keyHashCode))
            {
                return(true);
            }

            if (downloadings.ContainsKey(req.udKey))
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 15
0
        protected static void CallbackAsyncList(CRequest creq)
        {
            List <CRequest> callbacklist = null;// requestCallBackList[creq.udKey];
            string          udkey        = creq.udKey;

            if (requestCallBackList.TryGetValue(udkey, out callbacklist))
            {
                requestCallBackList.Remove(udkey);
                int      count = callbacklist.Count;
                CRequest reqitem;
                for (int i = 0; i < count; i++)
                {
                    reqitem = callbacklist[i];

                    if (!creq.isAssetBundle)                       //如果加载的不是assetbundle
                    {
                        reqitem.data = creq.data;
                        loadedAssetQueue.Enqueue(reqitem);
                                                #if HUGULA_LOADER_DEBUG
                        Debug.LogFormat("3. <color=green>  Add all to loadedAssetQueue Req(assetname={0},url={1})  </color>", creq.assetName, creq.url);
                                                #endif
                    }
                    else                         // if (!creq.isShared) { //非共享资源需要回调
                    {
                        loadingAssetBundleQueue.Add(reqitem);
                                                #if HUGULA_LOADER_DEBUG
                        Debug.LogFormat("3. <color=green>  Add all to loadingAssetBundleQueue Req(assetname={0},url={1})  </color>", creq.assetName, creq.url);
                                                #endif
                    }
                }
                ListPool <CRequest> .Release(callbacklist);

                // if(creq.isShared)loadingAssetBundleQueue.Add(creq);
            }
            else
            {
                if (!creq.isAssetBundle)                 //r如果不是assetbundle不需要load asset
                {
                    loadedAssetQueue.Enqueue(creq);
                }
                else
                {
                    loadingAssetBundleQueue.Add(creq);
                }
                                #if HUGULA_LOADER_DEBUG
                Debug.LogFormat("3. <color=green> Add one to loadingAssetBundleQueue Req(assetname={0},url={1})  </color>", creq.assetName, creq.url);
                                #endif
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// 加载资源
        /// </summary>
        /// <param name="CRequest">request</param>
        /// <param name="bool">async = true 异步加载</param>
        /// <returns></returns>
        static int LoadAsset(CRequest request, bool async = true, bool subAssets = false)
        {
            totalCount++; //count ++
            int opID = 0;

            LoadAssetBundle(request.assetBundleName, async);
#if UNITY_EDITOR
            if (SimulateAssetBundleInEditor)
            {
                AssetOperationSimulation assetOperS = OperationPools <AssetOperationSimulation> .Get();

                assetOperS.request   = request;
                assetOperS.subAssets = subAssets;
                assetOperS.StartSync();

                assetOperS.ReleaseToPool();
                DispatchReqAssetOperation(request, request.error != null, 0, false); //模拟器模式下只有同步所以需要调用回调
            }
            else
#endif
            {
                var assetOper = OperationPools <AssetOperation> .Get();

                assetOper.request   = request;
                assetOper.subAssets = subAssets;
                if (async) //如果异步加载 设置id可以阻止回调
                {
                    AssetOperation.SetId(assetOper);
                    opID = assetOper.id;
                    completeOper.Add(opID);
                }

                if (!async) //同步加载
                {
                    assetOper.StartSync();
                    assetOper.ReleaseToPool();
                }
                else if (inProgressOperations.Count >= maxLoading) //如果大于最大值
                {
                    waitOperations.Enqueue(assetOper);             //放入等待列表
                }
                else
                {
                    inProgressOperations.Add(assetOper);
                }
                // Debug.LogFormat("LoadAsset({0},{1},{2})", opID, request.assetBundleName,request.assetName);
            }
            return(opID);
        }
Exemplo n.º 17
0
        static void PopGroup(CRequest req)
        {
            GroupRequestRecord group;

            if (currGroupRequestsRef.TryGetValue(req, out group))
            {
                currGroupRequestsRef.Remove(req);
                group.Complete(req);
            }

            if (req.pool)
            {
                LRequest.Release(req);
            }
        }
Exemplo n.º 18
0
        /// <summary>
        ///  以 WWW 方式加载网络非ab资源
        /// </summary>
        /// <param name="url"></param>
        /// <param name="head"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        static public HttpLoadOperation HttpWebRequestCoroutine(string url, WebHeaderCollection head, System.Type type)
        {
            var req = CRequest.Get();

            req.vUrl      = url;
            req.head      = head;
            req.assetType = type;
            HttpWebRequestOperation op = new HttpWebRequestOperation();

            req.assetOperation = op;
            op.SetRequest(req);
            inProgressOperations.Add(op);
            op.BeginDownload();
            return(op);
        }
Exemplo n.º 19
0
        //创建一个CRequest
        public static CRequest Create(string relativeUrl, string assetName, Type assetType, System.Action <CRequest> onComp, System.Action <CRequest> onEnd,
                                      object head, bool async)
        {
            var req = CRequest.Get();

            req.relativeUrl = relativeUrl;
            req.assetName   = assetName;
            req.assetType   = assetType;

            req.OnComplete = onComp;
            req.OnEnd      = onEnd;
            req.head       = head;
            req.async      = async;

            return(req);
        }
Exemplo n.º 20
0
        /// <summary>
        /// 加载场景
        /// </summary>
        /// <param name="abName"></param>
        /// <param name="sceneName"></param>
        /// <param name="onComplete"></param>
        /// <param name="onEnd"></param>
        /// <param name="allowSceneActivation"></param>
        /// <param name="loadSceneMode"></param>
        /// <returns></returns>
        static public void LoadScene(string abName, string sceneName, System.Action <object, object> onComplete, System.Action <object, object> onEnd, bool allowSceneActivation = true, LoadSceneMode loadSceneMode = LoadSceneMode.Additive)
        {
            var req = CRequest.Get();

            req.assetName       = sceneName;
            req.assetType       = LoaderType.Typeof_ABScene;
            req.assetBundleName = abName;
            req.OnComplete      = onComplete;
            req.OnEnd           = onEnd;
            // if (CacheManager.GetSceneBundle(sceneName) == null) //没有加载场景
            LoadSceneAsset(req, allowSceneActivation, loadSceneMode);
            // else
            // {
            //     DispatchReqAssetOperation(req, false);
            // }
        }
Exemplo n.º 21
0
        /// <summary>
        /// 目标引用减一
        /// </summary>
        /// <param name="hashcode"></param>
        /// <returns></returns>
        public static string OverrideRequestUrlByCrc(CRequest req)
        {
            string url    = req.url;
            ABInfo abInfo = ManifestManager.GetABInfo(req.key);

            if (abInfo != null)
            {
                bool appCrc = HugulaSetting.instance != null ? HugulaSetting.instance.appendCrcToFile : false;
                if (abInfo.crc32 > 0 && appCrc)
                {
                    url = CUtils.InsertAssetBundleName(url, "_" + abInfo.crc32.ToString());
                }
            }

            return(url);
        }
Exemplo n.º 22
0
        /// <summary>
        /// 排队或者加载
        /// </summary>
        /// <param name="req">Req.</param>
        static void QueueOrLoad(CRequest req)
        {
#if HUGULA_LOADER_DEBUG
            Debug.LogFormat("  0.2 <color=#15A0A1>QueueOrLoad Request(assetName={0}, url={1},isNormal={2},isShared={3})</color>", req.assetName, req.url, req.isNormal, req.isShared);
#endif
            if (req.isNormal)
            {
                realyLoadingQueue.Enqueue(req);
            }
            else
            {
                CCar car = GetCCar();
                freeLoader.Add(car);
                car.BeginLoad(req);
            }
        }
Exemplo n.º 23
0
        /// <summary>
        /// 获取key URL
        /// </summary>
        public static string GetUDKeyURL(CRequest req)
        {
            string url   = string.Empty;
            var    uris  = req.uris;
            int    index = 0;

            if (uris != null && uris.count > index && index >= 0)
            {
                url = CUtils.PathCombine(uris[index], req.relativeUrl);
            }
            else
            {
                url = req.relativeUrl;
            }
            return(url);
        }
Exemplo n.º 24
0
        /// <summary>
        /// assetbunlde load complete
        /// </summary>
        /// <param name="loader">loader.</param>
        /// <param name="req">Req.</param>
        static void LoadComplete(CCar loader, CRequest creq)
        {
#if HUGULA_LOADER_DEBUG
            Debug.LogFormat(" 1.3 <color=#15C1B2>CResLoader.LoadComplete Request(assetName={0}, hash={1},isShared={2})</color>", creq.assetName, creq.keyHashCode, creq.isShared);
#endif
            downloadings.Remove(creq.udKey);
            CallbackAsyncList(creq);
            if (!creq.isShared || !creq.isNormal) //共享和非普通都不计数
            {
                currentLoaded++;
            }
            if (!creq.isShared && creq.isAssetBundle && _instance != null && _instance.OnAssetBundleComplete != null)
            {
                _instance.OnAssetBundleComplete(creq);
            }
        }
Exemplo n.º 25
0
        public new bool Update()
        {
            if (m_Request != null)
            {
                CRequest.SetProgress(request, m_Request.progress);
                if (!allowSceneActivation && LoaderType.Typeof_ABScene.Equals(request.assetType) && m_Request.progress >= 0.9f)//加载场景的时候如果allowSceneActivation = false 只能通过progress判断完成
                {
                    return(false);
                }
                else
                {
                    return(!m_Request.isDone);
                }
            }

            string assetName       = request.assetName;
            string assetBundleName = request.assetBundleName;

            if (LoaderType.Typeof_ABScene.Equals(request.assetType)) //加载场景
            {
                var levelPaths = UnityEditor.AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, assetName);

                if (levelPaths.Length == 0)
                {
                    CRequest.SetError(request, string.Format("There is no scene with name \"" + assetName + "\" in " + assetBundleName));
                    Debug.LogError(request.error);
                }
                else
                {
                    LoadSceneParameters loadSceneParameters = new LoadSceneParameters();
                    loadSceneParameters.loadSceneMode = loadSceneMode;
                    m_Request = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(levelPaths[0], loadSceneParameters);
                    m_Request.allowSceneActivation = allowSceneActivation;
                    CRequest.SetData(request, m_Request);
                    CRequest.SetProgress(request, m_Request.progress);
                    CacheManager.AddScene(request.assetName, request.assetBundleName);//缓存场景
                }
            }
            else //加载资源
            {
                StartSync();
                m_isDone = true;//标记完成
                return(false);
            }

            return(false);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Adds the source cache data from WW.
        /// </summary>
        /// <param name="www">Www.</param>
        /// <param name="req">Req.</param>
        internal static bool AddSourceCacheDataFromWWW(WWW www, CRequest req)
        {
            object data = null;
            var    ab   = www.assetBundle;

            req.isAssetBundle = false;

            if (ab != null)
            {
                data = ab;
                req.isAssetBundle = true;
                CacheData cacheData = new CacheData(data, null, req.key);                 //缓存
                CacheManager.AddCache(cacheData);
                cacheData.allDependencies = req.allDependencies;
                cacheData.assetBundle     = ab;
            }
            else if (Typeof_String.Equals(req.assetType))
            {
                req.data = www.text;
            }
            else if (Typeof_AudioClip.Equals(req.assetType))
            {
                req.data = www.audioClip;
            }
            else if (Typeof_Texture2D.Equals(req.assetType))
            {
                if (req.assetName.Equals("textureNonReadable"))
                {
                    req.data = www.textureNonReadable;
                }
                else
                {
                    req.data = www.texture;
                }
            }

            if (Typeof_Bytes.Equals(req.assetType))
            {
                req.data          = www.bytes;
                req.isAssetBundle = false;
            }

            req.uris.OnWWWComplete(req, www.bytes);

            www.Dispose();
            return(req.isAssetBundle);
        }
Exemplo n.º 27
0
        static protected void LoadAssetInternalSimulation(CRequest req)
        {
            ResourcesLoadOperation op = null;

            if (LoaderType.Typeof_ABScene.Equals(req.assetType))
            {
                op = OperationPools <LoadLevelOperationSimulation> .Get();
            }
            else
            {
                op = OperationPools <LoadAssetOperationSimulation> .Get();
            }

            op.SetRequest(req);
            inProgressOperations.Add(op);
            op.Start();
        }
Exemplo n.º 28
0
        /// <summary>
        /// load asset from cache
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        static bool LoadAssetFromCache(CRequest req)
        {
            var cache = CacheManager.TryGetCache(req.keyHashCode);

            if (cache != null)
            {
                var asset = cache.GetAsset(req.udAssetKey);
                if (asset != null)
                {
                    req.data = asset;
                    // Debug.LogFormat("LoadAssetFromCache Req(assetBundleName={0},assetName={1},data={2}); frame={3}", req.assetBundleName, req.assetName, asset, Time.frameCount);
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 29
0
 internal static bool AddSourceCacheDataFromWWW(AssetBundle ab, CRequest req)
 {
     if (ab)
     {
         req.isAssetBundle = true;
         CacheData cacheData = new CacheData(ab, null, req.key); //缓存
         CacheManager.AddCache(cacheData);
         cacheData.allDependencies = req.allDependencies;
         cacheData.assetBundle     = ab;
         return(req.isAssetBundle);
     }
     else
     {
         req.isAssetBundle = false;
         return(false);
     }
 }
Exemplo n.º 30
0
        /// <summary>
        /// append request to  assetCallBackList
        /// </summary>
        /// <param name="req">Req.</param>
        protected static void AddReqToAssetCallBackList(CRequest req)
        {
            string          key  = req.udAssetKey;
            List <CRequest> list = null;

            if (assetCallBackList.TryGetValue(key, out list))  //回调列表
            {
                list.Add(req);
            }
            else
            {
                list = ListPool <CRequest> .Get();

                assetCallBackList.Add(key, list);
                loadingAssetBundleQueue.Add(req);
            }
        }
Exemplo n.º 31
0
        static public void LoadAsset(CRequest req)
        {
            string relativeUrl = ManifestManager.RemapVariantName(req.vUrl);

            req.vUrl = relativeUrl;

            //check asset cache
            if (CheckAssetIsLoaded(req))
            {
#if HUGULA_LOADER_DEBUG
                HugulaDebug.FilterLogFormat(req.key, "<color=#15A0A1>2.0.0 LoadAssetFromCache Request(url={0},assetname={1},dependencies.count={3})keyHashCode{2}, frameCount{4}</color>", req.url, req.assetName, req.keyHashCode, req.dependencies == null ? 0 : req.dependencies.Length, Time.frameCount);
#endif
                return;
            }
            waitRequest.Enqueue(req);  //等待

            LoadingQueue();
        }
Exemplo n.º 32
0
        /// <summary>
        /// check load from cache
        /// </summary>
        /// <param name="req"></param>
        static bool CheckLoadAssetAsync(CRequest req)
        {
#if UNITY_EDITOR
            if (SimulateAssetBundleInEditor && CacheManager.SetRequestDataFromPrefab(req))
            {
                loadingAssetQueue.Add(req);
                return(true);
            }
#endif

            ABDelayUnloadManager.CheckRemove(req.keyHashCode);
            if (CacheManager.Contains(req.keyHashCode))
            {
                AddReqToAssetCallBackList(req);
                return(true);
            }
            return(false);
        }
Exemplo n.º 33
0
        /// <summary>
        /// 以 webreuest 方式加载网络非ab资源
        /// </summary>
        /// <param name="req"></param>
        /// <param name="coroutine"></param>
        /// <returns></returns>
        static public HttpLoadOperation HttpRequest(CRequest req, bool coroutine = false)
        {
            WebRequestOperation op = null;

            if (coroutine)
            {
                op = new WebRequestOperation();
                req.assetOperation = op;
            }
            else
            {
                op = WebRequestOperation.Get();
            }
            op.SetRequest(req);
            inProgressOperations.Add(op);
            op.BeginDownload();
            return(op);
        }
Exemplo n.º 34
0
 internal string OnOverrideUrl(CRequest req)
 {
     Func<CRequest, string> act = null;
     if (onOverrideUrls != null && onOverrideUrls.TryGetValue(req.index, out act))
     {
         return act(req);
     }
     return req.url;
 }
Exemplo n.º 35
0
 /// <summary>
 /// 设置req index处的uri
 /// </summary>
 /// <param name="req"></param>
 /// <param name="index"></param>
 /// <returns></returns>
 public bool SetNextUri(CRequest req)
 {
     int index = req.index + 1;
     if (index >= count) index = 0;
     string uri = GetUri(index);
     if (!string.IsNullOrEmpty(uri))
     {
         req.index = index;
         req.uri = uri;
         return true;
     }
     return false;
 }
Exemplo n.º 36
0
 public bool CheckUriCrc(CRequest req)
 {
     Func<CRequest, bool> act = null;
     if (onCrcChecks != null && onCrcChecks.TryGetValue(req.index, out act))
     {
         return act(req);
     }
     return true;
 }
Exemplo n.º 37
0
        /// <summary>
        /// 判断所有依赖项目是否加载完成
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public static bool CheckDependenciesComplete(CRequest req)
        {
            if (req.allDependencies == null || req.allDependencies.Length == 0) return true;

            int[] denps = req.allDependencies;

            for (int i = 0; i < denps.Length; i++)
            {
                if (!caches.ContainsKey(denps[i]))
                    return false;
            }

            return true;
        }
Exemplo n.º 38
0
        /// <summary>
        /// 从缓存设置数据
        /// </summary>
        /// <param name="req"></param>
        public static bool SetRequestDataFromCache(CRequest req)
        {
            bool re = false;
            int keyhash = req.keyHashCode;
            CacheData cachedata = GetCache(keyhash);

            if (cachedata != null)
            {
                AssetBundle abundle = cachedata.assetBundle;
                System.Type assetType = req.assetType;
                if (assetType == null) assetType = Typeof_Object;
                if (req.isShared) //共享的
                {
                    req.data = abundle;
                    re = true;
                }
                else if (Typeof_AssetBundle.Equals(assetType))
                {
                    req.data = cachedata.assetBundle;
                    re = true;
                }
                else if (Typeof_ABScene.Equals(assetType))
                {
            #if UNITY_5_0 || UNITY_5_1 || UNITY_5_2
                    if (req.isAdditive)
                        req.assetBundleRequest = Application.LoadLevelAdditiveAsync(req.assetName);
                    else
                        req.assetBundleRequest = Application.LoadLevelAsync(req.assetName);
            #else
                    req.assetBundleRequest = SceneManager.LoadSceneAsync(req.assetName, req.isAdditive ? LoadSceneMode.Additive : LoadSceneMode.Single);
            #endif
                    re = true;
                }
                else
                {
                    if (abundle == null)
                    {
            #if UNITY_EDITOR
                        Debug.LogWarningFormat("SetRequestDataFromCache Assetbundle is null request(url={0},assetName={1},assetType={2})  ", req.url, req.assetName, req.assetType);
            #endif
                    }
                    else if (req.async)
                        req.assetBundleRequest = abundle.LoadAssetAsync(req.assetName, assetType);
                    else
                    {
                        req.data = abundle.LoadAsset(req.assetName, assetType);
                    }
                    re = true;
                }
            }

            return re;
        }
Exemplo n.º 39
0
 public static void SaveWWWFileToPersistent(CRequest req, Array www)
 {
     string saveName = req.assetBundleName;
     FileHelper.SavePersistentFile(www, saveName);
 }
Exemplo n.º 40
0
 private void OnEndHandler(CRequest req)
 {
     if (onEndFn != null)
         onEndFn.call(req);
 }
Exemplo n.º 41
0
 private void OnCompHandler(CRequest req)
 {
     if (onCompleteFn != null)
         onCompleteFn.call(req);
 }
Exemplo n.º 42
0
 public static void Release(CRequest toRelease)
 {
     if(toRelease is LRequest)
         pool.Release((LRequest)toRelease);
 }
Exemplo n.º 43
0
        /// <summary>
        /// 判断异步加载Asset
        /// </summary>
        /// <param name="req"></param>
        static bool CheckLoadAssetAsync(CRequest req)
        {
            if (CacheManager.SetRequestDataFromCache(req))
            {
                if (req.assetBundleRequest != null)
                {
                    CacheManager.AddLock(req.keyHashCode);
                    loadingAssetQueue.Add(req);
                    //Debug.LogFormat("loadingAsyncQueue.Add key:{0} ", req.key);
                }
                else
                {
                    //Debug.LogFormat("req.assetBundleRequest != null  key:{0}", req.key);
                    LoadAssetComplate(req);
                }
                return true;
            }

            return false;
        }
Exemplo n.º 44
0
        /// <summary>
        /// 根据组策略校验request.url的crc值。
        /// 文件不存在或者校验失败返回false
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public static bool CheckUriCrc(CRequest req)
        {
            uint crc = 0;
            bool check = CheckLocalFileCrc(req.url, out crc);
            if (!check)
            {
                var re = req.uris.SetNextUri(req); //CUtils.SetRequestUri(req, 1);
            #if HUGULA_LOADER_DEBUG
                Debug.LogFormat("<color=red>CrcCheck.CheckUriCrc Req(assetname={0},url={1}) crc={2},CheckFileCrc=false,SetNextUri={3}</color>", req.assetName, req.url, crc, re);
            #endif
                return re;
            }

            return true;
        }
Exemplo n.º 45
0
 internal void OnWWWComplete(CRequest req, WWW www)
 {
     Action<CRequest, Array> act = null;
     if (onWWWCompletes != null && onWWWCompletes.TryGetValue(req.index, out act))
     {
         act(req, www.bytes);
     }
 }
Exemplo n.º 46
0
 static void PushGroup(CRequest req)
 {
     if (currGroupRequests == null) currGroupRequests = currGroupRequestsRef;
     currGroupRequests.Add(req);
 }
Exemplo n.º 47
0
        /// <summary>
        /// 移除引用记录
        /// </summary>
        /// <param name="keyhash"></param>
        static void RemoveReferenceRecord(CRequest creq)
        {
            int keyhash = creq.keyHashCode;

            if (referenceRecord.ContainsKey(keyhash))
            {
                int refc = referenceRecord[keyhash];
                CountMananger.Add(keyhash, refc);//真实引用
                referenceRecord.Remove(keyhash);
            }
        }
Exemplo n.º 48
0
 void L_OnAssetBundleErrFn(CRequest req)
 {
     if (onAssetBundleErrFn != null)
         onAssetBundleErrFn.call (req);
 }
Exemplo n.º 49
0
        /// <summary>
        /// 判断所有依赖项目是否加载完成
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public static bool CheckDependenciesComplete(CRequest req)
        {
            if (req.allDependencies == null || req.allDependencies.Length == 0) return true;

            int[] denps = req.allDependencies;
            CacheData cache = null;

            for (int i = 0; i < denps.Length; i++)
            {
                if (caches.TryGetValue(denps[i], out cache))
                {
                    if (!cache.isAssetLoaded)
                        return false;
                }
                else
                    return false;
            }

            return true;
        }
Exemplo n.º 50
0
 void L_OnAssetBundleComplete(CRequest req)
 {
     if (onAssetBundleCompleteFn != null)
         onAssetBundleCompleteFn.call (req);
 }
Exemplo n.º 51
0
        /// <summary>
        /// Adds the source cache data from WW.
        /// </summary>
        /// <param name="www">Www.</param>
        /// <param name="req">Req.</param>
        internal static bool AddSourceCacheDataFromWWW(WWW www, CRequest req)
        {
            object data = null;
            var ab = www.assetBundle;
            req.isAssetBundle = false;

            if (ab != null) {
                data = ab;
                req.isAssetBundle = true;
                CacheData cacheData = new CacheData (data, null, req.key);//缓存
                CacheManager.AddCache (cacheData);
                cacheData.allDependencies = req.allDependencies;
                cacheData.assetBundle = ab;

            } else if (Typeof_String.Equals (req.assetType)) {
                req.data = www.text;
            }
            else if(Typeof_AudioClip.Equals(req.assetType)) {
                req.data = www.audioClip;
            }else if(Typeof_Texture2D.Equals(req.assetType) ) {
                if (req.assetName.Equals ("textureNonReadable"))
                    req.data = www.textureNonReadable;
                else
                    req.data = www.texture;
            }

            if (Typeof_Bytes.Equals (req.assetType)) {
                req.data = www.bytes;
                req.isAssetBundle = false;
            }

            req.uris.OnWWWComplete (req, www);
            www.Dispose();

            return req.isAssetBundle;
        }
Exemplo n.º 52
0
 void L_onSharedComplete(CRequest req)
 {
     if (onSharedCompleteFn != null)
         onSharedCompleteFn.call(req);
 }
Exemplo n.º 53
0
 static void PopGroup(CRequest req)
 {
     if (currGroupRequests != null)
         currGroupRequests.Remove(req);
 }
Exemplo n.º 54
0
 private void DispatchErrorEvent(CRequest cReq)
 {
     if (OnError != null)
     {
         OnError(this, cReq);
     }
 }
Exemplo n.º 55
0
        static void LoadComplete(CCar loader, CRequest creq)
        {
            //Debug.LogFormat(" <color=green>LoadComplete {0} {1}</color>", creq.key, creq.isShared);
            downloadings.Remove(creq.udKey);

            if (creq.isShared)
            {
                //添加引用计数
                RemoveReferenceRecord(creq);

                //回调
                if (_instance && _instance.OnSharedComplete != null)
                    _instance.OnSharedComplete(creq);

            }
            else
            {
                CallbackAsyncList(creq);
            }
        }
Exemplo n.º 56
0
 void L_onSharedErr(CRequest req)
 {
     if (onSharedErrFn != null)
         onSharedErrFn.call(req);
 }
Exemplo n.º 57
0
 private void DispatchCompleteEvent(CRequest cReq)
 {
     if (OnComplete != null)
     {
         OnComplete(this, cReq);
     }
 }
Exemplo n.º 58
0
        static void LoadError(CCar cloader, CRequest req)
        {
            string oldUdKey = req.udKey;
            downloadings.Remove(oldUdKey);
            req.index++;

            if (req.index < req.maxTimes && CUtils.SetRequestUri(req, req.index))
            {
                //req.priority = req.priority - 10;
                List<CRequest> callbacklist = null;
                if (requestCallBackList.TryGetValue(oldUdKey, out callbacklist))
                {
                    requestCallBackList.Remove(oldUdKey);
                }
                var udkey = req.udKey;
                if (callbacklist == null)
                    callbacklist = new List<CRequest>();

                if (requestCallBackList.ContainsKey(udkey))
                { //if 正在加载
                    var old = requestCallBackList[udkey];

                    CRequest chekReq = null;
                    for (int i = 0; i < callbacklist.Count; i++)
                    {
                        chekReq = callbacklist[i];
                        if (!old.Contains(chekReq))
                            old.Add(chekReq);
                    }
                }
                else
                {
                    if (!callbacklist.Contains(req))
                        callbacklist.Add(req);
                    requestCallBackList[udkey] = callbacklist;
                    realyLoadingQueue.Enqueue(req);
                }

            }
            else
            {
                CallbackError(req);
                BeginQueue();
                CheckAllComplete();
            }
        }
Exemplo n.º 59
0
        /// <summary>
        /// 从缓存设置数据
        /// </summary>
        /// <param name="req"></param>
        public static bool SetRequestDataFromCache(CRequest req)
        {
            bool re = false;
            int keyhash = req.keyHashCode;
            CacheData cachedata = GetCache(keyhash);
            if (cachedata != null)
            {
                AssetBundle abundle = cachedata.assetBundle;
                System.Type assetType = LuaHelper.GetType(req.assetType);
                if (assetType == null) assetType = typeof(UnityEngine.Object);

                if (req.isShared) //共享的
                {
                    req.data = abundle;
                    re = true;
                }
                else if (assetType.Equals(Typeof_String))
                {

                    var str = string.Empty;
                    if (cachedata.www is byte[])
                    {
                        str = LuaHelper.GetUTF8String((byte[])cachedata.www);
                    }
                    req.data = new string[] { str };

                    req.clearCacheOnComplete = true;
                    re = true;
                }
                else if (assetType.Equals(Typeof_Bytes))
                {
                    req.data = cachedata.www;
                    req.clearCacheOnComplete = true;
                    re = true;
                }
                else if (assetType.Equals(Typeof_AssetBundle))
                {
                    req.data = cachedata.assetBundle;
                    re = true;
                }
                else
                {
                    if (req.async)
                        req.assetBundleRequest = abundle.LoadAssetAsync(req.assetName, assetType);
                    else
                    {
                        req.data = abundle.LoadAsset(req.assetName, assetType);
                        //Debug.LogFormat("<color=yellow>set data {0},{1},{2},{3},{4}</color>",req.key,req.data, req.assetName, req.assetType, assetType);
                    }
                    re = true;
                }
            }

            return re;
        }
Exemplo n.º 60
0
        /// <summary>
        /// 清理没有ab的缓存
        /// </summary>
        /// <param name="req"></param>
        static void ClearNoABCache(CRequest req)
        {
            if (req.assetBundleRequest != null) CacheManager.RemoveLock(req.keyHashCode);

            if (req.clearCacheOnComplete)
            {
            #if UNITY_EDITOR
                Debug.LogFormat("<color=#8cacbc>{0} ClearCache</color>", req.key);
            #endif
                CacheManager.ClearCache(req.keyHashCode);
            }
        }