Exemple #1
0
    void Start()
    {
        //bool isPlay = Handheld.PlayFullScreenMovie("logo.mp4", Color.black, FullScreenMovieControlMode.CancelOnInput, FullScreenMovieScalingMode.AspectFill);
        //if (!isPlay)
        //{
        //	Debug.LogWarning("Can not play movie");
        //}

        GameObject main = Resources.Load("Prefabs/MainGame") as GameObject;

        if (null != main)
        {
            Load(main, "");
            Debug.Log("Load MainGame from Resources");
            return;
        }
        main = GameResMng.LoadResource(Path + "Prefabs/MainGame.prefab") as GameObject;
        if (null != main)
        {
            Load(main, Path);
            Debug.Log("Load MainGame from " + Path);
            return;
        }

        StartCoroutine(RemoveEffect(0.5f));
    }
Exemple #2
0
    //--------------------------------------------------------------------------------------------
    // 清理未使用的资源
    static public void ClearUnusedRes()
    {
        GameResMng pMng = GameResMng.GetResMng();

        if (null != pMng)
        {
            pMng.NtfClearUnusedRes();
        }
    }
Exemple #3
0
    //--------------------------------------------------------------------------------------------
    static public void SetLoading()
    {
        GameResMng pMng = GetResMng();

        if (pMng != null)
        {
            pMng.mbLoad = false;
        }
    }
Exemple #4
0
    //---------------------------------------------------------------------------------------------------
    //
    // 测试用
    //
    static public void OnResMngGUI()
    {
        GameResMng pMng = GameResMng.GetResMng();

        if (null != pMng)
        {
            pMng.NtfOnResMngGUI();
        }
    }
Exemple #5
0
    //--------------------------------------------------------------------------------------------
    // 统计资源包的总体加载进度[0, 100]
    static public float GetProgress()
    {
        GameResMng pMng = GameResMng.GetResMng();

        if (null != pMng)
        {
            return(pMng.GetCurProgress());
        }
        return(100.0f);
    }
Exemple #6
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));
        }
    }
Exemple #7
0
    //--------------------------------------------------------------------------------------------
    static public bool IsLoaded()
    {
        GameResMng pMng = GameResMng.GetResMng();

        if (null != pMng)
        {
            return(pMng.IsLoadOver());
        }
        return(true);
    }
Exemple #8
0
    //--------------------------------------------------------------------------------------------
    // szfile要求: Assets/ 之后的完整路径(含扩展名), 示例参考顶部说明
    static public UnityEngine.Object LoadResource(string szfileWithoutResources)
    {
        UnityEngine.Object obj = null;

        GameResMng pMng = GetResMng();

        if (null != pMng)
        {
            obj = pMng.NtfLoadResource(szfileWithoutResources);
        }
#if (UNITY_EDITOR) // 编辑模式下
        if (null == obj)
        {
            //Debug.LogWarning("Load Resource Failed:" + szfileWithoutResources);
            //return obj;
        }
#endif

#if (UNITY_EDITOR) // 编辑模式下
        if (null == obj && !ForcePackage)
        {
            obj = AssetDatabase.LoadMainAssetAtPath("Assets/Extends/" + szfileWithoutResources);
        }
        if (null == obj)
        {
            obj = AssetDatabase.LoadMainAssetAtPath("Assets/Resources/" + szfileWithoutResources);
        }
#endif
        if (null == obj)                          // 容错: 也许没有打包或用Unity打包
        {
            string szf  = szfileWithoutResources; // 影射到 Resources/ 目录下
            int    npos = szf.LastIndexOf('.');   // 去掉扩展名
            if (npos > 0)
            {
                szf = szf.Substring(0, npos);
            }
            obj = Resources.Load("Extends/" + szf);
            if (null == obj)
            {
                obj = Resources.Load(szf);
            }
        }


        if (null == obj)
        {
            Debug.LogWarning("Load Resource Failed:" + szfileWithoutResources);
        }
        return(obj);
    }
Exemple #9
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;
    }
Exemple #10
0
 //-------------------------------------------------------------------------------------------------------------------
 //
 // 对外接口
 //
 //--------------------------------------------------------------------------------------------
 // objEntry 用来启动 Coroutine 的
 static public GameResMng CreateResMng(MonoBehaviour objEntry)
 {
     if (mResMng == null)
     {
         mResMng = new GameResMng();
         mResMng.SetEntryAs(objEntry);   // 启动线程用
         //mResMng.StartWWW(false);
     }
     else
     {
         mResMng.SetEntryAs(objEntry);
     }
     return(mResMng);
 }
Exemple #11
0
 // Use this for initialization
 void Start()
 {
     if (null == mLvCtrl)
     {
         float fw = Screen.width;
         float fh = Screen.height;
         float f3 = fh / 3.0f * 2;
         mLvCtrl         = new UIListViewCtrl();
         mLvCtrl.mRctWH  = new Vector2(fw, f3);
         mLvCtrl.mViewWH = new Vector2(fw, f3);
         mLvCtrl.OnClick = GameResMng.TestLoadScene;
     }
     GameResMng.ForcePackage = ForceReadFromPackage;
     GameResMng.CreateResMng(this);
 }
Exemple #12
0
    //--------------------------------------------------------------------------------------------
    public IEnumerator NtfDownOrLoad(bool bLocal)
    {
        GameResMng.SetLoading();
        string sf = ResPath.GetLocal(mFile);

        if (bLocal) // 从本地读取的话要确保资源存在
        {
            try
            {
                if (!File.Exists(sf))   // 本地不存在依然从网上下载
                {
                    bLocal = false;
                }
            }
            catch (Exception exp)
            {
                Debug.LogWarning("Call File.Exists() Er, file = " + sf + ", Msg = " + exp.Message);
            }
        }
        string sUrl = "";

        if (bLocal)
        {
            sUrl = ResPath.WLocalUrl(mFile);
        }
        else // 从网上下载
        {
            sUrl = ResPath.GetUrl(mFile);
        }
        Debug.Log("Download, URL = " + sUrl);
        GameResMng.DebugMsg = "Download, URL = " + sUrl;

        //WWW.LoadFromCacheOrDownload(sUrl,1);//
        mWLoad = new WWW(sUrl);
        yield return(mWLoad);

        if ((!bLocal) && mWLoad.isDone)
        {
            ResPath.SaveToLocal(sf, mWLoad.bytes);
            Clean();
        }
        if (null != mWLoad.error)
        {
            Debug.LogError(mWLoad.error);
        }
        ApplyPackge();
    }
Exemple #13
0
    static public void DrawGui()
    {
        float    fx             = (Screen.width - 400) * 0.5f;
        float    fy             = (Screen.height - 95);
        float    fProg          = GameResMng.GetProgress();
        int      bytesPersecond = GameResMng.GetResMng().GetDownloadBytesPerSecond();
        float    kbPerSecond    = bytesPersecond / 1024.0f;
        GUIStyle st             = new GUIStyle();

        st.fontSize         = 24;
        st.normal.textColor = UnityEngine.Color.black;
        if (GameResMng.GetResMng().m_failedDownloadPackage.Count != 0 &&
            GameResMng.GetResMng().IsDownloadQueueEmpty)
        {
        }
        else
        {
            string msg = string.Format("資源包下載中 --- {0:###.##}%    {1:.##}KB/S", fProg, kbPerSecond);
            GUI.Label(new Rect(fx, fy, 400, 95), msg, st);
        }
    }
Exemple #14
0
 void OnGUI()
 {
     //GUI.Slider();
     GameResMng.OnResMngGUI();
     if (null != mLvCtrl)
     {
         mLvCtrl.mRctWH.x  = Screen.width;
         mLvCtrl.mViewWH.x = Screen.width;
         float py = Screen.height - mLvCtrl.mRctWH.y;
         mLvCtrl.OnDrawListView(0, py);
     }
     if (!GameResMng.IsLoaded())
     {
         float fx = (Screen.width - 300) * 0.5f;
         float fy = (Screen.height - 60);
         float fw = Screen.width * 0.8f;
         fx = (Screen.width - fw) * 0.5f;
         float fProg = GameResMng.GetProgress();
         GUI.Label(new Rect(fx, fy, 300, 80), @"进度: " + fProg + "%");
         //GUI.HorizontalScrollbar (new Rect (fx, fy, fw, 30), fProg, 1.0f, 0.0f, 100.0f);
     }
 }
Exemple #15
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());
                }
            }
        }
    }
Exemple #16
0
    public IEnumerator TryDownload(bool isClean, bool forceDownload)
    {
        if (mWLoad != null)
        {
            yield break;
        }
        GameResMng.SetLoading();
        string sf             = ResPath.GetLocal(mFile);
        bool   isNeedDownload = forceDownload;

        try
        {
            if (!File.Exists(sf))   // 本地不存在依然从网上下载
            {
                isNeedDownload = true;
                m_state        = State.Downloading;
            }
            else if (isClean)
            {
                m_state = State.LocalReady;
            }
        }
        catch (Exception exp)
        {
            Debug.LogWarning("Call File.Exists() Er, file = " + sf + ", Msg = " + exp.Message);
        }
        string sUrl = "";

        if (isNeedDownload || !isClean)
        {
            if (isNeedDownload)
            {
                sUrl = ResPath.GetUrl(mFile);
            }
            else
            {
                sUrl = ResPath.WLocalUrl(mFile);
            }
            Debug.Log("BeginDownload, URL = " + sUrl);
            GameResMng.DebugMsg = "Download, URL = " + sUrl;
            m_state             = State.Downloading;
            mWLoad = new WWW(sUrl);
            yield return(mWLoad);

            if (null != mWLoad.error)
            {
                m_state = State.Failed;
                Debug.LogError("Error, URL = " + sUrl + "   " + mWLoad.error);
                GameResMng.GetResMng().OnPackageDownloadFailed(mFile);
            }
            else if (IsDone())
            {
                m_state = State.LocalReady;
                if (isNeedDownload)
                {
                    ResPath.SaveToLocal(sf, mWLoad.bytes);
                }
                GameResMng.GetResMng().OnPackageDownload(mFile, mWLoad.bytes.Length);
            }
            if (isClean)
            {
                Clean();
                Resources.UnloadUnusedAssets();
                GC.Collect();
            }
            string msg = "EndDownload, URL = " + sUrl;
            if (isClean)
            {
                msg += "[Clean]";
            }
            Debug.Log(msg);
            //
        }
        ApplyPackge();
    }
Exemple #17
0
    void NtfOnResMngGUI()
    {
#if (MY_DEBUG) // 显示出来
        UIListViewCtrl LvCtrl = m_lvCtrl;
        if (LvCtrl == null)
        {
            return;
        }
        if (LvCtrl.IsEmpty())
        {
            AddReToViewCtrl();
        }
#endif
        float fy  = 5.0f;
        float flw = Screen.width - 80;
        if (GUI.Button(new Rect(flw, fy, 80, 20), @"本地资源"))
        {
            mResMng.StartWWW(true);
        }
        if (GUI.Button(new Rect(flw - 80, fy, 80, 20), @"网络资源"))
        {
            mResMng.StartWWW(false);
        }

        fy += 40;
        //GUI.Label(new Rect( 0, fy, Screen.width, 20), @"调试信息:" + GameResMng.DebugMsg);

        //fy += 40;
        //mResTest = GUI.TextField(new Rect( 0, fy, 400, 20), mResTest);

        if (GUI.Button(new Rect(410, fy, 40, 20), @"查找"))
        {
            mMsg = "";
            UnityEngine.Object myObj = LoadResource(mResTest);
            if (myObj == null)
            {
                string szMsg = @"加载失败: " + mResTest;
                Debug.Log(szMsg);
            }
            else
            {
                Debug.Log("myObj = " + myObj.name);
            }
        }

        if (GUI.Button(new Rect(460, fy, 40, 20), @"清除"))
        {
            mMsg     = "";
            mResTest = "";
        }

        if (GUI.Button(new Rect(510, fy, 40, 20), @"测试"))
        {
            if (null != mResDic)
            {
                OnTestPack();
            }
        }
        if (GUI.Button(new Rect(560, fy, 40, 20), @"场景"))
        {
            GameResMng pMng = GameResMng.GetResMng();
            if (pMng != null)
            {
                pMng.LoadSceneCallback(mResTest, null);
            }
        }
        if (GUI.Button(new Rect(610, fy, 40, 20), @"列表"))
        {
            OnListPackFiles();
        }

        //fy += 40;
        //GUI.Label(new Rect( 0, fy, Screen.width, 20), @"提示消息:" + mMsg);
    }