Exemple #1
0
    public IEnumerator LoadAsync(string strFullName)
    {
        if (AssetBundleManifest == null || string.IsNullOrEmpty(strFullName))
        {
            yield break;
        }

        InitAsync();

        int nHashCode            = strFullName.GetHashCode();
        LoadedAssetBundle loaded = ABManager.Instance.GetLoadedBundle(nHashCode);

        if (loaded != null)
        {
            loaded.Count();
            yield break;
        }
        if (mLoadingReqs.Contains(nHashCode))
        {
            yield break;
        }

        LoadFromType loadFromType = LoadFromType.LoadFromNone;

        string[] dependencies = null;
        if (AssetBundleManifest != null && AssetBundleHashSet.Contains(strFullName))
        {
            loadFromType = LoadFromType.LoadFromDownLoad;
            dependencies = AssetBundleManifest.GetAllDependencies(strFullName);
        }
        else if (LocalABBundleManifest != null && LocalABBundleHashSet.Contains(strFullName))
        {
            loadFromType = LoadFromType.LoadFromLocalAB;
            dependencies = LocalABBundleManifest.GetAllDependencies(strFullName);
        }

        int nLength = dependencies.Length;

        if (nLength > 0)
        {
            DependencsLoader dependCallBack = mDependItemPool.GetObject();
            if (dependCallBack != null)
            {
                dependCallBack.Reset();
                dependCallBack.mLength = nLength;
            }
            for (int i = 0; i < nLength; ++i)
            {
                ResourceManager.Instance.StartCoroutine(LoadBundleByWWW(dependencies[i], dependCallBack, loadFromType));
            }
            while (!dependCallBack.AllDone)
            {
                yield return(null);
            }
            mDependItemPool.RemoveObject(dependCallBack);
        }

        yield return(ResourceManager.Instance.StartCoroutine(LoadBundleByWWW(strFullName, null, loadFromType)));

        loaded = ABManager.Instance.GetLoadedBundle(nHashCode);
        if (loaded != null)
        {
            if (nLength > 0)
            {
                loaded.AddDpendences(dependencies);
            }
            loaded.MapAssets();
            ABManager.Instance.AfterLoad(loaded);
        }
        yield return(null);
    }
Exemple #2
0
    public LoadedAssetBundle LoadSyn(string strFullName, UpdateProgress updateFunc = null, bool bSend = false)
    {
        LoadedAssetBundle loaded = ABManager.Instance.GetLoadedBundle(strFullName.GetHashCode());

        if (loaded != null)
        {
            loaded.Count();
            return(loaded);
        }

        AssetManageInfo info = AssetManageConfigManager.Instance.GetInfo(strFullName);

        //资源是从DownLoad包里还是StreamAsset的包里读取的
        LoadFromType loadFromType = LoadFromType.LoadFromNone;

        string[] dependencies = null;
        if (AssetBundleManifest != null && AssetBundleHashSet.Contains(strFullName))
        {//是否在下载的包里
            loadFromType = LoadFromType.LoadFromDownLoad;
            dependencies = AssetBundleManifest.GetAllDependencies(strFullName);
        }
        else if (LocalABBundleManifest != null && LocalABBundleHashSet.Contains(strFullName))
        {//下载的包里找不到就到跟包的目录里寻找一遍看是否有依赖
            loadFromType = LoadFromType.LoadFromLocalAB;
            dependencies = LocalABBundleManifest.GetAllDependencies(strFullName);
        }

        //只要不是LoadFromNone,说明这个资源是有身份证的,并非来路不明
        if (loadFromType != LoadFromType.LoadFromNone)
        {
            int nCnt = 1;
            if (dependencies != null)
            {
                nCnt += dependencies.Length;
                for (int i = 0; i < dependencies.Length; ++i)
                {
                    LoadBundleByFileStream(dependencies[i], getLoadFromType(dependencies[i]), AssetEncryptMode.None);
                    if (updateFunc != null)
                    {
                        updateFunc((float)(i + 1) / nCnt, bSend);
                    }
                }
            }

            //Debug.Log("<color=red> LoadSyn: " + strFullName + "</color>");

            loaded = LoadBundleByFileStream(strFullName, loadFromType, info.encryption);
            if (loaded != null)
            {
                if (dependencies != null && dependencies.Length > 0)
                {
                    loaded.AddDpendences(dependencies);
                }
                if (info.loadType != ELoadType.Music && info.loadType != ELoadType.Scene)
                {
                    loaded.MapAssets();
                    ABManager.Instance.AfterLoad(loaded);
                }
                if (updateFunc != null)
                {
                    updateFunc(1.0f, bSend);
                }
            }

            return(loaded);
        }
        else
        {
            Debug.Log("<color=red>资源:" + strFullName + "来路不明,在bundle表里不存在。</color>");
            return(null);
        }
    }