/// <summary> /// 加载模型 /// </summary> /// <param name="SkinID">模型ID</param> /// <param name="strPrefabPath">模型路径</param> /// <returns>是否成功</returns> private static Skin LoadSkinSynchronous(SkinModelInfo info) { Skin reslut = null; //已经有这个皮肤,不加载了 if (m_SkinMap.TryGetValue(info.nSkinID, out reslut)) { return(reslut); } ResNode obj = AssetBundleManager.GetAssets(AssetType.Asset_Prefab, info.strPatch); if (null != obj) { reslut = BuildSkin(info, obj, obj.isAsync); if (reslut != null) { reslut.AddRef(); SkinAsyncLoadingObj asyncObj = null; if (m_AsyncLoadSkinRequestTable.TryGetValue(info.nSkinID, out asyncObj)) { reslut.AddRef(asyncObj.ReferenceCount); asyncObj.ReferenceCount = 0; } } return(reslut); } else { obj = null; Trace.Warning("加载皮肤模型失败,ID:" + info.nSkinID + ",路径:" + info.strPatch + ",请[--策划--]检查配置"); return(reslut); } }
private static void UpdateLoadingSkin() { if (m_AsyncLoadSkinRequestTable.Count <= 0) { return; } LoadCompleteList.Clear(); foreach (KeyValuePair <int, SkinAsyncLoadingObj> var in m_AsyncLoadSkinRequestTable) { Skin sk = null; if (!m_SkinMap.TryGetValue(var.Key, out sk)) { continue; } LoadCompleteList.Add(var.Key); } foreach (int id in LoadCompleteList) { SkinAsyncLoadingObj var = null; m_AsyncLoadSkinRequestTable.TryGetValue(id, out var); m_AsyncLoadSkinRequestTable.Remove(id); Skin sk = null; m_SkinMap.TryGetValue(id, out sk); sk.AddRef(var.ReferenceCount); foreach (System.Action <Skin> callback in var.callbackList) { callback(sk); } } }
/// <summary> /// 取得皮肤 /// </summary> /// <param name="SkinID"></param> /// <param name="sk"></param> /// <returns></returns> public static SkinInstance GetSkin(int SkinID) { if (null == m_SkinConfigMap) { return(null); } Skin Reslut = null; Reslut = GetSkinFromCache(SkinID); if (Reslut != null) { Reslut.AddRef(); m_SkinMap.Add(Reslut.nSkinID, Reslut); return(Reslut.Instantiate_Main()); } //先看看这个皮肤是不是有这个皮肤 if (m_SkinConfigMap.ContainsKey(SkinID)) { //再看看这个皮肤是否被加载了 if (m_SkinMap.ContainsKey(SkinID)) { Reslut = m_SkinMap[SkinID]; Reslut.AddRef(); return(Reslut.Instantiate_Main()); } //没有就加载皮肤 SkinModelInfo info = m_SkinConfigMap[SkinID]; Skin sk = LoadSkinSynchronous(info); if (null != sk && sk.isValid) { return(sk.Instantiate_Main()); } return(null); } else { Trace.LogWarning("找不到皮肤配置,ID:" + SkinID); } return(null); }
/// <summary> /// 异步取得Skin /// </summary> /// <param name="SkinID"></param> /// <param name="CallBack"></param> /// <returns></returns> private static bool GetSkinAsyncImpl(int SkinID, System.Action <Skin> CallBack, AssetLoadPriority priority = AssetLoadPriority.Priority_Normal) { SkinModelInfo info = null; if (!m_SkinConfigMap.TryGetValue(SkinID, out info)) { Debug.LogWarning("找不到皮肤配置,ID:" + SkinID); return(false); } Skin sk = null; SkinAsyncLoadingObj loadingObj = null; sk = GetSkinFromCache(SkinID); if (sk != null) { sk.AddRef(); m_SkinMap.Add(sk.nSkinID, sk); if (m_AsyncLoadSkinRequestTable.TryGetValue(SkinID, out loadingObj)) { loadingObj.callbackList.Add(CallBack); } else { loadingObj = new SkinAsyncLoadingObj(); loadingObj.callbackList.Add(CallBack); m_AsyncLoadSkinRequestTable.Add(SkinID, loadingObj); } return(true); } if (m_SkinMap.TryGetValue(SkinID, out sk)) { if (m_AsyncLoadSkinRequestTable.TryGetValue(SkinID, out loadingObj)) { sk.AddRef(); loadingObj.callbackList.Add(CallBack); } else { loadingObj = new SkinAsyncLoadingObj(); loadingObj.callbackList.Add(CallBack); sk.AddRef(); m_AsyncLoadSkinRequestTable.Add(SkinID, loadingObj); } return(true); } if (m_AsyncLoadSkinRequestTable.TryGetValue(SkinID, out loadingObj)) { loadingObj.ReferenceCount++; loadingObj.callbackList.Add(CallBack); } else { ResNode obj = AssetBundleManager.GetAssetsAsync(AssetType.Asset_Prefab, ResLoadCallBack, info.strPatch, false, info, priority); if (obj != null) { loadingObj = new SkinAsyncLoadingObj(); loadingObj.callbackList.Add(CallBack); loadingObj.ReferenceCount++; loadingObj.loadingResNode = obj; m_AsyncLoadSkinRequestTable.Add(SkinID, loadingObj); } else { Trace.Warning("加载皮肤模型失败,ID:" + info.nSkinID + ",路径:" + info.strPatch + ",请[--策划--]检查配置"); return(false); } } return(true); }