Exemplo n.º 1
0
 public void Cancel()
 {
     onComplete         = null;
     onError            = null;
     onCancel           = null;
     retry              = 0;
     Progress           = 1;
     depencencyRequests = null;
     master             = null;
     isAsyncMode        = true;
 }
Exemplo n.º 2
0
        //是否所有的sameRequest加载完了
        public bool isSameRequestComplete()
        {
            if (sameMasterRequest == null)
            {
                return(true);
            }

            for (int i = 0; i < sameMasterRequest.Count; i++)
            {
                CLoadRequest r = sameMasterRequest[i];
                if (r == this)
                {
                    continue;
                }
                if (r.load_num != r.loaded_num)
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 3
0
        private IEnumerator DoLoadObjectFromAssetBundle(AssetBundle asset_bundle, string sub_path, bool isAsyncMode = true)
        {
            for (int i = 0, n = load_num; i < n; ++i)
            {
                if (load_objectsThisRequest[i] == null)
                {
                    UnityEngine.Object asset = null;

                    if (isAsyncMode)
                    {
                        AssetBundleRequest asset_bundle_load_asset = null;
                        if (MbAssetBundleManager.Instance.ResourceDefine.IsSprite(m_eResourceType))
                        {
                            asset_bundle_load_asset = asset_bundle.LoadAssetAsync <Sprite>(resourceNames[i]);
                        }
                        else
                        {
                            asset_bundle_load_asset = asset_bundle.LoadAssetAsync(resourceNames[i]);
                        }
                        while (asset_bundle_load_asset.isDone == false)
                        {
                            yield return(null);
                        }

                        asset = asset_bundle_load_asset.asset;
                    }
                    else
                    {
                        if (MbAssetBundleManager.Instance.ResourceDefine.IsSprite(m_eResourceType))
                        {
                            asset = asset_bundle.LoadAsset <Sprite>(resourceNames[i]);
                        }
                        else
                        {
                            asset = asset_bundle.LoadAsset(resourceNames[i]);
                        }
                    }

                    if (asset == null && !resourceNames[i].ToLower().Equals("shader"))
                    {
                        CAssetBundleLog.LogError(string.Format("Load {0} from assetbundle {1} failed", resourceNames[i], packageName));
                    }
                    load_objectsThisRequest[i] = CAssetObject.Get(m_eResourceType,
                                                                  sub_path + resourceNames[i], asset);//refCount++
                    loaded_num++;
#if DEBUG
                    CAssetBundleLog.Log("读取资源:" + resourceNames[i]);
#endif
                    //保存读出来的资源到缓存
                    if (!MbAssetBundleManager.Instance.loadedAssetObjectDic.ContainsKey(m_eResourceType))
                    {
                        MbAssetBundleManager.Instance.loadedAssetObjectDic.Add(m_eResourceType, new Dictionary <string, CAssetObject>());
                    }

                    Dictionary <string, CAssetObject> loadedAssetCategoryDic = null;
                    if (MbAssetBundleManager.Instance.loadedAssetObjectDic.TryGetValue(m_eResourceType, out loadedAssetCategoryDic))
                    {
                        if (!loadedAssetCategoryDic.ContainsKey(sub_path + resourceNames[i]))
                        {
                            loadedAssetCategoryDic.Add(sub_path + resourceNames[i], load_objectsThisRequest[i]);
                        }
                    }
                }
            }

            if (sameMasterRequest != null)
            {
                for (int i = 0; i < sameMasterRequest.Count; i++)
                {
                    CLoadRequest r = sameMasterRequest[i];
                    if (r == this)
                    {
                        continue;
                    }
                    r.LoadObjectFromAssetBundle(asset_bundle, sub_path, isAsyncMode);
                    //  while (r.isLoadingFromAssetBundle)
                    //     yield return null;
#if DEBUG
                    CAssetBundleLog.Log(string.Format("sameMasterRequest loaded.{0}", r.packageName));
#endif
                }
            }

            while (isLoadingFromAssetBundle_sameMasterRequest())
            {
                yield return(null);
            }

            if (load_objectsThisRequest != null)
            {
                for (int j = 0; j < load_objectsThisRequest.Length; j++)
                {
                    if (load_objectsThisRequest[j] == null)
                    {
                        CAssetBundleLog.LogError(string.Format("error !{0},{1}", packageName, j));
                    }
                }
            }

            isLoadingFromAssetBundle = false;
        }