/// <summary> /// 加载资源 /// </summary> /// <param name="assetName"></param> /// <param name="completeCallback"></param> /// <param name="cacheType"></param> /// <param name="cacheTimeout"></param> public void LoadAsset(string assetName, Action <string, UnityEngine.Object> completeCallback = null, BundleCacheType cacheType = BundleCacheType.None, float cacheTimeout = 5) { if (!CheckInited()) { if (completeCallback != null) { completeCallback("", null); } return; } var requestBundleName = m_assetNameToBundleNameMap[assetName]; IncreaseRef(requestBundleName); if (string.IsNullOrEmpty(requestBundleName)) { if (completeCallback != null) { completeCallback("", null); } Debug.LogError("Asset Info " + assetName + " Not Found"); return; } if (m_assetLoading.ContainsKey(assetName))//说明之前有同一个资源的请求 { m_assetLoading[assetName].completeCallbackList.Add(completeCallback); return; } WeakReference weakPtr = null; if (m_assetNameToWeakPtr.TryGetValue(assetName, out weakPtr) && weakPtr.IsAlive) { if (completeCallback != null) { completeCallback(assetName, (UnityEngine.Object)weakPtr.Target); } return; } //由update决定下一帧是读取bundle还是读取asset var assetLoader = new KTAssetLoader() { loaderType = KTAssetLoader.LoaderType.Asset, requestAssetName = assetName, requestBundleName = requestBundleName, cacheType = cacheType, cacheTimeout = cacheTimeout, dependentBundleNames = m_manifest.GetAllDependencies(requestBundleName).ToList(), request = null, completeCallbackList = new List <Action <string, UnityEngine.Object> >() { completeCallback } }; m_assetLoading.Add(assetName, assetLoader); }
/// <summary> /// 加载场景 /// </summary> /// <param name="assetName"></param> /// <param name="completeCallback"></param> /// <param name="loadMode"></param> /// <param name="cacheType">可以选三种模式</param> /// <param name="cacheTimeout"></param> public void LoadScene(string assetName, Action <string> completeCallback = null, LoadSceneMode loadMode = LoadSceneMode.Additive, BundleCacheType cacheType = BundleCacheType.None, float cacheTimeout = 5) { if (!CheckInited()) { if (completeCallback != null) { completeCallback(""); } return; } var requestBundleName = m_assetNameToBundleNameMap[assetName]; IncreaseRef(requestBundleName); if (string.IsNullOrEmpty(requestBundleName)) { if (completeCallback != null) { completeCallback(""); } Debug.LogError("Asset Info " + assetName + " Not Found"); return; } if (m_assetLoading.ContainsKey(assetName))//场景不允许请求重复 { if (completeCallback != null) { completeCallback(""); } Debug.LogError("Request Scene " + assetName + " Repeated"); return; } WeakReference weakPtr = null; if (m_assetNameToWeakPtr.TryGetValue(assetName, out weakPtr) && weakPtr.IsAlive) { if (completeCallback != null) { completeCallback(assetName); } return; } //由update决定下一帧是读取bundle还是读取asset var assetLoader = new KTAssetLoader() { loaderType = KTAssetLoader.LoaderType.Scene, requestAssetName = assetName, requestBundleName = requestBundleName, cacheType = cacheType, cacheTimeout = cacheTimeout, dependentBundleNames = m_manifest.GetAllDependencies(requestBundleName).ToList(), sceneRequest = null, sceneCompleteCallback = completeCallback }; m_assetLoading.Add(assetName, assetLoader); }