public SDictionary <int, UnityEngine.Object> LoadAll(string bundleName, ELoadType loadType) { if (string.IsNullOrEmpty(bundleName)) { return(null); } LoadedAssetBundle loaded = ABManager.Instance.GetLoadedBundle(bundleName.GetHashCode()); if (loaded != null) { loaded.Count(); } else { loaded = LoadSyn(bundleName); } if (loaded != null) { loaded.mLoadType = loadType; if (loaded.mAssetBundle != null) { loaded.MapAssets(); ABManager.Instance.AfterLoad(loaded); } return(loaded.GetAllAssets()); } return(null); }
public static void SetActive(GameObject obj, bool state, ELoadType loadType = ELoadType.Max) { //obj.SetActive(state); switch (loadType) { case ELoadType.Sound: obj.SetActive(state); break; case ELoadType.Effect: obj.SetActive(state); break; default: if (state) { obj.transform.position = Vector3.zero; } else { obj.transform.position = InvalidPosition; } break; } }
public void DeSpawn(ELoadType loadType, GameObject Instance, bool bImediate = false) { SpawnPool pool = null; if (m_Pools == null) { Debug.Log("Despaw() Instance.name:" + Instance.name + " m_Pools had destroyed"); return; } if (m_Pools.TryGetValue(loadType, out pool)) { if (pool != null && pool.isActiveAndEnabled && Instance != null) { Instance.transform.parent = pool.transform; if (!bImediate && pool.delayDelTime > 0.0f) { pool.Despawn(Instance, pool.delayDelTime); } else { pool.Despawn(Instance); } } } }
public void UnLoad(string bundleName, ELoadType loadType, bool unloadAllLoadedObjects = false) // ELoadType { string strFullBundleName = BundleLoaderManager.GetBundleName(bundleName, loadType); int nBundleId = strFullBundleName.GetHashCode(); //Debug.Log("<color=yellow>资源:bundleName: " + strFullBundleName + "</color>"); BundleLoaderManager.Instance.UnloadAssetBundle(nBundleId, unloadAllLoadedObjects); }
//获取实例化资源的地方(同步方式加载预设) public GameObject RGet(string bundleName, string assetName, ELoadType loadType, GameObject parent = null) { if (string.IsNullOrEmpty(bundleName)) { return(null); } string strFullBundleName = BundleLoaderManager.GetBundleName(bundleName, loadType); string strFullAssetName = BundleLoaderManager.GetAssertName(bundleName, assetName, ABPathHelper.PrefabSuffix, loadType); //Debug.Log("<color=yellow>资源:bundleName: " + strFullBundleName + " assetName: " + strFullAssetName + "</color>"); Object source = null; #if UNITY_EDITOR if (GameUtils.ScriptLoad && loadType == ELoadType.UI) { source = UnityEditor.AssetDatabase.LoadAssetAtPath(strFullAssetName, typeof(UnityEngine.Object)); } else #endif { source = BundleLoaderManager.Instance.Load(strFullBundleName, strFullAssetName, loadType); } if (source is GameObject) { GameObject go = GameObject.Instantiate(source) as GameObject; MaterialUtils.ResetGameObjectMaterials(go); if (loadType == ELoadType.UI) { AutoDestroy autoDestroyCom = go.GetComponent <AutoDestroy>(); if (autoDestroyCom == null) { autoDestroyCom = go.AddComponent <AutoDestroy>(); } } go.name = go.name.Replace("(Clone)", ""); int nBundleId = strFullBundleName.GetHashCode(); m_AllGameObjects.Add(go, nBundleId); if (parent != null) { go.transform.parent = parent.transform; go.transform.localPosition = Vector3.zero; go.transform.localScale = Vector3.one; go.transform.localRotation = Quaternion.identity; } return(go); } else { Debug.Log("<color=red> object is null: " + strFullAssetName + "\n" + "</color>"); } return(null); }
public Object Load(string bundleName, string assetName, ELoadType loadType) { if (string.IsNullOrEmpty(bundleName)) { return(null); } int nHashCode = bundleName.GetHashCode(); LoadedAssetBundle loaded = ABManager.Instance.GetLoadedBundle(nHashCode); if (loaded != null) { loaded.Count(); } else { loaded = LoadSyn(bundleName); } if (loaded != null) { loaded.mLoadType = loadType; Object asset = null; if (loaded.mAssetBundle != null) { AssetBundle ab = loaded.mAssetBundle; if (string.IsNullOrEmpty(assetName)) { asset = ab.mainAsset != null ? ab.mainAsset : ab.LoadAsset(ab.GetAllAssetNames()[0]); if (asset != null) { loaded.SetMainAsset(asset); } } else { loaded.MapAssets(); asset = loaded.LoadAsset(assetName); } ABManager.Instance.AfterLoad(loaded); //Debug.Log("<color=yellow>assetName:" + assetName + "</color>"); } else { asset = loaded.LoadAsset(assetName); //Debug.Log("<color=red>assetName:"+ assetName + "</color>"); } return(asset); } return(null); }
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 SpawnPool CreateSpawnPool(ELoadType loadType, float fDelayDelTime) { if (!m_Pools.ContainsKey(loadType)) { GameObject owner = new GameObject(loadType.ToString()); owner.transform.parent = this.transform; m_Pools[loadType] = owner.AddComponent <SpawnPool>(); m_Pools[loadType].loadType = loadType; m_Pools[loadType].delayDelTime = fDelayDelTime; m_Pools[loadType].dontDestroyOnLoad = true; m_Pools[loadType].Init(); } return(m_Pools[loadType]); }
public bool DestroySpawnPool(ELoadType type) { SpawnPool spawnPool = null; if (m_Pools.TryGetValue(type, out spawnPool)) { // The rest of the logic will be handled by OnDestroy() in SpawnPool if (spawnPool != null) { spawnPool.Destroy(); } return(true); } //Debug.Log(string.Format("PoolManager: Unable to destroy '{0}'. Not in PoolManager", type.ToString())); return(false); }
public void LoadTexture(ELoadType loadType) { switch (loadType) { case ELoadType.Res: var path = TextureResPath.CombinePath(TextureName.Trim()); var texture = ImageController.LoadLocalImage(path); //Resources.Load<Texture2D>(TextureName); FinishedLoadTexture(texture, 0); break; case ELoadType.Url: Debug.LogError(TextureName); // ImageController.LoadImageFromUrl(TextureName, FinishedLoadTexture); AsyncImage.Instance.GetAsyncImage(TextureName, FinishedLoadTexture); break; case ELoadType.Request: ImageController.LoadImageFromServerConfig(TextureName, FinishedLoadTexture); break; } }
/// <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 void ResetInfo(string path, AssetManageMode bundleMode, AssetEncryptMode encryption, ELoadType loadType, float delayDelTime) { this.path = path; this.loadType = loadType; this.delayDelTime = delayDelTime; }
public LoadEditorAssetAsync(UnityEngine.Object asset, string path) : base(path) { mainAsset = asset; loadType = ELoadType.Prefab; }
public LoadEditorAssetAsync(string path) : base(path) { loadType = ELoadType.AssetPath; }
private IEnumerator LoadBundleByWWW(string bundleName, DependencsLoader callback, LoadFromType loadFromType, ELoadType loadType = ELoadType.Max) { if (string.IsNullOrEmpty(bundleName)) { yield break; } int nHashCode = bundleName.GetHashCode(); LoadedAssetBundle loaded = ABManager.Instance.GetLoadedBundle(nHashCode); if (loaded != null) { loaded.Count(); yield break; } if (!mLoadingReqs.Contains(nHashCode)) { mLoadingReqs.Add(nHashCode); string strBundleUrl = "file://"; if (loadFromType == LoadFromType.LoadFromDownLoad) { strBundleUrl += ABPathHelper.AssetsURL; } else { strBundleUrl = ABPathHelper.AssetsLocalABURL; } strBundleUrl += bundleName; WWW www = new WWW(strBundleUrl); if (www != null) { while (!www.isDone && string.IsNullOrEmpty(www.error)) { yield return(null); } if (string.IsNullOrEmpty(www.error)) { Debug.Log("<color=yellow>AddLoadedBundle:" + bundleName + "</color> " + Time.realtimeSinceStartup); ABManager.Instance.AddLoadedBundle(nHashCode, www.assetBundle); if (callback != null) { ++callback.mDoneCnt; } } www.Dispose(); } mLoadingReqs.Remove(nHashCode); } yield return(null); }
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()); }
public Object RGetNoInstance(string bundleName, string assetName = "", string suffix = ".prefab", ELoadType loadType = ELoadType.Max) { string strFullBundleName = BundleLoaderManager.GetBundleName(bundleName, loadType); string strFullAssetName = BundleLoaderManager.GetAssertName(bundleName, assetName, suffix, loadType); Object source = BundleLoaderManager.Instance.Load(strFullBundleName, strFullAssetName, loadType); return(source); }
public SDictionary <int, Object> GetBundleObjects(string bundleName, ELoadType loadType) { return(BundleLoaderManager.Instance.LoadAll(bundleName, loadType)); }