예제 #1
0
    IEnumerator LoadTask(AysnLoadTask task)
    {
        yield return(null);

        WWW www = new WWW("File://" + task.absolutePath);

        yield return(www);

        if (www.error == null)
        {
            AssetBundle ab  = www.assetBundle;
            Object      obj = ab.LoadAsset(task.name);
            mDicPool.Add(task.path, obj);
            ab.Unload(false);
        }
        else
        {
            Debug.LogError("load error:" + www.error + "  " + task.absolutePath);
        }
        if (mListLoading.Contains(task.path))
        {
            mListLoading.Remove(task.path);
        }
        www.Dispose();
        www = null;
    }
예제 #2
0
    /// <summary>
    /// 获取图片资源
    /// </summary>
    /// <param name="path"></param>
    /// <returns></returns>
    public Texture2D GetTexture2D(string path)
    {
        if (mDicPool.ContainsKey(path))//已经在缓存中存在了
        {
            return(mDicPool[path] as Texture2D);
        }
        if (IResManager.ResDebug) //调试模式下直接下载
        {
            Texture2D texture2D = Resources.Load(path, typeof(Texture2D)) as Texture2D;
            mDicPool.Add(path, texture2D);
            return(texture2D);
        }

        //缓存不存在 那么看看是否在加载队列中
        if (mListLoading.Contains(path))
        {
            return(null);
        }
        //加载

        DBVersionEnum versionEnum = DBVersionManager.CompareVersion(path);

        int    index = path.LastIndexOf("/") + 1;
        string name  = path.Substring(index, path.Length - index);


        if (versionEnum == DBVersionEnum.None)
        { //本地已经是最新的,那么从本地加载
            AysnLoadTask task = new AysnLoadTask();
            task.name         = name;
            task.path         = path;
            task.absolutePath = LocalUrl + "/" + path;
            mListLoading.Add(path);
            mLoadingTask.Add(task);
        }
        else   //从服务器加载
        {
            Texture2DMsg texture2DMsg = new Texture2DMsg();
            texture2DMsg.name         = path.Substring(index, path.Length - index);
            texture2DMsg.versionEnum  = versionEnum;
            texture2DMsg.path         = path;
            texture2DMsg.absolutePath = ResUrl + "/" + path;
            texture2DMsg.localPath    = LocalUrl + "/" + path;
            texture2DMsg.SetUrl(texture2DMsg.absolutePath);
            CThreadManager.GetInstance().PushMsg(enumThreadID.enumThread_Web, texture2DMsg);
            mListLoading.Add(path);
        }
        return(null);
    }
예제 #3
0
    IEnumerator Run()
    {
        while (true)
        {
            if (mLoadingTask.Count > 0)
            {
                AysnLoadTask task = mLoadingTask[0];
                mLoadingTask.RemoveAt(0);

                yield return(StartCoroutine(LoadTask(task)));

                if (mLoadingTask.Count == 0)
                {
                    Resources.UnloadUnusedAssets();
                    System.GC.Collect();
                }
            }

            yield return(null);
        }
    }