async void LoadResAsync(EABType abType, string bundleName) { var tmpResMgr = Game.ResourcesMgr; await tmpResMgr.LoadBundleByTypeAsync(abType, bundleName); if (mIsRelease) { tmpResMgr.UnLoadBundleByType(abType, bundleName); return; } //Logger.Log($"成功加载bundle -> {bundleName} 已成功 -> {mLoadedResCount} 需加载 -> {mNeedLoadResCount}"); //已加载的bundle记录 List <string> tmpBundleNameList = null; if (!mAbType2NameLoadedResDict.TryGetValue((int)abType, out tmpBundleNameList)) { tmpBundleNameList = new List <string>(); mAbType2NameLoadedResDict.Add((int)abType, tmpBundleNameList); } tmpBundleNameList.Add(bundleName); // ++mLoadedResCount; if (mLoadedResCount >= mNeedLoadResCount) { mLoadedHandle?.Invoke(); mLoadedHandle = null; } }
//释放资源 void ReleaseRes(EABType resType = EABType.Invalid, string resName = null) { if (null != mGameObject) { Game.ResourcesMgr.ResPool.Despawn(EABType.Invalid != resType ? resType : this.ResType, null != resName ? resName : this.ResName, mGameObject); mGameObject = null; } }
public GameObject Spawn(EABType resType, string goName) { GameObject tmpGo = null; GameObjectPool tmpGoPool = null; if (mABType2GoPoolDict.TryGetValue(resType, out tmpGoPool)) { tmpGo = tmpGoPool.Spawn(goName); } return(tmpGo); }
public void AddPreLoadRes(EABType type, string bundleName) { List <string> tmpBundleNameList = null; if (!mAbType2NameDict.TryGetValue((int)type, out tmpBundleNameList)) { tmpBundleNameList = new List <string>(); mAbType2NameDict.Add((int)type, tmpBundleNameList); } tmpBundleNameList.Add(bundleName); }
public void Despawn(EABType resType, string goName, GameObject go) { GameObjectPool tmpGoPool = null; if (!mABType2GoPoolDict.TryGetValue(resType, out tmpGoPool)) { GameObject tmpGo = new GameObject(resType.ToString()); tmpGo.transform.SetParent(mRootGo.transform, false); tmpGoPool = new GameObjectPool(tmpGo); mABType2GoPoolDict.Add(resType, tmpGoPool); } tmpGoPool.Despawn(goName, go); }
void ReleaseRes() { if (EABType.Invalid != mResType && !string.IsNullOrEmpty(mResName)) { Game.ResourcesMgr.UnLoadBundleByType(mResType, mResName); mResType = EABType.Invalid; mResName = string.Empty; } if (null != mImage) { mImage.sprite = null; Utility.GameObj.SetActive(mImage, false); } }
public void ClearByType(EABType eABType) { GameObjectPool tmpGoPool = null; if (mABType2GoPoolDict.TryGetValue(eABType, out tmpGoPool)) { tmpGoPool.Clear((name, count) => { for (int i = 0; i < count; ++i) { mResMgr.UnLoadBundleByType(eABType, name); } }); mABType2GoPoolDict.Remove(eABType); } }
//异步加载 async void LoadResAsync(EABType type, string name) { await Game.ResourcesMgr.LoadBundleByTypeAsync(type, name); if (type != mResType || !name.Equals(mResName)) { Game.ResourcesMgr.UnLoadBundleByType(type, name); return; } if (mIsReleased) { ReleaseRes(); return; } OnResLoaded(); }
public void LoadByAbType(EABType type, string name, Image image, Action loadedHandle = null, bool async = true) { mIsReleased = false; mResType = type; mResName = name; mImage = image; mLoadedHandle = loadedHandle; Utility.GameObj.SetActive(image, false); if (async) { LoadResAsync(type, name); } else { LoadResSync(type, name); } }
//重新异步加载资源 private async void ReloadResAsync() { EABType tmpResType = ResType; string tmpResName = ResName; await Game.ResourcesMgr.LoadBundleByTypeAsync(tmpResType, tmpResName); GameObject tmpGo = Game.ResourcesMgr.GetAssetByType <GameObject>(tmpResType, tmpResName); if (null == tmpGo) { return; } tmpGo = Hotfix.Instantiate(tmpGo); InitGameObject(tmpGo); if (mIsInvalid) { ReleaseRes(tmpResType, tmpResName); return; } OnResLoaded(); }
public async Task LoadBundleByTypeAsync(EABType abType, string abName) { await ResMgrBase.Instance.LoadBundleAsync(GetBundleNameByType(abType, abName)); }
public void LoadBundleByType(EABType type, string abName) { ResMgrBase.Instance.LoadBundle(GetBundleNameByType(type, abName)); }
public K GetAssetByType <K>(EABType abType, string bundleName, string assetName) where K : class { return(ResMgrBase.Instance.GetAsset <K>(GetBundleNameByType(abType, bundleName), assetName)); }
public static string GetBundleNameByType(EABType type, string name) { return(string.Format(ABType2Path[(int)type], name)); }
public void LoadBundleByType(EABType type, string abName) { LoadBundle(ResourcesHelper.GetBundleNameByType(type, abName)); }
public async Task LoadBundleByTypeAsync(EABType abType, string abName) { await LoadBundleAsync(ResourcesHelper.GetBundleNameByType(abType, abName)); }
//同步加载 void LoadResSync(EABType type, string name) { Game.ResourcesMgr.LoadBundleByType(type, name); OnResLoaded(); }
public K GetAssetByType <K>(EABType abType, string bundleName) where K : class { return(GetAsset <K>(ResourcesHelper.GetBundleNameByType(abType, bundleName), bundleName)); }