//-------------------------------------------------------------------------------------------- // 清理未使用的资源 static public void ClearUnusedRes() { GameResMng pMng = GameResMng.GetResMng(); if (null != pMng) { pMng.NtfClearUnusedRes(); } }
//--------------------------------------------------------------------------------------------------- // // 测试用 // static public void OnResMngGUI() { GameResMng pMng = GameResMng.GetResMng(); if (null != pMng) { pMng.NtfOnResMngGUI(); } }
//-------------------------------------------------------------------------------------------- static public bool IsLoaded() { GameResMng pMng = GameResMng.GetResMng(); if (null != pMng) { return(pMng.IsLoadOver()); } return(true); }
//-------------------------------------------------------------------------------------------- // 统计资源包的总体加载进度[0, 100] static public float GetProgress() { GameResMng pMng = GameResMng.GetResMng(); if (null != pMng) { return(pMng.GetCurProgress()); } return(100.0f); }
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; }
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); } }
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(); }
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); }