//---------------------------------------------------------------------------- public sAssetInfo ParseResourseList(ref XmlElement element, EAssetType type = EAssetType.eGameObject) { sAssetInfo info = sAssetInfo.zero; info.strID = element.GetAttribute("id"); info.assetName = element.GetAttribute("name"); if (!string.IsNullOrEmpty(info.assetName)) { info.strName = ParseName(info.assetName); } info.strFile = element.GetAttribute("file").ToLower(); info.strRealFile = element.GetAttribute("file").ToLower(); if (string.IsNullOrEmpty(info.strName)) { info.strName = ParseName(info.strFile); } if (string.IsNullOrEmpty(info.assetName)) { info.assetName = info.strName; } info.bundleName = ParseName(info.strFile); info.bPreLoad = InitToBool(element.GetAttribute("preload")); info.eAssetType = type; if (element.HasAttribute("EnvirUse")) { info.ParseEnvir(element.GetAttribute("EnvirUse")); } else { info.ParseEnvir(""); } return(info); }
//---------------------------------------------------------------------------- public sAssetInfo InsertResourseList(ref XmlElement element, EAssetType type = EAssetType.eGameObject) { sAssetInfo info = ParseResourseList(ref element, type); AddElement(ref m_dicResourseList, info.strID, info); return(info); }
//---------------------------------------------------------------------------- public bool StartLoad <T, U>(string strAssetID, Callback <T, U> result) { if (m_state != FileSystemState.File_OK) { Debug.LogError("StartLoad m_state " + m_state.ToString() + " " + strAssetID + "! FileSystemState.File_OK"); return(false); } if (result == null) { Debug.LogError(string.Format("{0} is not hava callback!", strAssetID)); return(false); } sAssetInfo info = sAssetInfo.zero; m_ResourceList.GetAssetBundleInfo(strAssetID, ref info); if (string.IsNullOrEmpty(info.strFile)) { Debug.LogError(strAssetID + " Is not exist in anywhere"); return(false); } UnityEngine.Object obj = assetsManager.GetAssetObjByID(strAssetID); if (obj != null) { Callback <string, object> callback = result as Callback <string, object>; callback(strAssetID, obj); return(true); } AssetBundle bundle = null; if (m_assetBundleDict.TryGetValue(info.strFile, out bundle)) { Callback <string, UnityEngine.Object> callback = result as Callback <string, UnityEngine.Object>; string loadAssetName = string.IsNullOrEmpty(info.assetName) ? info.strName : info.assetName; UnityEngine.Object[] objlist = bundle.LoadAllAssets(); var count = objlist.Length; for (int i = 0; i < objlist.Length; i++) { ProcessAsset(strAssetID, objlist[i], callback, info.eAssetType, count, i); ProcessStreamedAsset(info, objlist[i], bundle); } } else { sNeedLoadData needLoad; needLoad.strAssetID = strAssetID; needLoad.callback = result as Callback <string, UnityEngine.Object>; m_queueNeedLoad.Enqueue(needLoad); m_bHaveNeedLoad = true; } return(true); }
//---------------------------------------------------------------------------- public bool IsPreLoadView() { ResourceListData data = FileSystem.Instance().GetResData(); if (data == null) { return(false); } sAssetInfo info = sAssetInfo.zero; data.GetAssetBundleInfo(strAssetID, ref info); return(info.bPreLoad); }
//---------------------------------------------------------------------------- private void AddUseAtlas() { m_bHasAddAtlas = true; ResourceListData data = FileSystem.Instance().GetResData(); sAssetInfo info = sAssetInfo.zero; data.GetAssetBundleInfo(strAssetID, ref info); if (info.childListAssetID != null && info.childListAssetID.Count > 0) { int nTotalCount = info.childListAssetID.Count; for (int i = 0; i < nTotalCount; i++) { m_uiSystem.AddUseAtlas(info.childListAssetID[i]); } } }
//---------------------------------------------------------------------------- public virtual void StageLoadViewer() { m_uiSystem.AddPreLoadAsset(strAssetID); ResourceListData data = FileSystem.Instance().GetResData(); sAssetInfo info = sAssetInfo.zero; data.GetAssetBundleInfo(strAssetID, ref info); if (info.childListAssetID != null && info.childListAssetID.Count > 0) { int nTotalCount = info.childListAssetID.Count; for (int i = 0; i < nTotalCount; i++) { m_uiSystem.AddPreLoadAsset(info.childListAssetID[i]); m_uiSystem.AddUseAtlas(info.childListAssetID[i]); } } m_bHasAddAtlas = true; }
//---------------------------------------------------------------------------- public void ProcessStreamedAsset(sAssetInfo info, UnityEngine.Object objAsset, AssetBundle bundle) { if (string.IsNullOrEmpty(info.strFile) || objAsset == null || bundle == null) { return; } if (info.eAssetType == EAssetType.eAudio) { AudioClip clip = objAsset as AudioClip; if (clip.loadType == AudioClipLoadType.Streaming) { if (!m_audioAssetList.Contains(info.strFile)) { m_audioAssetList.Add(info.strFile); } assetsManager.AddAssetBundleList(info.strID, bundle); } } }
//---------------------------------------------------------------------------- public void GetAssetInfo(string strID, ref sAssetInfo info) { m_data.GetAssetBundleInfo(strID, ref info); }
//---------------------------------------------------------------------------- public void GetAssetBundleInfo(string strID, ref sAssetInfo info) { m_dicResourseList.TryGetValue(strID, out info); }
//---------------------------------------------------------------------------- private bool InitResourseListFile(string xmlData) { string XmlData = xmlData; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(XmlData); XmlNode node = xmlDoc.SelectSingleNode("Resourselist"); if (node != null) { XmlNodeList nodeList = node.SelectSingleNode("deps").ChildNodes; int nNodeCount = nodeList.Count; for (int i = 0; i < nNodeCount; ++i) { XmlElement element = nodeList[i] as XmlElement; sAssetInfo info = InsertResourseList(ref element); info.bAlwaysCache = true; m_dicResourseList[info.strID] = info; m_gameInitPreLoadRes.Add(element.GetAttribute("id")); } nodeList = node.SelectSingleNode("uitexture").ChildNodes; nNodeCount = nodeList.Count; for (int i = 0; i < nNodeCount; i++) { XmlElement element = nodeList[i] as XmlElement; InsertResourseList(ref element, EAssetType.eTexture); } nodeList = node.SelectSingleNode("ui").ChildNodes; nNodeCount = nodeList.Count; for (int i = 0; i < nNodeCount; i++) { XmlElement element = null; if (nodeList[i].Name.Equals("Atlas")) { XmlNodeList AtlasList = nodeList[i].ChildNodes; int nAtlasCount = AtlasList.Count; for (int j = 0; j < nAtlasCount; j++) { element = AtlasList[j] as XmlElement; InsertResourseList(ref element, EAssetType.eAtlas); } } else { element = nodeList[i] as XmlElement; sAssetInfo info = InsertResourseList(ref element); string strFile = info.strFile; int indexBegin = strFile.LastIndexOf("/") + 1; int indexEnd = strFile.LastIndexOf("."); int Length = indexEnd - indexBegin; if (Length > 0) { string id = strFile.Substring(indexBegin, indexEnd - indexBegin); if (m_dictResourseList_1 != null && m_dictResourseList_1.ContainsKey(id)) { List <string> list = m_dictResourseList_1[id]; int nCount = list.Count; for (int j = 0; j < nCount; j++) { if (m_dicResourseList.ContainsKey(info.strID)) { m_dicResourseList[info.strID].childListAssetID.Add(list[j]); } } } } } } } return(true); }
//---------------------------------------------------------------------------- private void StartLoad(sNeedLoadData needLoad) { string strAssetID = needLoad.strAssetID; UnityEngine.Object obj = assetsManager.GetAssetObjByID(strAssetID); if (obj != null) { Callback <string, UnityEngine.Object> callback = needLoad.callback as Callback <string, UnityEngine.Object>; callback(strAssetID, obj); return; } sAssetInfo info = sAssetInfo.zero; m_ResourceList.GetAssetBundleInfo(strAssetID, ref info); string strBaseDir = GetResDirByPath(info.strFile); string path = info.strFile; if (m_bundleDependenciseDict.ContainsKey(path)) { List <string> strDependecise = m_bundleDependenciseDict[path]; for (int i = 0; i < strDependecise.Count; i++) { if (!m_assetBundleDict.ContainsKey(strDependecise[i])) { AssetBundle tempBundle = AssetBundle.LoadFromFile(GetResPathByName(strDependecise[i])); if (tempBundle != null) { m_assetBundleDict.Add(strDependecise[i], tempBundle); } else { Debug.LogErrorFormat("资源加载失败:{0}", strDependecise[i]); } } } path = strBaseDir + path; AssetBundle bundle = null; if (!m_assetBundleDict.ContainsKey(info.strFile)) { bundle = AssetBundle.LoadFromFile(path); if (bundle != null) { m_assetBundleDict.Add(info.strFile, bundle); } else { Debug.LogErrorFormat("资源加载失败:{0}", path); } } else { bundle = m_assetBundleDict[info.strFile]; } string loadAssetName = string.IsNullOrEmpty(info.assetName) ? info.strName : info.assetName; UnityEngine.Object[] tempObjList = bundle.LoadAllAssets(); var count = tempObjList.Length; for (int i = 0; i < tempObjList.Length; i++) { ProcessAsset(strAssetID, tempObjList[i], needLoad.callback, info.eAssetType, count, i); ProcessStreamedAsset(info, tempObjList[i], bundle); } return; } needLoad.callback?.Invoke(strAssetID, null); Debug.LogError("配置了不存在的资源:" + path); return; }