コード例 #1
0
    //--------------------------------------------------------------------------------------------
    // 从包里加载资源
    UnityEngine.Object NtfLoadResource(string szfileWithoutResources)
    {
        string szfile;

        if (mResDic != null)
        {
            ResPackItm itm = null;
            szfile = "Extends/" + szfileWithoutResources;
            if (mResDic.TryGetValue(szfile.ToLower(), out itm))
            {
                if (mPackDic != null)
                {
                    ResPackge pck = null;
                    if (mPackDic.TryGetValue(itm.mPack, out pck))
                    {
                        return(pck.LoadObject(szfile));
                    }
                }
            }
            szfile = "resources/" + szfileWithoutResources;
            if (mResDic.TryGetValue(szfile.ToLower(), out itm))
            {
                if (mPackDic != null)
                {
                    ResPackge pck = null;
                    if (mPackDic.TryGetValue(itm.mPack, out pck))
                    {
                        return(pck.LoadObject(szfile));
                    }
                }
            }
        }

        return(null);
    }
コード例 #2
0
    public LvItmBtnEx AddLvBtnEx(string sLabel, ResPackge pck)
    {
        LvItmBtnEx itm = new LvItmBtnEx();

        itm.mLabel  = sLabel;  // 显示的文字
        itm.mRefPck = pck;
        PushToAry(itm);
        return(itm);
    }
コード例 #3
0
    //-------------------------------------------------------------------------------------------------
    public LvItmLabelEx AddLvLabelEx(ResPackge pck)
    {
        LvItmLabelEx itm = new LvItmLabelEx();

        itm.mLabel  = pck.mFile;  // 显示的文字
        itm.mRefPck = pck;
        PushToAry(itm);
        return(itm);
    }
コード例 #4
0
    public LvItmBtnEx AddLvBtnEx(string sLabel, ResPackge pck)
    {
        LvItmBtnEx itm = new LvItmBtnEx();

        itm.mWidth  = mViewWH.x;
        itm.mLabel  = sLabel;  // 显示的文字
        itm.mRefPck = pck;
        AddLvItem(itm);
        return(itm);
    }
コード例 #5
0
    //-------------------------------------------------------------------------------------------------
    public LvItmLabelEx AddLvLabelEx(ResPackge pck)
    {
        LvItmLabelEx itm = new LvItmLabelEx();

        itm.mWidth  = mViewWH.x;
        itm.mLabel  = pck.mFile;  // 显示的文字
        itm.mRefPck = pck;
        AddLvItem(itm);
        return(itm);
    }
コード例 #6
0
 public ResPackge GetPackge(string sPck)
 {
     if (mPackDic != null)
     {
         ResPackge pck = null;
         if (mPackDic.TryGetValue(sPck, out pck))
         {
             return(pck);
         }
     }
     return(null);
 }
コード例 #7
0
 public void AddDelayCleanPackage(ResPackge package)
 {
     foreach (ResPackge pkg in m_delayCleanPackage)
     {
         if (pkg == package)
         {
             pkg.m_delayCleanStartTime = Time.realtimeSinceStartup;
             return;
         }
     }
     package.m_delayCleanStartTime = Time.realtimeSinceStartup;
     m_delayCleanPackage.Add(package);
 }
コード例 #8
0
 void MergePakcageList(PackageVersion pkgVersion)
 {
     foreach (KeyValuePair <string, PackageVersion.Version> p in pkgVersion.m_versions)
     {
         if (!mPackDic.ContainsKey(p.Key))
         {
             ResPackge pck = new ResPackge();
             pck.mType = 0;
             pck.mFile = p.Key;
             mPackDic.Add(pck.mFile, pck);
         }
     }
 }
コード例 #9
0
 public void RemoveKeepAlivePackage(string package)
 {
     for (int i = 0; i < m_keepAlivePackage.Count; i++)
     {
         if (m_keepAlivePackage[i] == package)
         {
             ResPackge pack = GetPackge(m_keepAlivePackage[i]);
             pack.Clean();
             pack.m_isKeepAlive = false;
             m_keepAlivePackage.RemoveAt(i);
             return;
         }
     }
 }
コード例 #10
0
 public bool IsAllKeepAlivePackageLoaded()
 {
     for (int i = 0; i < m_keepAlivePackage.Count; i++)
     {
         string    pkgName    = m_keepAlivePackage[i];
         ResPackge cfgPackage = GetPackge(pkgName);
         if (cfgPackage != null)
         {
             if (!cfgPackage.IsDone())
             {
                 return(false);
             }
         }
     }
     return(true);
 }
コード例 #11
0
 public void UpdateDelayCleanPackageTime(ResPackge package)
 {
     for (int i = 0; i < m_delayCleanPackage.Count;)
     {
         ResPackge pkg = m_delayCleanPackage[i];
         if (pkg == package)
         {
             pkg.m_delayCleanStartTime = Time.realtimeSinceStartup;
             return;
         }
         else
         {
             i++;
         }
     }
 }
コード例 #12
0
 //--------------------------------------------------------------------------------------------
 // 从包里加载场景
 bool NtfLoadScene(string szScene)
 {
     if (mPackDic != null)
     {
         ResPackItm itm  = null;
         string     szNm = Path.GetFileNameWithoutExtension(szScene).ToLower();
         if (mResDic.TryGetValue(szNm + ".unity", out itm))
         {
             ResPackge pck = null;
             if (mPackDic.TryGetValue(itm.mPack, out pck))
             {
                 return(pck.LoadLevel(szNm));
             }
         }
     }
     return(false);
 }
コード例 #13
0
    public void AddKeepAlivePackage(string package, bool startOpenImm = true)
    {
        for (int i = 0; i < m_keepAlivePackage.Count; i++)
        {
            if (m_keepAlivePackage[i] == package)
            {
                return;
            }
        }
        ResPackge pack = GetPackge(package);

        if (pack != null)
        {
            pack.m_isKeepAlive = true;
            m_keepAlivePackage.Add(package);
            if (!pack.IsDone() && startOpenImm)
            {
                mEntry.StartCoroutine(pack.TryDownload(false, false));
            }
        }
    }
コード例 #14
0
    public IEnumerator LoadSceneAsync(string sceneName, ResPackge.AsyncLoadData data, Action callback = null)
    {
        bool   isLoaded = false;
        string szNm     = Path.GetFileNameWithoutExtension(sceneName).ToLower();

        if (mPackDic != null)
        {
            ResPackItm itm = null;
            if (mResDic.TryGetValue(szNm + ".unity", out itm))
            {
                ResPackge pck = null;
                if (mPackDic.TryGetValue(itm.mPack, out pck))
                {
                    IEnumerator e = pck.LoadPackageAsync(data);
                    while (true)
                    {
                        e.MoveNext();
                        if (data.IsFinish)
                        {
                            break;
                        }
                        yield return(e.Current);
                    }
                    isLoaded = pck.LoadLevel(sceneName);
                    AddDelayCleanPackage(pck);
                }
            }
        }
        data.IsFinish = true;
        if (!isLoaded)    // 也许没有打包或用Unity打包
        {
            string unitySceneName = Path.GetFileNameWithoutExtension(sceneName);
            Application.LoadLevel(unitySceneName.ToLower());
        }
        if (callback != null)
        {
            callback();
        }
    }
コード例 #15
0
    public void CheckDelayCleanPackage()
    {
        bool isCleanOccur = false;

        for (int i = 0; i < m_delayCleanPackage.Count;)
        {
            ResPackge pkg = m_delayCleanPackage[i];
            if (Time.realtimeSinceStartup > pkg.m_delayCleanStartTime + 1 && pkg.m_canClean)
            {
                pkg.Clean();
                isCleanOccur = true;
                m_delayCleanPackage.RemoveAt(i);
            }
            else
            {
                i++;
            }
        }
        if (isCleanOccur)
        {
            NtfClearUnusedRes();
        }
    }
コード例 #16
0
    void OnTestPack()
    {
        if (null == mResDic)
        {
            return;
        }
        foreach (ResPackItm itm in mResDic.Values)
        {
            ResPackge pck = null;

            if (mPackDic.TryGetValue(itm.mPack, out pck))
            {
                string      szfnd  = itm.mFile;
                AssetBundle bundle = pck.mWLoad.assetBundle;
                bundle.LoadAllAssets();

                if (bundle.Contains(szfnd))
                {
                    Debug.Log("Find KEY = " + szfnd);
                    continue;
                }
                szfnd = Path.GetFileName(itm.mFile);
                if (bundle.Contains(szfnd))
                {
                    Debug.Log("Find KEY = " + szfnd);
                    continue;
                }
                szfnd = Path.GetFileNameWithoutExtension(itm.mFile);
                if (bundle.Contains(szfnd))
                {
                    Debug.Log("Find KEY = " + szfnd);
                    continue;
                }
            }
            Debug.LogWarning("NO file = " + itm.mFile);
        }
    }
コード例 #17
0
    //--------------------------------------------------------------------------------------------
    // szName 带路径但 不需要扩展名
    static public void TestLoadScene(LvItm itm, UIListViewCtrl frm)
    {
        bool       bLoad = false;
        LvItmBtnEx itx   = itm as LvItmBtnEx;

        if (itx != null)
        {
            ResPackge pck = itx.mRefPck;
            if (pck != null)
            {
                string     szName = Path.GetFileNameWithoutExtension(pck.mFile);
                GameResMng pMng   = GetResMng();
                if (null != pMng)
                {
                    bLoad = pMng.NtfLoadScene(szName);
                }
                if (!bLoad)    // 也许没有打包或用Unity打包
                {
                    string szNm = Path.GetFileNameWithoutExtension(szName);
                    Application.LoadLevel(szNm.ToLower());
                }
            }
        }
    }
コード例 #18
0
    IEnumerator BuildPackListAndDownLoad_Impl()
    {
        int downloadQueueCount = 1;

        for (int i = m_needDownloadPackage.Count; i < downloadQueueCount; i++)
        {
            m_needDownloadPackage.Add(new List <NeedDownloadData>());
        }
        string szLast = "";

        mMsg     = "Build Pack List ...";
        mPackDic = new Dictionary <string, ResPackge>();
        if (mResDic != null)
        {
            foreach (ResPackItm itm in mResDic.Values)
            {
                if (szLast == itm.mPack)
                {
                    continue;
                }
                szLast = itm.mPack;
//                string szNm = Path.GetFileName(itm.mPack);
                if (mPackDic.ContainsKey(itm.mPack))
                {
                    continue;
                }
                ResPackge pck = new ResPackge();
                pck.mType = itm.mType;
                pck.mFile = itm.mPack;
                mPackDic.Add(itm.mPack, pck);
            }
        }
        MergePakcageList();

        mMsg = "Down Pack Files ...";
        int downloadIndex = 0;

        foreach (KeyValuePair <string, ResPackge> res in mPackDic)
        {
            ResPackge pck = res.Value;
            mMsg = "DownOrLoad ... " + pck.mFile;
            //mEntry.StartCoroutine(pck.NtfDownOrLoad(mbLocal));
            bool forceDownload = false;
            bool keepAlive     = false;
            if (!m_versionPackage.HavePackage(pck.mFile))
            {
                forceDownload = true;
            }
            else
            {
                PackageVersion.Version localVersion = m_versionPackage.LookupPackageVersion(pck.mFile);
                if (localVersion.m_isAliveInRuntime)
                {
                    keepAlive = true;
                }
                if (m_remotePackage.HavePackage(pck.mFile))
                {
                    PackageVersion.Version remoteVersion = m_remotePackage.LookupPackageVersion(pck.mFile);
                    if (remoteVersion.m_version != localVersion.m_version)
                    {
                        forceDownload = true;
                    }
                }
            }

            if (m_remotePackage.HavePackage(pck.mFile))
            {
                PackageVersion.Version remoteVersion = m_remotePackage.LookupPackageVersion(pck.mFile);
                if (remoteVersion.m_isAliveInRuntime)
                {
                    keepAlive = true;
                }
            }
            if (keepAlive)
            {
                AddKeepAlivePackage(pck.mFile, false);
            }
            keepAlive = IsKeepAlivePackage(res.Key);
            //if (forceDownload || keepAlive)
            {
                NeedDownloadData data = new NeedDownloadData();
                data.m_forceDownload = forceDownload;
                data.m_isKeepAlive   = keepAlive;
                data.m_pck           = pck;
                List <NeedDownloadData> downQueue = m_needDownloadPackage[downloadIndex % m_needDownloadPackage.Count];
                downQueue.Add(data);
                downloadIndex++;
            }
            //else
            //{
            //    IEnumerator e = pck.TryDownload(!keepAlive, forceDownload);
            //    while (true)
            //    {
            //        e.MoveNext();
            //        if (pck.m_state != ResPackge.State.Downloading)
            //        {
            //            break;
            //        }
            //        yield return e.Current;
            //    }
            //}
        }
        IsCheckPackage          = true;
        mMsg                    = "";
        m_calcDownloadBytesTime = Time.realtimeSinceStartup;
        for (int i = 0; i < m_needDownloadPackage.Count; i++)
        {
            List <NeedDownloadData> downQueue = m_needDownloadPackage[i];
            if (downQueue.Count > 0)
            {
                mEntry.StartCoroutine(ProcDownloadQueue(i));
                mEntry.StartCoroutine(OverTimeCheck());
            }
        }

#if (MY_DEBUG) // 显示出来
        AddReToViewCtrl();
#endif
        yield return(1);
    }
コード例 #19
0
    //--------------------------------------------------------------------------------------------
    // szfile要求: Assets/ 之后的完整路径(含扩展名), 示例参考顶部说明
    public IEnumerator LoadResourceAsync(string szfileWithoutResources, ResPackge.AsyncLoadData data)
    {
        string    szfile      = "resources/" + szfileWithoutResources;
        ResPackge pck         = null;
        bool      isInPackage = false;

        if (mResDic != null)
        {
            ResPackItm itm = null;
            if (mResDic.TryGetValue(szfile.ToLower(), out itm))
            {
                isInPackage = true;
                if (mPackDic != null)
                {
                    if (mPackDic.TryGetValue(itm.mPack, out pck))
                    {
                    }
                }
            }
            if (pck == null)
            {
                szfile = "Extends/" + szfileWithoutResources;
                itm    = null;
                if (mResDic.TryGetValue(szfile.ToLower(), out itm))
                {
                    isInPackage = true;
                    if (mPackDic != null)
                    {
                        if (mPackDic.TryGetValue(itm.mPack, out pck))
                        {
                        }
                    }
                }
            }
        }
        if (pck != null)
        {
            UpdateDelayCleanPackageTime(pck);
            IEnumerator e           = pck.LoadObjectAsync(szfile, mEntry, data);
            bool        interrupted = false;
            data.AsyncCount++;
            while (!interrupted)
            {
                e.MoveNext();
                if (data.IsFinish)
                {
                    break;
                }
                yield return(e.Current);
            }
            data.FinishCount++;
        }
        //////////////////////////////////////////////////////////////////////////
        //Simulate
#if (UNITY_EDITOR) // 编辑模式下
        if (GameResMng.ForcePackage && DisableOtherResource)
        {
            IEnumerator eSimulate = SimulateWait();
            data.AsyncCount++;
            int testcount = 0;
            while (true)
            {
                eSimulate.MoveNext();
                testcount++;
                if (testcount > 1)
                {
                    break;
                }
                yield return(eSimulate.Current);
            }
            data.FinishCount++;
            data.IsFinish = true;
        }
#endif
        //////////////////////////////////////////////////////////////////////////
#if (UNITY_EDITOR) // 编辑模式下
        if (null == data.m_res && !DisableOtherResource && !ForcePackage)
        {
            data.m_res = AssetDatabase.LoadMainAssetAtPath("Assets/Extends/" + szfileWithoutResources);
        }
        if (null == data.m_res)
        {
            data.m_res = AssetDatabase.LoadMainAssetAtPath("Assets/Resources/" + szfileWithoutResources);
        }
#endif
        if (data.m_res == null)                   // 容错: 也许没有打包或用Unity打包
        {
            string szf  = szfileWithoutResources; // 影射到 Resources/ 目录下
            int    npos = szf.LastIndexOf('.');   // 去掉扩展名
            if (npos > 0)
            {
                szf = szf.Substring(0, npos);
            }
#if (UNITY_EDITOR) // 编辑模式下
            if (!DisableOtherResource)
            {
                data.m_res = Resources.Load("Extends/" + szf);
            }
#else
            data.m_res = Resources.Load("Extends/" + szf);
#endif
            if (null == data.m_res)
            {
                data.m_res = Resources.Load(szf);
            }
        }

        data.IsFinish = true;
        if (null == data.m_res)
        {
//			string msg = "";
            if (!isInPackage)
            {
                Debug.LogWarning("Load Resource Failed:" + szfile);
            }
            else
            {
                Debug.LogWarning("[Package]Load Resource Failed:" + szfile);
            }
        }
    }
コード例 #20
0
    void AddReToViewCtrl()
    {
#if (MY_DEBUG) // 显示出来
        UIListViewCtrl LvCtrl = m_lvCtrl;
        if (LvCtrl == null)
        {
            return;
        }
        LvCtrl.ClearLvItems();
        LvItm lvHdr = LvCtrl.AddLvLabel(@"调试信息", Color.red);
        lvHdr.mfont   = 24;
        lvHdr.mAnchor = TextAnchor.MiddleCenter;

        LvColGrp iGrp = LvCtrl.AddLvColGrp();

        //LvColGrp iGrp0 = iGrp.AddLvColGrp(0);
        string szVer = @"游戏版本:" + GameResMng.mGmVer;
        iGrp.AddLvLabel(szVer, 200, Color.green);

        szVer = @"资源版本:" + GameResMng.mReVer;
        iGrp.AddLvLabel(szVer, 200, Color.blue);

        //LvColGrp iGrp1 = iGrp.AddLvColGrp(2);
        //lvHdr = iGrp1.AddLvBtn(@"网络资源", 80, Color.blue);
        //lvHdr.mAnchor = TextAnchor.MiddleCenter;

        //lvHdr = iGrp1.AddLvBtn(@"本地资源", 80, Color.blue);
        //lvHdr.mAnchor = TextAnchor.MiddleCenter;

        iGrp.UpdateDrawH();


        LvCtrl.AddLvEmpty(5);

        LvCtrl.AddLvLabel(@"运行信息:", Color.green);

        LvItmGrp itmGrp = LvCtrl.AddLvItmGrp(@"搜索到的资源包:", Color.green);
        //itmGrp.AddLvLabel("asdf", 0, Color.white);
        //itmGrp.AddLvLabel("234234asdf", 0, Color.white);
        if (null != mPackDic)
        {
            foreach (ResPackge pck in mPackDic.Values)
            {
                Debug.Log("pck.mType = " + pck.mType.ToString());
                if (pck.mType == 0)
                {
                    itmGrp.AddLvLabelEx(pck);
                }
            }
        }

        itmGrp = LvCtrl.AddLvItmGrp(@"搜索到的场景:", Color.green);
        //itmGrp.AddLvLabel("asdf", 0, Color.white);
        //itmGrp.AddLvLabel("234234asdf", 0, Color.white);
        if (null != mPackDic)
        {
            Dictionary <string, ResPackItm> vDic = GetSceneItms();
            foreach (ResPackItm itm in vDic.Values)
            {
                ResPackge pck = GetPackge(itm.mPack);
                string    sf  = Path.GetFileNameWithoutExtension(itm.mFile);
                itmGrp.AddLvBtnEx(@"Load " + sf, pck);
            }
        }
#endif
    }