/// <summary> /// 添加自己依赖的资源 /// </summary> /// <param name="assets"></param> public void AddSelfDependent(AssetsBundle assets) { if (!m_selfDependent.Contains(assets)) { m_selfDependent.Add(assets); } }
/// <summary> /// 添加依赖本对象的资源 /// </summary> /// <param name="assets"></param> public void AddDependentSelf(AssetsBundle assets) { if (!m_dependentSelf.Contains(assets)) { m_dependentSelf.Add(assets); } }
/// <summary> /// /// </summary> /// <param name="path"></param> /// <param name="action"></param> /// <param name="dic"></param> private AsyncAsset AssetBundleAsyncLoadDependent(string path, Action <bool, AsyncAsset> complete, Action <bool, AsyncAsset> action, bool dependence, Dictionary <string, AsyncAsset> dic) { // 依赖加载 AssetsBundle[] dependent = null; if (dependence) { string assetBundleName = "data/" + GetAssetBundleName(path); var data = m_getDependentAsset(assetBundleName); dependent = new AssetsBundle[data.Count]; for (int i = 0; i < data.Count; ++i) { dependent[i] = (AssetsBundle)AssetBundleAsyncLoadDependent(path.Replace(assetBundleName, data[i]), action, action, dependence, dic); } } // 加载本资源 AssetsBundle asset = (AssetsBundle)AssetBundleAsyncLoadWithoutDependent(path, complete); if (null != dic) { dic.Add(path, asset); } // 计算依赖关系 if (dependence && dependent != null) { for (int i = 0; i < dependent.Length; ++i) { dependent[i].AddDependentSelf(asset); asset.AddSelfDependent(dependent[i]); } } return(asset); }
/// <summary> /// AssetBundle加载 /// </summary> /// <param name="url"></param> /// <returns></returns> public AsyncAsset AssetBundleLoad(string path) { // 依赖加载 string assetBundleName = "data/" + GetAssetBundleName(path); var data = m_getDependentAsset(assetBundleName); AssetsBundle[] dependent = new AssetsBundle[data.Count]; for (int i = 0; i < data.Count; ++i) { dependent[i] = (AssetsBundle)AssetBundleLoad(path.Replace(assetBundleName, data[i])); } AsyncAsset async = null; if (m_complete.ContainsKey(path)) { async = m_complete[path]; } else { if (m_loading.ContainsKey(path)) { async = m_loading[path]; } else { async = new AssetsBundle(path); async.AsyncLoad(); } while (!async.isDone) { } async.Complete(); m_complete.Add(async.url, async); // 计算依赖关系 if (dependent != null) { for (int i = 0; i < dependent.Length; ++i) { dependent[i].AddDependentSelf((AssetsBundle)async); ((AssetsBundle)async).AddSelfDependent(dependent[i]); } } } return(async); }
/// <summary> /// AssetBundle资源加载 /// </summary> /// <param name="path"></param> /// <param name="action"></param> /// <returns></returns> private AsyncAsset AssetBundleAsyncLoadWithoutDependent(string path, Action <bool, AsyncAsset> action) { AsyncAsset async = null; if (m_complete.ContainsKey(path)) { async = m_complete[path]; } else { if (m_loading.ContainsKey(path)) { async = m_loading[path]; } else { async = new AssetsBundle(path); m_loading.Add(async.url, async); } } m_queue.Add(new AsyncAssetBundle(async, action)); return(async); }