//添加一个节点到头部 public MDoubleLinkedListNode <T> AddToHead(T t) { MDoubleLinkedListNode <T> mDoubleLinkedListNode = mDoubleLinkedListNodePool.Spawn(true); mDoubleLinkedListNode.m_prev = null; mDoubleLinkedListNode.m_next = null; mDoubleLinkedListNode.m_t = t; return(AddToHead(mDoubleLinkedListNode)); }
//根据单个AbName 加载AB private AssetBundle LoadAssetBundle(string assetBundleName) { MAssetBundleItem assetBundleItem = null; uint crc = MCrcHelper.GetCRC32(assetBundleName); if (!m_assetBundleItemDic.TryGetValue(crc, out assetBundleItem)) { AssetBundle assetBundle = null; string fullPath = MPathUtils.ASSETBUNDLE_PATH + "/" + assetBundleName; if (File.Exists(fullPath)) { assetBundle = AssetBundle.LoadFromFile(fullPath); } if (assetBundle == null) { MDebug.singleton.AddErrorLog("没有找到这个AssetBundle " + assetBundleName); } assetBundleItem = m_assetBundleItemPool.Spawn(true); assetBundleItem.assetBundle = assetBundle; assetBundleItem.refCount++; m_assetBundleItemDic.Add(crc, assetBundleItem); } else { assetBundleItem.refCount++; } return(assetBundleItem.assetBundle); }
/// <summary> /// 同步加载GameObject的方法 /// </summary> /// <returns>The game obeject.</returns> /// <param name="resPath">资源路径</param> /// <param name="isSetToDefault">是否实例化到默认节点</param> /// <param name="isChangeSceneClear">在切换场景的时候是否清楚资源的缓存</param> public GameObject InstantiateGameObeject(string resPath, bool isSetToDefault = false, bool isChangeSceneClear = true) { uint crc = MCrcHelper.GetCRC32(resPath); MResourceObjectItem mResourceObjectItem = GetObjectFromPool(crc); if (mResourceObjectItem == null) { mResourceObjectItem = m_resourceObjectClssPool.Spawn(true); mResourceObjectItem.m_crc = crc; mResourceObjectItem.m_isClear = isChangeSceneClear; mResourceObjectItem = MResourceManager.singleton.LoadToResourceObject(resPath, mResourceObjectItem); if (mResourceObjectItem.m_resItem.m_object != null) { mResourceObjectItem.m_cloneObeject = (GameObject)Object.Instantiate(mResourceObjectItem.m_resItem.m_object); mResourceObjectItem.m_instanceId = mResourceObjectItem.m_cloneObeject.GetInstanceID(); mResourceObjectItem.m_resOffLineData = mResourceObjectItem.m_cloneObeject.GetComponent <MResOffLineDataBase>(); } } if (isSetToDefault) { mResourceObjectItem.m_cloneObeject.transform.SetParent(DefaultObjectTrans, false); } if (!m_resourceObjectDic.ContainsKey(mResourceObjectItem.m_instanceId)) { m_resourceObjectDic.Add(mResourceObjectItem.m_instanceId, mResourceObjectItem); } return(mResourceObjectItem.m_cloneObeject); }
/// <summary> /// 异步加载资源 仅加载不需要实例化的资源 音频 图片等等 /// </summary> public void AsyncLoadResource(string resPath, OnAsyncLoadFinished onAsyncLoadFinished, LoadResPriority loadResPriority, object[] parms = null) { if (string.IsNullOrEmpty(resPath)) { return; } uint crc = MCrcHelper.GetCRC32(resPath); MResourceItem mResourceItem = GetCacheResourceItem(crc); if (mResourceItem != null && mResourceItem.m_object != null) { if (onAsyncLoadFinished != null) { onAsyncLoadFinished(resPath, mResourceItem.m_object, parms); } return; } //判断下对象是不是在加载中 AsyncLoadResParam asyncLoadResParam = null; if (!m_asyncLoadingAssetDic.TryGetValue(crc, out asyncLoadResParam) || asyncLoadResParam == null) { asyncLoadResParam = m_asyncLoadResParamPool.Spawn(true); asyncLoadResParam.m_crc = crc; asyncLoadResParam.m_resPath = resPath; asyncLoadResParam.m_loadResPriority = loadResPriority; //结果保存 m_asyncAssetLoadingList[(int)loadResPriority].Add(asyncLoadResParam); m_asyncLoadingAssetDic.Add(crc, asyncLoadResParam); } //添加回调 AsyncCallBack m_asyncCallBack = m_asyncCallBackPool.Spawn(true); m_asyncCallBack.m_onAsyncLoadFinished = onAsyncLoadFinished; m_asyncCallBack.m_parms = parms; asyncLoadResParam.m_asyncCallBacks.Add(m_asyncCallBack); }