Example #1
0
    /// <summary>
    /// 每帧更新,所有的load完成后的回调都在这里完成
    /// </summary>
    IEnumerator InitLoad()
    {
        ResourceLoadTask temTask = null;

        while (true)
        {
            if (temTask != null)
            {
                if (string.IsNullOrEmpty(temTask.pAssetFileName))
                {
                    temTask.Callback();
                }
                else
                {
                    yield return(StartCoroutine(temTask.Load()));

                    if (string.IsNullOrEmpty(temTask.pError) == false)
                    {
                        Debug.Log(temTask.pError);
                    }

                    AddLoadedTask(temTask);//缓存完成的任务;

                    ///无论加载成功或失败都要回调
                    temTask.Callback();
                }

                temTask = null;
            }
            if (mLoadtasks.Count > 0)
            {
                temTask = mLoadtasks.Dequeue();
            }
            yield return(null);
        }
    }
Example #2
0
    /// <summary>
    /// AssetBundle资源任务的异步加载实现;
    /// </summary>
    /// <returns></returns>
    override public IEnumerator Load()
    {
        pLoadState = ResourceLoadState.Loading;
        ResourceLoadTask tempTask = ResourceManager.GetManager().GetResourceLoadTask(pAssetFileName);

        //如果任务已经加载过,则直接获取资源并完成;
        if (tempTask != null)
        {
            pAssetBundle = tempTask.pAssetBundle;
            pLoadObject  = tempTask.pLoadObject;
            if (pLoadObject == null && pAssetBundle != null && !string.IsNullOrEmpty(pAssetObjectName))
            {
                pLoadObject = pAssetBundle.LoadAsset(pAssetObjectName);
            }
            pLoadState = ResourceLoadState.Finished;
            yield break;
        }

        //否则,进行资源的加载;

        //获取资源的依赖文件;
        GetDependsTask(pAssetFileName);
        ResourceLoadTask temTask = null;

        if (mDependList != null)
        {
            //如果有依赖文件则先加载依赖文件;
            while (mDependList.Count > 0)
            {
                if (temTask != null)
                {
                    if (!string.IsNullOrEmpty(temTask.pAssetFileName))
                    {
                        yield return(temTask.Load());

                        if (string.IsNullOrEmpty(temTask.pError) == false)
                        {
                            Debug.Log(temTask.pError);
                        }

                        ResourceManager.GetManager().AddLoadedTask(temTask);
                    }
                    ///无论加载成功或失败都要回调
                    temTask.Callback();
                    temTask = null;
                    mDependList.RemoveAt(0);
                }
                if (mDependList.Count > 0)
                {
                    temTask = mDependList[0];
                }
            }
        }
        //通过WWW加载资源;
        string path = Application.dataPath + "/AssetBundles/" + pAssetFileName;
        WWW    www  = new WWW(path);

        yield return(www);

        if (www.isDone)
        {
            pAssetBundle = www.assetBundle;
            if (pAssetBundle != null)
            {
                if (!string.IsNullOrEmpty(pAssetObjectName) && pAssetObjectType != null)
                {
                    pLoadObject = pAssetBundle.LoadAsset(pAssetObjectName, pAssetObjectType);
                }
            }

            pLoadState = ResourceLoadState.Finished;
        }



        yield return(null);
    }