static public int get_count(IntPtr l) { try { Hugula.Loader.UriGroup self = (Hugula.Loader.UriGroup)checkSelf(l); pushValue(l, true); pushValue(l, self.count); return(2); } catch (Exception e) { return(error(l, e)); } }
static public int Clear(IntPtr l) { try { Hugula.Loader.UriGroup self = (Hugula.Loader.UriGroup)checkSelf(l); self.Clear(); pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
static public int constructor(IntPtr l) { try { Hugula.Loader.UriGroup o; o = new Hugula.Loader.UriGroup(); pushValue(l, true); pushValue(l, o); return(2); } catch (Exception e) { return(error(l, e)); } }
private void FinishDownload() { if (m_webrequest == null) { error = string.Format("webrequest is null ,key={0},url={1} ", cRequest.key, cRequest.url); return; } #if UNITY_2017 if (m_webrequest.isNetworkError) #else if (m_webrequest.isError) #endif { error = string.Format("url:{0},erro:{1}", cRequest.url, m_webrequest.error); Debug.LogErrorFormat(error); return; } if (m_webrequest.responseCode != 200) { error = string.Format("response error code = {0},url={1}", m_webrequest.responseCode, cRequest.url); // m_webrequest.error; Debug.LogError(error); return; } var type = cRequest.assetType; if (CacheManager.Typeof_AudioClip.Equals(type)) { m_Data = DownloadHandlerAudioClip.GetContent(m_webrequest); } else if (CacheManager.Typeof_Texture2D.Equals(type)) { m_Data = DownloadHandlerTexture.GetContent(m_webrequest); } else if (CacheManager.Typeof_Bytes.Equals(type)) { m_Data = m_webrequest.downloadHandler.data; } else { m_Data = DownloadHandlerBuffer.GetContent(m_webrequest); } UriGroup.CheckWWWComplete(cRequest, m_webrequest); cRequest.data = m_Data; m_webrequest.Dispose(); m_webrequest = null; m_asyncOperation = null; }
/// <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); }
static public int CheckUriCrc(IntPtr l) { try { Hugula.Loader.UriGroup self = (Hugula.Loader.UriGroup)checkSelf(l); Hugula.Loader.CRequest a1; checkType(l, 2, out a1); var ret = self.CheckUriCrc(a1); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } }
static public int GetUri(IntPtr l) { try { Hugula.Loader.UriGroup self = (Hugula.Loader.UriGroup)checkSelf(l); System.Int32 a1; checkType(l, 2, out a1); var ret = self.GetUri(a1); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } }
/// <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) { var ab = www.assetBundle; req.isAssetBundle = false; if (ab != null) { AddSourceCacheDataFromWWW(ab, req); } 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; } UriGroup.CheckWWWComplete(req, www); www.Dispose(); return(req.isAssetBundle); }
/// <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); } }
static public int Add(IntPtr l) { try { int argc = LuaDLL.lua_gettop(l); if (argc == 2) { Hugula.Loader.UriGroup self = (Hugula.Loader.UriGroup)checkSelf(l); System.String a1; checkType(l, 2, out a1); var ret = self.Add(a1); pushValue(l, true); pushValue(l, ret); return(2); } else if (argc == 3) { Hugula.Loader.UriGroup self = (Hugula.Loader.UriGroup)checkSelf(l); System.String a1; checkType(l, 2, out a1); System.Boolean a2; checkType(l, 3, out a2); self.Add(a1, a2); pushValue(l, true); return(1); } else if (argc == 4) { Hugula.Loader.UriGroup self = (Hugula.Loader.UriGroup)checkSelf(l); System.String a1; checkType(l, 2, out a1); System.Action <Hugula.Loader.CRequest, System.Array> a2; LuaDelegation.checkDelegate(l, 3, out a2); System.Func <Hugula.Loader.CRequest, System.Boolean> a3; LuaDelegation.checkDelegate(l, 4, out a3); self.Add(a1, a2, a3); pushValue(l, true); return(1); } else if (matchType(l, argc, 2, typeof(string), typeof(System.Action <Hugula.Loader.CRequest, System.Array>), typeof(System.Func <Hugula.Loader.CRequest, System.Boolean>), typeof(System.Func <Hugula.Loader.CRequest, System.String>))) { Hugula.Loader.UriGroup self = (Hugula.Loader.UriGroup)checkSelf(l); System.String a1; checkType(l, 2, out a1); System.Action <Hugula.Loader.CRequest, System.Array> a2; LuaDelegation.checkDelegate(l, 3, out a2); System.Func <Hugula.Loader.CRequest, System.Boolean> a3; LuaDelegation.checkDelegate(l, 4, out a3); System.Func <Hugula.Loader.CRequest, System.String> a4; LuaDelegation.checkDelegate(l, 5, out a4); self.Add(a1, a2, a3, a4); pushValue(l, true); return(1); } else if (matchType(l, argc, 2, typeof(string), typeof(bool), typeof(bool), typeof(bool))) { Hugula.Loader.UriGroup self = (Hugula.Loader.UriGroup)checkSelf(l); System.String a1; checkType(l, 2, out a1); System.Boolean a2; checkType(l, 3, out a2); System.Boolean a3; checkType(l, 4, out a3); System.Boolean a4; checkType(l, 5, out a4); self.Add(a1, a2, a3, a4); pushValue(l, true); return(1); } pushValue(l, false); LuaDLL.lua_pushstring(l, "No matched override function to call"); return(2); } catch (Exception e) { return(error(l, e)); } }
/// <summary> /// finish assetbundle /// </summary> /// <param name="operation"></param> static void ProcessFinishedBundleOperation(AssetBundleDownloadOperation operation) { #if HUGULA_PROFILER_DEBUG Profiler.BeginSample(string.Format("ResourcesLoader.ProcessFinishedBundleOperation CRequest({0},shared={1})", operation.cRequest.assetName, operation.cRequest.isShared)); #endif var req = operation.cRequest; bool isError = operation.assetBundle == null; var ab = operation.assetBundle; AssetBundleDownloadOperation download = operation; if (isError && UriGroup.CheckAndSetNextUriGroup(req)) { #if HUGULA_LOADER_DEBUG HugulaDebug.FilterLogFormat(req.key, "<color=#10f010>1.9 ProcessFinishedBundleOperation AssetBundle re Loaded Request(url={0},assetname={1},dependencies.count={3},keyHashCode{2}),isError={4} frameCount{5}</color>", req.url, req.assetName, req.keyHashCode, req.dependencies == null ? 0 : req.dependencies.Length, isError, Time.frameCount); #endif //loop load a assetbundle maybe cause a crash : signal 6 (SIGABRT), code -6 (?), fault addr -------- inProgressBundleOperations.Add(download); download.Reset(); download.SetRequest(req); download.BeginDownload(); //retry } else { if (!isError) { CacheManager.AddSourceCacheDataFromWWW(ab, req); } else { #if UNITY_EDITOR Debug.LogWarning(operation.error); #endif CacheManager.AddErrorSourceCacheDataFromReq(req); } #if HUGULA_LOADER_DEBUG HugulaDebug.FilterLogFormat(req.key, "<color=#10f010>1.9 ProcessFinishedBundleOperation AssetBundle Loaded Request(url={0},assetname={1},dependencies.count={3},keyHashCode{2}),isError={4} frameCount{5}</color>", req.url, req.assetName, req.keyHashCode, req.dependencies == null ? 0 : req.dependencies.Length, isError, Time.frameCount); #endif //begin load asset InsertAssetBundleLoadAssetOperation(download); downloadingBundles.Remove(req.key); download.ReleaseToPool(); if (isError) { CallOnAssetBundleErr(req); } else { CallOnAssetBundleComplete(req, ab); } if (req.isShared) { req.ReleaseToPool(); } } #if HUGULA_PROFILER_DEBUG Profiler.EndSample(); #endif }
/// <summary> /// 以 WWW 方式加载网络非ab资源 /// </summary> /// <param name="url"></param> /// <param name="head"></param> /// <param name="type"></param> /// <param name="onComplete"></param> /// <param name="onEnd"></param> static public void WWWRequest(string url, object head, System.Type type, System.Action <CRequest> onComplete, System.Action <CRequest> onEnd, UriGroup uris) { var req = CRequest.Get(); req.relativeUrl = url; req.head = head; req.assetType = type; req.OnComplete = onComplete; req.OnEnd = onEnd; req.uris = uris; WWWRequest(req); }
/// <summary> /// finish asset or http request /// </summary> /// <param name="operation"></param> internal static void ProcessFinishedOperation(ResourcesLoadOperation operation) { var req = operation.cRequest; bool isError = false; AssetBundleLoadAssetOperation assetLoad = operation as AssetBundleLoadAssetOperation; HttpLoadOperation httpLoad; if (assetLoad != null) { loadingTasks.Remove(req); isError = assetLoad.error != null; SetCacheAsset(req); // set asset cache DispatchAssetBundleLoadAssetOperation(req, isError); assetLoad.ReleaseToPool(); //relase AssetBundleLoadAssetOperation //等两帧再CheckAllComplete allCompleteCheckCount = 0.1f; //CheckAllComplete();//check all complete } else if ((httpLoad = operation as HttpLoadOperation) != null) { isError = !string.IsNullOrEmpty(httpLoad.error); req.error = httpLoad.error; if (isError && CUtils.IsResolveHostError(httpLoad.error) && !CUtils.IsHttps(req.url))// http dns { httpLoad.error = string.Format("dns resolve error url={0} ", req.url); var httpDnsOp = HttpDnsResolve.Get(); httpDnsOp.SetRequest(req); httpDnsOp.SetOriginalOperation(httpLoad); inProgressOperations.Add(httpDnsOp); } else if (isError && UriGroup.CheckAndSetNextUriGroup(req)) //多域名 { #if HUGULA_LOADER_DEBUG HugulaDebug.FilterLogFormat(req.key, "<color=#10f010>1.9 ProcessFinishedOperation re Loaded Request(url={0},assetname={1},dependencies.count={3},keyHashCode{2}),isError={4} frameCount{5}</color>", req.url, req.assetName, req.keyHashCode, req.dependencies == null ? 0 : req.dependencies.Length, isError, Time.frameCount); #endif // Debug.LogFormat(" re try {0};",req.url); inProgressOperations.Add(httpLoad); httpLoad.Reset(); httpLoad.SetRequest(req); httpLoad.BeginDownload(); //retry } else { httpLoad.ReleaseToPool(); if (isError) { req.DispatchEnd(); } else { req.DispatchComplete(); } if (req.group != null) { req.group.Complete(req, isError); } req.ReleaseToPool(); } } else { operation.ReleaseToPool(); } }
public virtual void Dispose() { this._url = string.Empty; this._relativeUrl = string.Empty; this._key = string.Empty; this._uri = string.Empty; this._udKey = string.Empty; this.priority = 0; this.index = 0; this._keyHashCode = 0; this._uris = null; this.data = null; this.head = null; this.userData = null; _assetBundleName = string.Empty; _assetName = string.Empty; assetType = null;//string.Empty; async = true; pool = false; isAdditive = false; isShared = false; isNormal = true; isAssetBundle = true; isLoadFromCacheOrDownload = false; this.assetBundleRequest = null; this.allDependencies = null; this.OnComplete = null; this.OnEnd = null; }
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 (!UriGroup.CheckRequestCurrentIndexCrc(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); } 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) { LoadAssetBundle(req); if (group != null) { PushGroup(req, group); } } else { queue.Push(req); totalLoading++; if (group != null) { PushGroup(req, group); } } return(true); } }