public GameObject Spawn(string bundleName, string assetName, ELoadType loadType, Transform parent = null) { if (string.IsNullOrEmpty(bundleName)) { return(null); } //Debug.Log("<color=red> Spawn: " + bundleName + "/" + fileName + "\n" + "</color>"); SpawnPool pool = null; if (!m_Pools.TryGetValue(loadType, out pool)) { AssetManageInfo info = AssetManageConfigManager.Instance.GetInfo(loadType); pool = CreateSpawnPool(loadType, info.delayDelTime); pool.limitCount = info.limitCount; if (loadType == ELoadType.Effect) { pool.transform.parent = CGameRoot.UIRoot.transform; } } string strFullBundleName = BundleLoaderManager.GetBundleName(bundleName, loadType); string strFullAssetName = BundleLoaderManager.GetAssertName(bundleName, assetName, ABPathHelper.PrefabSuffix, loadType); //Debug.Log("<color=yellow>资源:bundleName: " + strFullBundleName + " assetName: " + strFullAssetName + "</color>"); int nBundleId = strFullBundleName.GetHashCode(); int nAssetId = strFullAssetName.GetHashCode(); PrefabPool prefabPool = pool.GetPrefabPool(nBundleId, nAssetId); GameObject inst = null; if (prefabPool != null && prefabPool.prefab != null) { inst = pool.Spawn(prefabPool.prefab, nBundleId, nAssetId, parent); } else { Object source = BundleLoaderManager.Instance.Load(strFullBundleName, strFullAssetName, loadType); if (source != null) { inst = pool.Spawn(source, nBundleId, nAssetId, parent); } else { Debug.Log("<color=red> object is null: " + strFullAssetName + "\n" + "</color>"); } } return(inst); }
public AssetManageInfo GetInfo(ELoadType loadType) { if (m_Configs == null) { return(AssetManageInfo.Default); } AssetManageInfo info = null; if ((int)loadType < (int)ELoadType.Max) { info = m_Configs[(int)loadType]; } return((info != null) ? info : AssetManageInfo.Default); }
public static string GetAssertName(string bundleName, string assetName, string suffixName, ELoadType loadType) { bundleName = bundleName.ToLower(); m_strFullName.Length = 0; m_strFullName.Capacity = 128; m_strFullName.Append(ABPathHelper.AssetNoResourcePrefix); AssetManageInfo info = AssetManageConfigManager.Instance.GetInfo(loadType); m_strFullName.Append(info.path); m_strFullName.Append(ABPathHelper.Separator); m_strFullName.Append(bundleName); if (!string.IsNullOrEmpty(assetName)) { m_strFullName.Append(ABPathHelper.Separator); m_strFullName.Append(assetName.ToLower()); } m_strFullName.Append(suffixName); return(m_strFullName.ToString()); }
/// <summary> /// 获取ABResource目录下的Bundle目录 /// </summary> /// <param name="bundleName"></param> /// <param name="bGroup"></param> /// <returns></returns> public static string GetBundleName(string bundleName, ELoadType loadType) { bundleName = bundleName.ToLower(); m_strFullName.Length = 0; m_strFullName.Capacity = 128; AssetManageInfo info = AssetManageConfigManager.Instance.GetInfo(loadType); if (info != null && info.loadType == loadType) { if (loadType == ELoadType.Icon) { m_strFullName.Append(ABPathHelper.ABResourcePrefix); } else { m_strFullName.Append(info.path); m_strFullName.Append(ABPathHelper.Separator); } m_strFullName.Append(bundleName); m_strFullName.Append(ABPathHelper.Unity3dSuffix); } return(m_strFullName.ToString()); }
public AssetManageInfo GetInfo(string key) { if (m_Configs == null) { Debug.Log("<color=red> assetmanageconfig file load fail: " + strAssetManageConfigName + ABPathHelper.AssetXmlSuffix + "</color>"); return(AssetManageInfo.Default); } AssetManageInfo info = null; for (int i = 0; i < m_Configs.Length; ++i) { if (m_Configs[i] != null) { if (key.IndexOf(m_Configs[i].path, System.StringComparison.OrdinalIgnoreCase) >= 0) { info = m_Configs[i]; break; } } } return((info != null) ? info : AssetManageInfo.Default); }
private void ToLower(AssetManageInfo info) { info.path = info.path.ToLower(); }
public void AddInfo(AssetManageInfo info) { infos.Add(info); }
public LoadedAssetBundle LoadSyn(string strFullName, UpdateProgress updateFunc = null, bool bSend = false) { LoadedAssetBundle loaded = ABManager.Instance.GetLoadedBundle(strFullName.GetHashCode()); if (loaded != null) { loaded.Count(); return(loaded); } AssetManageInfo info = AssetManageConfigManager.Instance.GetInfo(strFullName); //资源是从DownLoad包里还是StreamAsset的包里读取的 LoadFromType loadFromType = LoadFromType.LoadFromNone; string[] dependencies = null; if (AssetBundleManifest != null && AssetBundleHashSet.Contains(strFullName)) {//是否在下载的包里 loadFromType = LoadFromType.LoadFromDownLoad; dependencies = AssetBundleManifest.GetAllDependencies(strFullName); } else if (LocalABBundleManifest != null && LocalABBundleHashSet.Contains(strFullName)) {//下载的包里找不到就到跟包的目录里寻找一遍看是否有依赖 loadFromType = LoadFromType.LoadFromLocalAB; dependencies = LocalABBundleManifest.GetAllDependencies(strFullName); } //只要不是LoadFromNone,说明这个资源是有身份证的,并非来路不明 if (loadFromType != LoadFromType.LoadFromNone) { int nCnt = 1; if (dependencies != null) { nCnt += dependencies.Length; for (int i = 0; i < dependencies.Length; ++i) { LoadBundleByFileStream(dependencies[i], getLoadFromType(dependencies[i]), AssetEncryptMode.None); if (updateFunc != null) { updateFunc((float)(i + 1) / nCnt, bSend); } } } //Debug.Log("<color=red> LoadSyn: " + strFullName + "</color>"); loaded = LoadBundleByFileStream(strFullName, loadFromType, info.encryption); if (loaded != null) { if (dependencies != null && dependencies.Length > 0) { loaded.AddDpendences(dependencies); } if (info.loadType != ELoadType.Music && info.loadType != ELoadType.Scene) { loaded.MapAssets(); ABManager.Instance.AfterLoad(loaded); } if (updateFunc != null) { updateFunc(1.0f, bSend); } } return(loaded); } else { Debug.Log("<color=red>资源:" + strFullName + "来路不明,在bundle表里不存在。</color>"); return(null); } }