Пример #1
0
 static public int set_onGroupComplate(IntPtr l)
 {
     try {
         Hugula.Loader.GroupRequestRecord self = (Hugula.Loader.GroupRequestRecord)checkSelf(l);
         System.Action <System.Object>    v;
         int op = LuaDelegation.checkDelegate(l, 2, out v);
         if (op == 0)
         {
             self.onGroupComplate = v;
         }
         else if (op == 1)
         {
             self.onGroupComplate += v;
         }
         else if (op == 2)
         {
             self.onGroupComplate -= v;
         }
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Пример #2
0
 static public int set_onGroupProgress(IntPtr l)
 {
     try {
         Hugula.Loader.GroupRequestRecord self = (Hugula.Loader.GroupRequestRecord)checkSelf(l);
         System.Action <Hugula.Loader.LoadingEventArg> v;
         int op = LuaDelegation.checkDelegate(l, 2, out v);
         if (op == 0)
         {
             self.onGroupProgress = v;
         }
         else if (op == 1)
         {
             self.onGroupProgress += v;
         }
         else if (op == 2)
         {
             self.onGroupProgress -= v;
         }
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Пример #3
0
 static void PushGroup(CRequest req, GroupRequestRecord group)
 {
     currGroupRequestsRef[req] = group;
     group.Add(req);
     if (!allGroupRequestRecord.Contains(group))
     {
         allGroupRequestRecord.Add(group);
     }
 }
Пример #4
0
 static public int Progress(IntPtr l)
 {
     try {
         Hugula.Loader.GroupRequestRecord self = (Hugula.Loader.GroupRequestRecord)checkSelf(l);
         self.Progress();
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Пример #5
0
 static public int get_Count(IntPtr l)
 {
     try {
         Hugula.Loader.GroupRequestRecord self = (Hugula.Loader.GroupRequestRecord)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.Count);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Пример #6
0
 static public int constructor(IntPtr l)
 {
     try {
         Hugula.Loader.GroupRequestRecord o;
         o = new Hugula.Loader.GroupRequestRecord();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Пример #7
0
 static public int Complete(IntPtr l)
 {
     try {
         Hugula.Loader.GroupRequestRecord self = (Hugula.Loader.GroupRequestRecord)checkSelf(l);
         Hugula.Loader.CRequest           a1;
         checkType(l, 2, out a1);
         self.Complete(a1);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Пример #8
0
 static public int set_Count(IntPtr l)
 {
     try {
         Hugula.Loader.GroupRequestRecord self = (Hugula.Loader.GroupRequestRecord)checkSelf(l);
         int v;
         checkType(l, 2, out v);
         self.Count = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Пример #9
0
        /// <summary>
        /// 将多个资源加载到本地并缓存。
        /// </summary>
        /// <param name="req"></param>
        public void LoadReq(IList <CRequest> req, System.Action <object> onGroup, System.Action <LoadingEventArg> onProgress) //onAllCompleteHandle onAllCompletehandle=null,onProgressHandle onProgresshandle=null
        {
            GroupRequestRecord groupFn = null;

            if (onGroup != null)
            {
                groupFn = GroupRequestRecord.Get();
                groupFn.onGroupComplate = onGroup;
                groupFn.onGroupProgress = onProgress;
            }
            for (int i = 0; i < req.Count; i++)
            {
                AddReqToQueue(req[i], groupFn);
            }

            BeginQueue();
        }
Пример #10
0
        /// <summary>
        /// 加载luatable里面的request
        /// </summary>
        /// <param name="reqs"></param>
        public void LoadLuaTable(LuaTable reqs, System.Action <object> groupCompleteFn, System.Action <LoadingEventArg> groupProgressFn)
        {
            GroupRequestRecord re = null;

            if (groupCompleteFn != null)
            {
                re = GroupRequestRecord.Get();
                re.onGroupComplate = groupCompleteFn;
                re.onGroupProgress = groupProgressFn;
            }

            foreach (var pair in reqs)
            {
                AddReqToQueue((CRequest)pair.value, re);
            }

            BeginQueue();
        }
Пример #11
0
        /// <summary>
        /// append request to queue.
        /// </summary>
        /// <param name="req">Req.</param>
        /// <param name="group">Group.</param>
        protected static bool AddReqToQueue(CRequest req, GroupRequestRecord group = null)
        {
            if (req == null)
            {
                return(false);
            }
            string key = req.udKey; //the udkey never change 第一个URI和relativeUrl评级而成。

            UriGroup.CheckRequestUrlIsAssetbundle(req);

            if (!req.isShared && group != null)
            {
                PushGroup(req, group);
            }

            if (CheckLoadAssetAsync(req))  //已经下载
            {
                return(false);

#if UNITY_EDITOR
            }
            else if (SimulateAssetBundleInEditor && req.isAssetBundle)   //
            {
                CallbackError(req);
                return(false);
#endif
            }
            else if (!UriGroup.CheckRequestCurrentIndexCrc(req))    //如果校验失败
            {
#if HUGULA_LOADER_DEBUG
                Debug.LogFormat(" 0.0 <color=#ff0000>CheckCrcUri0Exists==false Req(assetname={0},url={1})  </color>", req.assetName, req.url);
#endif
                CallbackError(req);
                return(false);
            }

            List <CRequest> list = null;
            if (requestCallBackList.TryGetValue(key, out list))  //.ContainsKey(key)) //回调列表
            {
#if HUGULA_LOADER_DEBUG
                Debug.LogFormat(" 0.1 <color=#15A0A1>requestCallBackList.ContainsKey Req(assetname={0},url={1})  </color>", req.assetName, req.url);
#endif
                list.Add(req);
                return(true);
            }
            else
            {
                var listreqs = ListPool <CRequest> .Get();

                requestCallBackList.Add(key, listreqs);
                listreqs.Add(req);

                if (queue.Count == 0 && currentLoading == 0 && loadingAssetBundleQueue.Count == 0)
                {
                    totalLoading  = 0;
                    currentLoaded = 0;
                }
#if HUGULA_LOADER_DEBUG
                Debug.LogFormat(" 0.1 <color=#15A0A1>LoadAssetBundle  Req(assetname={0},url={1} isShared={2},isNormal={3})  </color>", req.assetName, req.url, req.isShared, req.isNormal);
#endif

                if (req.isShared)
                {
                    QueueOrLoad(req);  //  LoadAssetBundle(req);// QueueOrLoad (req);//realyLoadingQueue.Enqueue (req);
                }
                else if (!req.isNormal)
                {
                    LoadAssetBundle(req);
                }
                else
                {
                    queue.Push(req);
                    totalLoading++;
                }

                return(true);
            }
        }
Пример #12
0
 /// <summary>
 /// Loads the req.
 /// </summary>
 /// <param name="req">Req.</param>
 /// <param name="group">Group.</param>
 public void LoadReq(CRequest req, GroupRequestRecord group)
 {
     AddReqToQueue(req, group);
     BeginQueue();
 }
Пример #13
0
        // Update is called once per frame
        void Update()
        {
            for (int i = 0; i < freeLoader.Count;)
            {
                CCar load = freeLoader[i];
                if (load.enabled)
                {
                    load.Update();
                }

                if (load.isFree)
                {
                    freeLoader.RemoveAt(i);
                    ReleaseCCar(load);  //放回对象池
                }
                else
                {
                    i++;
                }
            }

            //1 load assetbunlde
            for (int i = 0; i < loaderPool.Count; i++)
            {
                CCar load = loaderPool[i];
                if (load.isFree && realyLoadingQueue.Count > 0)
                {
                    var req = realyLoadingQueue.Dequeue();
                    if (CheckLoadedAssetBundle(req))
                    {
                        CheckLoadAssetAsync(req);
                    }
                    else if (CheckLoadingAssetBundle(req))
                    {
                        AddReqToQueue(req);
                    }
                    else
                    {
                        downloadings[req.udKey] = load;
                        load.BeginLoad(req);
                    }
                }
                if (load.enabled)
                {
                    load.Update();
                }
            }
#if UNITY_EDITOR
            loadingAssetBundleQueueCount = loadingAssetBundleQueue.Count;
            loadingAssetQueueCount       = loadingAssetQueue.Count;
            DebugInfo = "";
#endif
            //2 wait dependencies set asset
            for (int i = 0; i < loadingAssetBundleQueue.Count;)
            {
                var item = loadingAssetBundleQueue[i];
                if (CacheManager.CheckDependenciesComplete(item))   //判断依赖项目是否加载完成
                {
                    if (CacheManager.SetRequestDataFromCache(item)) //设置缓存数据。
                    {
                        loadingAssetQueue.Add(item);                //加载资源
                    }
                    else
                    {
                        loadedAssetQueue.Enqueue(item);
#if HUGULA_LOADER_DEBUG
                        Debug.LogFormat("<color=red> 2.2 SetRequestDataFromCache false Req(assetname={0},url={1}) frame={2}loadingAssetBundleQueue.Count={3} </color>", item.assetName, item.url, Time.frameCount, loadingAssetBundleQueue.Count);
#endif
                    }
                    // if (item.assetBundleRequest != null)
                    //  CacheManager.AddLock (item.keyHashCode);//异步需要锁定
                    loadingAssetBundleQueue.RemoveAt(i);
#if HUGULA_LOADER_DEBUG
                    Debug.LogFormat(" 2.3 <color=#15C132>DependenciesComplete Req(assetname={0},url={1},async={2}) frameCount{3},loadingAssetBundleQueue.Count={4}</color>", item.assetName, item.url, item.async, Time.frameCount, loadingAssetBundleQueue.Count);
#endif
                }
                else
                {
                    i++;
#if UNITY_EDITOR
                    DebugInfo += string.Format(" -2.3CheckDependenciesComplete Req(assetname={0},url={1}) frameCount{2},loadingAssetBundleQueue.Count={3}</color>", item.assetName, item.url, Time.frameCount, loadingAssetBundleQueue.Count);
#endif
#if HUGULA_LOADER_DEBUG
                    Debug.LogFormat(" -2.3 <color=#15C132>CheckDependenciesComplete Req(assetname={0},url={1}) frameCount{2},loadingAssetBundleQueue.Count={3}</color>", item.assetName, item.url, Time.frameCount, loadingAssetBundleQueue.Count);
#endif
                }
            }

            //3 load asset
            for (int i = 0; i < loadingAssetQueue.Count; i++)
            {
                var item = loadingAssetQueue[i];
#if HUGULA_LOADER_DEBUG
                Debug.LogFormat(" 3.2.-1 <color=#A9C115> Req(assetname={0},url={1}) loadingAssetQueue.Count={2} frameCount{3} </color>", item.assetName, item.url, loadingAssetQueue.Count, Time.frameCount);
#endif
                if (item.assetBundleRequest != null && item.assetBundleRequest.isDone) //如果加载完成
                {
#if HUGULA_LOADER_DEBUG
                    Debug.LogFormat(" 3.2.0 <color=#A9C115>set Req(assetname={0},url={1}).data asnyc Count{2} frameCount{3} </color>", item.assetName, item.url, loadingAssetQueue.Count, Time.frameCount);
#endif
                    if (item.assetBundleRequest is AssetBundleRequest)
                    {
                        if (CacheManager.Typeof_ABAllAssets.Equals(item.assetType))
                        {
                            item.data = ((AssetBundleRequest)item.assetBundleRequest).allAssets;  //赋值
                        }
                        else
                        {
                            item.data = ((AssetBundleRequest)item.assetBundleRequest).asset;  //赋值
                        }
                    }
                    else
                    {
                        item.data = item.assetBundleRequest;
                    }
#if HUGULA_LOADER_DEBUG
                    Debug.LogFormat(" 3.2.1 <color=#A9C115>set Req(assetname={0},url={1} data{2}) end </color>", item.assetName, item.url, item.data);
#endif
                    loadedAssetQueue.Enqueue(item);
                    loadingAssetQueue.RemoveAt(i);
                }
                else if (item.assetBundleRequest == null)   //非异步
                {
                    loadedAssetQueue.Enqueue(item);
                    loadingAssetQueue.RemoveAt(i);
#if HUGULA_LOADER_DEBUG
                    Debug.LogFormat(" 3.2 <color=#A9C115>set Req(assetname={0},url={1}).data Async  Count{2} frameCount{3}</color>", item.assetName, item.url, loadingAssetQueue.Count, Time.frameCount);
#endif
                }
                else
                {
                    i++;
                }
            }

            //4 complete asset
            while (loadedAssetQueue.Count > 0)
            {
                LoadAssetComplate(loadedAssetQueue.Dequeue());
            }

            //group check
            for (int i = 0; i < allGroupRequestRecord.Count;)
            {
                var group = allGroupRequestRecord[i];
                group.Progress();
                if (group.Count > 0)
                {
                    i++;
                }
                else
                {
                    var act = group.onGroupComplate;
                    GroupRequestRecord.Release(group);
                    allGroupRequestRecord.RemoveAt(i);
                    if (act != null)
                    {
                        act(group);
                    }
                }
            }
        }
Пример #14
0
 public static void Release(GroupRequestRecord toRelease)
 {
     objectPool.Release(toRelease);
 }
Пример #15
0
 private static void m_ActionOnRelease(GroupRequestRecord re)
 {
     re.Count           = 0;
     re.onGroupComplate = null;
     re.onGroupProgress = null;
 }
Пример #16
0
        protected static bool AddReqToQueue(CRequest req, GroupRequestRecord group = null)
        {
            if (req == null)
            {
                return(false);
            }

            if (!req.uris.CheckUriCrc(req))            //(!CrcCheck.CheckUriCrc(req)) //如果校验失败
            {
#if HUGULA_LOADER_DEBUG
                Debug.LogFormat(" 0. <color=yellow>CheckCrcUri0Exists==false Req(assetname={0},url={1})  </color>", req.assetName, req.url);
#endif
                CallbackError(req);
                return(false);
            }

            string key = req.udKey;       //need re
            if (CheckLoadAssetAsync(req)) //已经下载
            {
                return(false);
            }
            else if (requestCallBackList.ContainsKey(key)) //回调列表
            {
                requestCallBackList[key].Add(req);
                if (!req.isShared)
                {
                    if (group != null)
                    {
                        PushGroup(req, group);
                    }
                }
                return(true);
            }
            else
            {
                var listreqs = ListPool <CRequest> .Get(); //new List<CRequest>();

                requestCallBackList.Add(key, listreqs);
                listreqs.Add(req);

                if (queue.Count == 0 && currentLoading == 0 && loadingAssetBundleQueue.Count == 0)
                {
                    totalLoading  = 0;
                    currentLoaded = 0;
                }

                if (req.isShared)
                {
                    QueueOrLoad(req);                     //realyLoadingQueue.Enqueue (req);
                }
                else if (!req.isNormal)
                {
                    QueueOrLoad(req);
                    if (group != null)
                    {
                        PushGroup(req, group);
                    }
                }
                else
                {
                    queue.Push(req);
                    totalLoading++;
                    if (group != null)
                    {
                        PushGroup(req, group);
                    }
                }
                return(true);
            }
        }