//异步资源加载----------------------------------------------------------------------------------- /// <summary> /// 异步加载资源 /// </summary> /// <param name="path">资源路径</param> /// <param name="finishCallBack">完成后回调</param> /// <param name="loadPriority">加载优先级</param> /// <param name="param1">回调参数1</param> /// <param name="param2">回调参数2</param> /// <param name="param3">回调参数3</param> public void AsyncLoadResource(string path, OnAsyncFinishCallBack finishCallBack, LoadPriority loadPriority, bool isSprite = false, object param1 = null, object param2 = null, object param3 = null) { uint crc = CRC32.GetCRC32(path); ResourceItem item = GetCacheResourceItem(crc); if (item != null) { finishCallBack?.Invoke(path, item.m_Obj, param1, param2, param3); return; } //判断当前要加载的资源是否已存在加载列表中,不存在,则加入加载列表 AsyncLoadResParam param = null; if (!m_LoadingAssetDict.TryGetValue(crc, out param) || param == null) { param = m_AsyncLoadResPool.Spawn(); param.m_Crc = crc; param.m_Path = path; param.m_Priority = loadPriority; param.m_IsSprite = isSprite; m_LoadAsyncResList[(int)loadPriority].Add(param); m_LoadingAssetDict.Add(crc, param); } //回调列表里添加回调 AsyncCallBack asyncCallBack = m_AsyncCallBackPool.Spawn(); asyncCallBack.finishCallBack = finishCallBack; asyncCallBack.param1 = param1; asyncCallBack.param2 = param2; asyncCallBack.param3 = param3; param.callBackList.Add(asyncCallBack); }
/// <summary> /// 异步加载实例化物体 /// </summary> /// <param name="path">物体路径</param> /// <param name="finishCallBack">完成后的回调</param> /// <param name="loadPriority">加载优先级</param> /// <param name="isSceneParant">是否存放在默认场景父亲下(这里跳转场景不会清除)</param> /// <param name="isClear">该物体跳转场景是否清除</param> /// <param name="param1">回调参数1</param> /// <param name="param2">回调参数2</param> /// <param name="param3">回调参数3</param> public void InstantiateObjectAsync(string path, OnAsyncFinishCallBack finishCallBack, LoadPriority loadPriority, bool isSceneParant = false, bool isClear = true, object param1 = null, object param2 = null, object param3 = null) { if (string.IsNullOrEmpty(path)) { return; } uint crc = CRC32.GetCRC32(path); ResourceObject resObj = GetObjectFromPool(crc); if (resObj != null) { resObj.m_Already = false; resObj.m_IsClear = isClear; m_AsyncResObjectDict.Add(resObj.m_GameObj.GetInstanceID(), resObj); if (isSceneParant) { resObj.m_GameObj.transform.SetParent(m_SceneParentNode, false); } finishCallBack?.Invoke(path, resObj.m_GameObj, param1, param2, param3); return; } resObj = m_ResObjPool.Spawn(); resObj.m_IsClear = isClear; resObj.m_FinishCallBack = finishCallBack; resObj.m_Crc = crc; resObj.m_IsSceneParent = isSceneParant; resObj.m_LoadPriority = loadPriority; resObj.m_Param1 = param1; resObj.m_Param2 = param2; resObj.m_Param3 = param3; ResourceManager.Instance.AsyncLoadResObj(path, resObj, OnAysncResObjCallBack); }
public void Reset() { finishCallBack = null; resFinshCallBack = null; resObj = null; param1 = null; param2 = null; param3 = null; }
public void Reset() { m_Crc = 0; m_ResItem = null; m_GameObj = null; m_IsClear = true; m_Already = false; m_LoadPriority = LoadPriority.RES_LOWER; m_FinishCallBack = null; m_Param1 = m_Param2 = m_Param3 = null; m_OfflineData = null; }