コード例 #1
0
        public string getAbsPathByRelPath(ref string relPath, ref ResLoadType loadType)
        {
            // 获取版本
            string version = Ctx.m_instance.m_versionSys.getFileVer(relPath);
            string absPath = relPath;

            if (!string.IsNullOrEmpty(version))
            {
                absPath = UtilLogic.combineVerPath(Path.Combine(Ctx.m_instance.m_localFileSys.getLocalWriteDir(), relPath), version);
                if (!File.Exists(absPath))
                {
                    absPath = Path.Combine(Ctx.m_instance.m_localFileSys.getLocalReadDir(), relPath);
                    if (!File.Exists(absPath))
                    {
                        absPath = "";
                    }
                    else
                    {
                        loadType = ResLoadType.eStreamingAssets;
                    }
                }
                else
                {
                    relPath  = UtilLogic.combineVerPath(relPath, version);        // 在可写目录下,文件名字是有版本号的
                    loadType = ResLoadType.ePersistentData;
                }
            }
            else
            {
                loadType = ResLoadType.eStreamingAssets;
            }

            return(absPath);
        }
コード例 #2
0
        //protected void parsePath()
        //{
        //    string[] pathSplit = { "?" };
        //    string[] pathList = m_path.Split(pathSplit, StringSplitOptions.RemoveEmptyEntries);
        //    m_path = pathList[0];

        //    if (pathList.Length > 1)
        //    {
        //        string[] equalSplit = { "=" };
        //        string[] equalList = pathList[1].Split(equalSplit, StringSplitOptions.RemoveEmptyEntries);
        //        m_version = equalList[1];
        //    }
        //}

        override public void load()
        {
            //parsePath();
            base.load();
            if (ResLoadType.eStreamingAssets == m_resLoadType)
            {
                loadFromStreamingAssets();
            }
            else if (ResLoadType.ePersistentData == m_resLoadType)
            {
                loadFromPersistentData();
            }
            else if (ResLoadType.eLoadWeb == m_resLoadType)
            {
                //Ctx.m_instance.m_coroutineMgr.StartCoroutine(downloadAsset());
                //Ctx.m_instance.m_coroutineMgr.StartCoroutine(coroutWebDown());
                m_localPath = Path.Combine(Ctx.m_instance.m_localFileSys.getLocalWriteDir(), UtilLogic.getRelPath(m_path));
                if (!string.IsNullOrEmpty(m_version))
                {
                    m_localPath = UtilLogic.combineVerPath(m_localPath, m_version);
                }

                Ctx.m_instance.m_logSys.log(string.Format("添加下载任务 {0}", m_path));
                Ctx.m_instance.m_TaskQueue.push(this);
            }
        }
コード例 #3
0
        public void onWebMiniLoaded()
        {
            // 删除旧 mini 版本,修改新版本文件名字
            UtilApi.delFile(Path.Combine(Ctx.m_instance.m_localFileSys.getLocalWriteDir(), FilesVer.FILENAME));
            // 修改新的版本文件名字
            UtilApi.renameFile(UtilLogic.combineVerPath(Path.Combine(Ctx.m_instance.m_localFileSys.getLocalWriteDir(), FilesVer.MINIFILENAME), m_miniVer), Path.Combine(Ctx.m_instance.m_localFileSys.getLocalWriteDir(), FilesVer.MINIFILENAME));

            m_needUpdateVerFile = (m_localVer.m_miniPath2HashDic[FilesVer.FILENAME].m_fileMd5 != m_webVer.m_miniPath2HashDic[FilesVer.FILENAME].m_fileMd5);      // 如果版本不一致,需要重新加载
            //m_needUpdateVerFile = true;         // 测试强制更新
            m_miniLoadResultDisp();
        }
コード例 #4
0
        override public void load()
        {
            base.load();

            string curExt;

            // 如果是打包的资源
            if (Ctx.m_instance.m_cfg.m_pakExtNameList.IndexOf(m_extName) != -1)
            {
                curExt = FileResItem.UNITY3D_EXT;
            }
            else if (string.IsNullOrEmpty(m_extName))        // 材质 mat 源文件是没有扩展名字的,因为 3dmax 材质扩展名字也是 mat ,可能 unity 怕识别错误了吧
            {
                curExt = FileResItem.UNITY3D_EXT;
            }
            else
            {
                curExt = m_extName;
            }

            string curPath;

            curPath = Path.Combine(Application.streamingAssetsPath, m_pathNoExt);
            curPath = UtilLogic.getPakPathAndExt(curPath, curExt);

            if (Ctx.m_instance.m_localFileSys.isFileExist(curPath))
            {
                m_bytes = Ctx.m_instance.m_localFileSys.LoadFileByte(curPath);
            }
            else
            {
                Ctx.m_instance.m_logSys.log(string.Format("{0} 文件不存在", curPath));
            }

            if (m_bytes != null)
            {
                nonRefCountResLoadResultNotify.resLoadState.setSuccessLoaded();
            }
            else
            {
                nonRefCountResLoadResultNotify.resLoadState.setFailed();
            }

            nonRefCountResLoadResultNotify.loadResEventDispatch.dispatchEvent(this);
        }
コード例 #5
0
        override protected void updateLeftAttr(TableCardItemBody tableBody)
        {
            // 根据表中的数据更新,如果服务器有数据,还会根据服务器的数据更新一次,因为图鉴的数据是根据表中更新的,场景中的牌是根据服务器的数据更新的
            UtilLogic.updateCardDataNoChangeByTable(tableBody, m_model.selfGo);
            UtilLogic.updateCardDataChangeByTable(tableBody, m_model.selfGo);

            AuxLabel raceText = new AuxLabel(m_model.selfGo, "UIRoot/RaceText");

            // 更新种族
            if (tableBody.m_race > 0)
            {
                TableRaceItemBody raceTableItem = Ctx.m_instance.m_tableSys.getItem(TableID.TABLE_RACE, (uint)tableBody.m_race).m_itemBody as TableRaceItemBody;
                raceText.text = raceTableItem.m_raceName;
            }
            else
            {
                GameObject raceGO = UtilApi.TransFindChildByPObjAndPath(m_model.selfGo, m_cardModelItem.m_raceSubModel);
                UtilApi.SetActive(raceGO, false);
                raceText.text = "";
            }

            if (tableBody.m_type == (int)CardType.CARDTYPE_MAGIC)//法术牌
            {
                GameObject raceGO = UtilApi.TransFindChildByPObjAndPath(m_model.selfGo, "gongji_kapai");
                UtilApi.SetActive(raceGO, false);
                AuxLabel attText = new AuxLabel(m_model.selfGo, "UIRoot/AttText");
                attText.text = "";

                GameObject raceGO2 = UtilApi.TransFindChildByPObjAndPath(m_model.selfGo, "xue_kapai");
                UtilApi.SetActive(raceGO2, false);
                AuxLabel hpText = new AuxLabel(m_model.selfGo, "UIRoot/HpText");
                hpText.text = "";
            }
            else if (tableBody.m_type == (int)CardType.CARDTYPE_EQUIP)//武器牌
            {
                GameObject raceGO2 = UtilApi.TransFindChildByPObjAndPath(m_model.selfGo, "xue_kapai");
                UtilApi.SetActive(raceGO2, false);
                AuxLabel hpText = new AuxLabel(m_model.selfGo, "UIRoot/HpText");
                hpText.text = "";
            }
        }
コード例 #6
0
        public void loadOneUpdateFile(string path, FileVerInfo fileInfo)
        {
            //string loadPath = UtilApi.combineVerPath(path, fileInfo.m_fileMd5);
            //m_loadingPath.Add(loadPath);
            m_loadingPath.Add(UtilLogic.webFullPath(path));
            if (Ctx.m_instance.m_versionSys.m_localVer.m_path2HashDic.ContainsKey(path))
            {
                UtilApi.delFile(Path.Combine(Ctx.m_instance.m_localFileSys.getLocalWriteDir(), UtilLogic.combineVerPath(path, Ctx.m_instance.m_versionSys.m_localVer.m_path2HashDic[path].m_fileMd5)));     // 删除当前目录下已经有的 old 文件
            }
            //UtilApi.delFileNoVer(path);     // 删除当前目录下已经有的 old 文件

            LoadParam param = Ctx.m_instance.m_poolSys.newObject <LoadParam>();

            param.m_path = path;

            param.m_resLoadType = ResLoadType.eLoadWeb;
            param.m_version     = fileInfo.m_fileMd5;

            param.m_loadEventHandle = onLoadEventHandle;

            Ctx.m_instance.m_resLoadMgr.loadData(param);
            Ctx.m_instance.m_poolSys.deleteObj(param);
        }
コード例 #7
0
        protected void loadFromPersistentData()
        {
            string verPath = m_path;

            if (!string.IsNullOrEmpty(m_version))
            {
                verPath = UtilLogic.combineVerPath(m_path, m_version);
            }
            if (Ctx.m_instance.m_localFileSys.isFileExist(verPath))
            {
                m_bytes = Ctx.m_instance.m_localFileSys.LoadFileByte(verPath);
            }

            if (m_bytes != null)
            {
                nonRefCountResLoadResultNotify.resLoadState.setSuccessLoaded();
            }
            else
            {
                nonRefCountResLoadResultNotify.resLoadState.setFailed();
            }
            nonRefCountResLoadResultNotify.loadResEventDispatch.dispatchEvent(this);
        }
コード例 #8
0
        public void resolveLevel()
        {
            resolvePath();

            int slashIdx = 0;

            if (string.IsNullOrEmpty(m_origPath))
            {
                slashIdx = m_pathNoExt.LastIndexOf("/");
                if (slashIdx != -1)
                {
                    m_lvlName = m_pathNoExt.Substring(slashIdx + 1);
                }
                else
                {
                    m_lvlName = m_pathNoExt;
                }
            }
            else        // 如果是打包,需要从原始加载目录获取关卡名字
            {
                m_lvlName = UtilLogic.convScenePath2LevelName(m_origPath);
            }
        }
コード例 #9
0
        // 线程下载
        public void runTask()
        {
            Ctx.m_instance.m_logSys.log(string.Format("线程开始下载下载任务 {0}", m_path));

            string saveFile    = Path.Combine(Ctx.m_instance.m_localFileSys.getLocalWriteDir(), UtilLogic.getRelPath(m_path));
            string origFile    = saveFile;  // 没有版本号的文件名字,如果本地没有这个文件,需要先建立这个文件,等下载完成后,然后再改名字,保证下载的文件除了网络传输因素外,肯定正确
            bool   bNeedReName = false;

            if (!string.IsNullOrEmpty(m_version))
            {
                saveFile = UtilLogic.combineVerPath(saveFile, m_version);
            }

            try
            {
                //打开网络连接
                string webPath;
                if (!string.IsNullOrEmpty(m_version))
                {
                    webPath = string.Format("{0}?v={1}", m_path, m_version);
                }
                else
                {
                    webPath = m_path;
                }

                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(webPath);
                request.Method      = "GET";
                request.ContentType = "application/x-www-form-urlencoded";
                request.KeepAlive   = false;
                request.Proxy       = null;
                request.Timeout     = 5000;

                ServicePointManager.DefaultConnectionLimit = 50;

                // GetRequestStream 总是出错,因此只能使用 GET 方式
                //StreamWriter requestWriter = null;
                //Stream webStream = request.GetRequestStream();
                //requestWriter = new StreamWriter(webStream);
                //try
                //{
                //    string postString = string.Format("v={0}", m_version);
                //    requestWriter.Write(postString);
                //}
                //catch (Exception ex2)
                //{
                //    Ctx.m_instance.m_logSys.asynclog("error");
                //}
                HttpWebResponse response      = (HttpWebResponse)request.GetResponse();
                long            contentLength = response.ContentLength;
                long            readedLength  = 0;

                long       lStartPos  = 0;
                FileStream fileStream = null;
                if (File.Exists(saveFile))
                {
                    fileStream = File.OpenWrite(saveFile);
                    lStartPos  = fileStream.Length;
                    if (contentLength - lStartPos <= 0)     // 文件已经完成
                    {
                        fileStream.Close();
                        onRunTaskEnd();
                        Ctx.m_instance.m_logSys.log("之前文件已经下载完成,不用重新下载");
                        return;
                    }
                    fileStream.Seek(lStartPos, SeekOrigin.Current); //移动文件流中的当前指针
                }
                else
                {
                    bNeedReName = true;
                    try
                    {
                        fileStream = new FileStream(origFile, System.IO.FileMode.Create);
                    }
                    catch (Exception /*ex2*/)
                    {
                        Ctx.m_instance.m_logSys.error(string.Format("{0} 文件创建失败", saveFile));
                    }
                }

                if (lStartPos > 0)
                {
                    request.AddRange((int)lStartPos); //设置Range值
                    contentLength -= lStartPos;
                }

                //向服务器请求,获得服务器回应数据流
                System.IO.Stream retStream = response.GetResponseStream();
                int len = 1024 * 8;
                m_bytes = new byte[len];
                int    nReadSize = 0;
                string logStr;
                bool   isBytesValid = true;      // m_bytes 中数据是否有效
                while (readedLength != contentLength)
                {
                    nReadSize = retStream.Read(m_bytes, 0, len);
                    fileStream.Write(m_bytes, 0, nReadSize);
                    readedLength += nReadSize;
                    //logStr = "已下载:" + fs.Length / 1024 + "kb /" + contentLength / 1024 + "kb";
                    logStr = string.Format("文件 {0} 已下载: {1} b / {2} b", m_path, fileStream.Length, contentLength);
                    Ctx.m_instance.m_logSys.log(logStr);

                    if (isBytesValid)
                    {
                        if (readedLength != contentLength)
                        {
                            isBytesValid = false;
                        }
                    }
                }

                // 释放资源
                request.Abort();
                request = null;
                response.Close();
                response = null;

                retStream.Close();
                fileStream.Close();

                // 修改文件名字
                if (bNeedReName)
                {
                    UtilApi.renameFile(origFile, saveFile);
                }

                if (!isBytesValid)
                {
                    m_bytes = null;
                }

                if (readedLength == contentLength)
                {
                    m_isRunSuccess = true;
                }
                else
                {
                    m_isRunSuccess = false;
                }
                onRunTaskEnd();
            }
            catch (Exception /*err*/)
            {
                m_isRunSuccess = false;
                onRunTaskEnd();
            }
        }
コード例 #10
0
        // 协程下载
        protected IEnumerator coroutWebDown()
        {
            string uri      = UtilLogic.webFullPath(m_path);
            string saveFile = Path.Combine(Ctx.m_instance.m_localFileSys.getLocalWriteDir(), m_path);

            //try
            {
                //打开网络连接
                HttpWebRequest  request       = (HttpWebRequest)HttpWebRequest.Create(uri);
                HttpWebResponse response      = (HttpWebResponse)request.GetResponse();
                long            contentLength = response.ContentLength;
                long            readedLength  = 0;

                long       lStartPos = 0;
                FileStream fileStream;
                if (File.Exists(saveFile))
                {
                    fileStream = System.IO.File.OpenWrite(saveFile);
                    lStartPos  = fileStream.Length;
                    if (contentLength - lStartPos <= 0)     // 文件已经完成
                    {
                        fileStream.Close();
                        yield break;
                    }
                    fileStream.Seek(lStartPos, SeekOrigin.Current); //移动文件流中的当前指针
                }
                else
                {
                    fileStream = new FileStream(saveFile, System.IO.FileMode.Create);
                }

                if (lStartPos > 0)
                {
                    request.AddRange((int)lStartPos); //设置Range值
                    contentLength -= lStartPos;
                }

                //向服务器请求,获得服务器回应数据流
                System.IO.Stream retStream = response.GetResponseStream();
                int len = 1024 * 8;
                m_bytes = new byte[len];
                int    nReadSize = 0;
                string logStr;
                while (readedLength != contentLength)
                {
                    nReadSize = retStream.Read(m_bytes, 0, len);
                    fileStream.Write(m_bytes, 0, nReadSize);
                    readedLength += nReadSize;
                    logStr        = "已下载:" + fileStream.Length / 1024 + "kb /" + contentLength / 1024 + "kb";
                    Ctx.m_instance.m_logSys.log(logStr);
                    yield return(false);
                }
                retStream.Close();
                fileStream.Close();
                if (readedLength == contentLength)
                {
                    nonRefCountResLoadResultNotify.resLoadState.setSuccessLoaded();
                }
                else
                {
                    nonRefCountResLoadResultNotify.resLoadState.setFailed();
                }
                nonRefCountResLoadResultNotify.loadResEventDispatch.dispatchEvent(this);
            }
            //catch (Exception)
            //{
            //    if (onFailed != null)
            //    {
            //        onFailed(this);
            //    }
            //}
        }
コード例 #11
0
        // 修改卡牌纹理
        override protected void modifyTex(GameObject go_, TableCardItemBody tableBody)
        {
            // 头像是每一个卡牌一个配置
            string path = string.Format("{0}{1}", Ctx.m_instance.m_cfg.m_pathLst[(int)ResPathType.ePathCardImage], tableBody.m_cardHeader);

            m_subTex[(int)CardSubPartType.eHeader].tex.selfGo  = UtilApi.TransFindChildByPObjAndPath(go_, m_cardModelItem.m_headerSubModel);
            m_subTex[(int)CardSubPartType.eHeader].tex.texPath = path;
            m_subTex[(int)CardSubPartType.eHeader].tex.syncUpdateTex();

            TableJobItemBody jobTable;

            // 边框
            jobTable = Ctx.m_instance.m_tableSys.getItem(TableID.TABLE_JOB, (uint)(tableBody.m_career)).m_itemBody as TableJobItemBody;
            path     = string.Format("{0}{1}", Ctx.m_instance.m_cfg.m_pathLst[(int)ResPathType.ePathCardImage], jobTable.m_frameImage);
            m_subTex[(int)CardSubPartType.eFrame].tex.selfGo  = UtilApi.TransFindChildByPObjAndPath(go_, m_cardModelItem.m_frameSubModel);
            m_subTex[(int)CardSubPartType.eFrame].tex.texPath = path;
            m_subTex[(int)CardSubPartType.eFrame].tex.syncUpdateTex();

            // 腰带
            path = string.Format("{0}{1}", Ctx.m_instance.m_cfg.m_pathLst[(int)ResPathType.ePathCardImage], jobTable.m_yaoDaiImage);
            m_subTex[(int)CardSubPartType.eBelt].tex.selfGo  = UtilApi.TransFindChildByPObjAndPath(go_, m_cardModelItem.m_yaoDaiSubModel);
            m_subTex[(int)CardSubPartType.eBelt].tex.texPath = path;
            m_subTex[(int)CardSubPartType.eBelt].tex.syncUpdateTex();

            // 品质
            m_subTex[(int)CardSubPartType.EQuality].tex.selfGo = UtilApi.TransFindChildByPObjAndPath(go_, m_cardModelItem.m_pinZhiSubModel);
            if (tableBody.m_quality == 0)        // 品质 0 ,不显示
            {
                UtilApi.SetActive(m_subTex[(int)CardSubPartType.EQuality].tex.selfGo, false);
            }
            else
            {
                path = string.Format("{0}{1}", Ctx.m_instance.m_cfg.m_pathLst[(int)ResPathType.ePathCardImage], UtilLogic.getImageByPinZhi(tableBody.m_quality));
                m_subTex[(int)CardSubPartType.EQuality].tex.texPath = path;
                m_subTex[(int)CardSubPartType.EQuality].tex.syncUpdateTex();
            }
        }