Пример #1
0
    public bool HasResource(WWWType type, string url)
    {
        string hash = GetHash(type, url);

        if (mFileInfoMap == null)
        {
            return(false);
        }
        if (!mFileInfoMap.ContainsKey(hash))
        {
            return(false);
        }
        if (mFileInfoMap[hash] == null)
        {
            return(false);
        }
        if (!IsPathExists(mFileInfoMap[hash].localPath))
        {
            return(false);
        }

        if (!CheckMd5(type, url))
        {
            return(false);
        }

        if (IsExpired(type, url))
        {
            return(false);
        }

        return(true);
    }
Пример #2
0
    public WWWFileInfo GetFileInfo(WWWType type, string url)
    {
        string hash = GetHash(type, url);

        if (!mFileInfoMap.ContainsKey(hash))
        {
            return(null);
        }
        return(mFileInfoMap[hash]);
    }
Пример #3
0
    public IWWWRequestHandle BuildRequest(WWWType type, string url)
    {
        WWWRequestHandle requestHandle;

        requestHandle = new WWWRequestHandle(this);
        requestHandle.SetType(type);
        requestHandle.SetUrl(url);

        return(requestHandle);
    }
Пример #4
0
        public void ReadFileBytes(string noticeKey, string fileUrl, float timeoutSec, WWWUrlRstBytesDel del, LuaFunction lua)
        {
            mType           = WWWType.readBytes;
            mUrlRstBytesDel = del;
            setLuaCallback(lua);
            mTimeoutSec = timeoutSec;
            NoticeKey   = noticeKey;

            mList.Clear();
            mList.Add(new WWWInfo(fileUrl, ""));
        }
Пример #5
0
        /// <summary>
        /// 请求某个链接,并获取其返回值或错误信息
        /// </summary>
        /// <param name="url">请求地址</param>
        /// <param name="timeoutSec">超时时间(秒)</param>
        /// <param name="del">请求回调:
        /// (bool rst, string msg)
        /// rst 表示请求是否成功,msg信息(成返回结果,失败返回错误信息)
        /// </param>
        /// <param name="lua">lua回调,参数跟del相同</param>
        public void RequestUrl(string url, float timeoutSec, WWWUrlRstDel del, LuaFunction lua)
        {
            mType      = WWWType.request;
            mUrlRstDel = del;
            setLuaCallback(lua);
            mTimeoutSec = timeoutSec;

            mList.Add(new WWWInfo()
            {
                Url = url,
            });
        }
Пример #6
0
        /// <summary>
        /// 上传一个文件
        /// </summary>
        /// <param name="noticeKey">下载的key,用于多个上传组件时区分</param>
        /// <param name="info">上传的信息</param>
        /// <param name="timeoutSec">超时时间(秒)</param>
        /// <param name="del">上传进度回调
        /// (string noticeKey, double progress, int index, string msg);
        /// 上传key,上传进度(-1代表有错;1代表全部上传过[可能完成或部分失败]),当前上传的文件index,msg信息(当progress==1且msg=="succeeded"才表示上传成功)
        /// </param>
        /// <param name="lua">lua回调,参数跟del相同</param>
        public void UploadFile(string noticeKey, WWWInfo info, float timeoutSec, WWWRstDel del, LuaFunction lua)
        {
            mType   = WWWType.upload;
            mRstDel = del;
            setLuaCallback(lua);
            mTimeoutSec = timeoutSec;
            mTotalSize  = info.Size;
            NoticeKey   = noticeKey;

            mList.Clear();
            mList.Add(info);
        }
Пример #7
0
    public bool CheckMd5(WWWType type, string url)
    {
        WWWFileInfo fileIfo = GetFileInfo(type, url);

        if (fileIfo == null)
        {
            return(false);
        }
        string nowMd5 = GetFileMd5(fileIfo.localPath);

        return(string.Compare(nowMd5, fileIfo.md5, System.StringComparison.OrdinalIgnoreCase) == 0);
    }
Пример #8
0
    private bool IsExpired(WWWType type, string url)
    {
        string hash = GetHash(type, url);

        if (!mFileInfoMap.ContainsKey(hash))
        {
            return(true);
        }
        if (mFileInfoMap[hash].ExpiredTimestamp > GameMain.GetInstance().GetTime())
        {
            return(false);
        }
        return(true);
    }
Пример #9
0
        public void ReadFirstExistsBytes(string noticeKey, List <string> files, float timeoutSec, WWWUrlRstBytesDel del, LuaFunction lua)
        {
            mType           = WWWType.readBytes;
            mUrlRstBytesDel = del;
            setLuaCallback(lua);
            mTimeoutSec = timeoutSec;
            NoticeKey   = noticeKey;

            mList.Clear();
            for (int i = 0; i < files.Count; i++)
            {
                string fileUrl = files[i];
                mList.Add(new WWWInfo(fileUrl, ""));
            }
        }
Пример #10
0
        /// <summary>
        /// 上传多个文件
        /// </summary>
        /// <param name="noticeKey">上传的key,用于多个上传组件时区分</param>
        /// <param name="infos">上传的信息</param>
        /// <param name="timeoutSec">超时时间(秒)</param>
        /// <param name="del">上传进度回调
        /// (string noticeKey, double progress, int index, string msg)
        /// 上传key,下载进度(-1代表有错;1代表全部上传过[可能完成或部分失败]),index当前上传的文件index(0开始),msg信息(当progress==1且msg=="succeeded"才表示上传成功)
        /// </param>
        /// <param name="lua">lua回调,参数跟del相同</param>
        public void UploadFiles(string noticeKey, List <WWWInfo> infos, float timeoutSec, WWWRstDel del, LuaFunction lua)
        {
            mType = WWWType.upload;
            if (null == infos || infos.Count == 0)
            {
                callback(-1, "download files info list is null or empty!");
                return;
            }
            mRstDel = del;
            setLuaCallback(lua);
            mTimeoutSec = timeoutSec;
            NoticeKey   = noticeKey;
            for (int i = 0; i < infos.Count; i++)
            {
                mTotalSize = infos[i].Size;
            }

            mList.Clear();
            mList.AddRange(infos);
            mFialedList.Clear();
        }
Пример #11
0
    public T TryLoadFromCache <T>(WWWType type, string url) where T : UnityEngine.Object
    {
        if (mAssetPool != null)
        {
            T t = mAssetPool.Get <T>(url);
            if (t != null)
            {
                return(t);
            }
        }

        if (HasResource(type, url))
        {
            WWWFileInfo fileInfo = GetFileInfo(type, url);
            if (fileInfo != null)
            {
                string filePath = fileInfo.localPath;

                byte[] bytes = GameUtils.ReadAllBytesFromFile(filePath);

                if (typeof(T) == typeof(Texture2D))
                {
                    Texture2D tex = GameUtils.GetTextureFromBytes(bytes);

                    tex.Apply(false, true);

                    if (tex != null && mAssetPool != null)
                    {
                        tex.name = url;
                        mAssetPool.AddAsset(url, tex);
                    }

                    return(tex as T);
                }
            }
        }

        return(default(T));
    }
Пример #12
0
 public IWWWRequestHandle SetType(WWWType type)
 {
     Type = type;
     return(this);
 }
Пример #13
0
 public static string GetHash(WWWType type, string url)
 {
     return(GetMd5(type.ToString() + '_' + url));
 }