Beispiel #1
0
    //--------------------------------------------------------------------------------------------
    // szName 带路径但 不需要扩展名
    public void LoadSceneCallback(string szName, Action callback)
    {
        GameResMng pMng = GetResMng();

        if (null != pMng)
        {
            ResPackge.AsyncLoadData data = new ResPackge.AsyncLoadData();
            mEntry.StartCoroutine(pMng.LoadSceneAsync(szName, data, callback));
        }
    }
Beispiel #2
0
    public IEnumerator LoadObjectAsync(string sfile, MonoBehaviour delegateYield, ResPackge.AsyncLoadData data)
    {
        string sUrl = ResPath.WLocalUrl(mFile);

        m_canCleanCount++;
        if (m_state == State.LocalReady)
        {
            if (!IsDone() && m_state == State.LocalReady)
            {
                Debug.Log("LoadObjectAsync open package, URL = " + sUrl);
                if (mWLoad == null)
                {
                    mWLoad = new WWW(sUrl);
                }
                m_lockCount++;
                yield return(mWLoad);

                //yield return new WaitForSeconds(2);
                if (mWLoad == null || null != mWLoad.error)
                {
                    m_state = State.Failed;
                    if (mWLoad != null)
                    {
                        Debug.LogError(mWLoad.error);
                    }
                }

                ApplyPackge();
                m_lockCount--;
            }
            if (IsDone())
            {
                AssetBundle bundle = mWLoad.assetBundle;
                data.m_res   = bundle.LoadAsset(sfile, typeof(UnityEngine.Object));
                data.m_owner = this;
                //Clean();
                if (!m_isKeepAlive && m_lockCount == 0)
                {
                    GameResMng.GetResMng().AddDelayCleanPackage(this);
                    //Clean();
                }
            }
            else
            {
                Debug.LogError("Open package Failed, URL = " + sUrl);
            }
        }
        m_canCleanCount--;
        data.IsFinish = true;
    }
Beispiel #3
0
    IEnumerator LoadResourceAsyncCallback_Impl(string szfile, LoadResourceCallback callback)
    {
        ResPackge.AsyncLoadData data = new ResPackge.AsyncLoadData();
        IEnumerator             e    = LoadResourceAsync(szfile, data);

        while (true)
        {
            e.MoveNext();
            if (data.IsFinish)
            {
                break;
            }
            yield return(e.Current);
        }
        callback(data.m_res);
    }
Beispiel #4
0
    public IEnumerator LoadPackageAsync(ResPackge.AsyncLoadData data)
    {
        string sUrl = ResPath.WLocalUrl(mFile);

        m_canCleanCount++;
        if (m_state == State.LocalReady)
        {
            if (!IsDone() && m_state == State.LocalReady)
            {
//				float t = Time.realtimeSinceStartup;
                Debug.Log("Open package, URL = " + sUrl);
                if (mWLoad == null)
                {
                    mWLoad = new WWW(sUrl);
                }
                m_lockCount++;
                yield return(mWLoad);

                //yield return new WaitForSeconds(1);
                if (null != mWLoad.error)
                {
                    m_state = State.Failed;
                    Debug.LogError(mWLoad.error);
                }

                ApplyPackge();
                m_lockCount--;
            }
            if (IsDone())
            {
            }
            else
            {
                Debug.LogError("Open package Failed, URL = " + sUrl);
            }
        }
        m_canCleanCount--;
        data.IsFinish = true;
    }
Beispiel #5
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();
        }
    }
Beispiel #6
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);
            }
        }
    }