ResourceManagerImpl GetMgr(IResource.EResourceType type) { ResourceManagerImpl mgr = null; if (m_dicResourcesImpl.TryGetValue(type, out mgr)) { return(mgr); } mgr = new ResourceManagerImpl(); m_dicResourcesImpl.Add(type, mgr); return(mgr); }
public IResource CreateResource(IResource.EResourceType eType, ResourceManagerImpl mgr, TaskPriority ePriority = TaskPriority.TaskPriority_Normal) { IResource res = null; s_ResouceIDSeed++; switch (eType) { case IResource.EResourceType.EResourceType_AssetBundle: res = new AssetBundleResource(GetMgr(eType), s_ResouceIDSeed); break; case IResource.EResourceType.EResourceType_Texture: res = new TextureResource(GetMgr(eType), s_ResouceIDSeed); break; } res.SetPriority(ePriority); return(res); }
////////////////////////////////////////////////////////////////////////// /// 方法 /// <summary> /// 加载资源 /// </summary> /// <param name="eType">资源类型</param> /// <param name="strResourceName">资源名称</param> /// <param name="callBack">加载完成回调</param> /// <param name="custemParam">自定义参数</param> /// <param name="rcl">资源缓存等级</param> /// <returns></returns> public IResource GetResource(IResource.EResourceType eType, ref string strResourceName, LoadFinishDelegate callBack, object custumParam = null, IResource.ResourceCacheLevel rcl = IResource.ResourceCacheLevel.ResourceCacheLevel_NULL, TaskPriority ePriority = TaskPriority.TaskPriority_Normal) { if (strResourceName == null) { return(null); } strResourceName = strResourceName.ToLower(); IResource res = null; if (!m_mapResource.TryGetValue(strResourceName, out res)) { if (m_mapIdleResource.TryGetValue(strResourceName, out res)) { m_mapResource.Add(strResourceName, res); m_mapIdleResource.Remove(strResourceName); } } if (res != null) { res.AddRef(); // 缓存等级修正 if (rcl > res.m_eResourceCacheLevel) { res.m_eResourceCacheLevel = rcl; } if (res.m_eState == IResource.EResourceState.EResourceState_Complete) { res.loadFinishCallBack += callBack; res.customParams.Add(custumParam); if (ePriority == TaskPriority.TaskPriority_Immediate) { res.OnFinish(); } else { m_lstCompleteResource.Add(res); } } else { res.loadFinishCallBack += callBack; res.customParams.Add(custumParam); } } else { /// 根据资源后缀名称判定资源类型 res = ResourceManager.Instance().CreateResource(eType, this, ePriority); m_mapResource[strResourceName] = res; res.m_strResName = strResourceName; res.m_strResFileName = strResourceName; res.m_eState = IResource.EResourceState.EResourceState_Loading; res.m_objRes = null; res.m_eResourceCacheLevel = rcl; res.loadFinishCallBack += callBack; res.customParams.Add(custumParam); // 投递资源加载 res.LoadRes(); } return(res); }