public override bool LoadSync() { if (!CheckLoadAble()) { return(false); } State = ResState.Loading; #if UNITY_EDITOR if (SimulateAssetBundleInEditor) { } else #endif { var url = ResKitUtil.AssetBundleName2Url(mAssetName); var bundle = AssetBundle.LoadFromFile(url); mUnloadFlag = true; if (bundle == null) { Log.E("Failed Load AssetBundle:" + mAssetName); OnResLoadFaild(); return(false); } AssetBundle = bundle; } State = ResState.Ready; return(true); }
public AssetBundleRes(string assetName) { mPath = ResKitUtil.FullPathForAssetBundle(assetName); Name = assetName; State = ResState.Waiting; }
static void BuildAssetBundles() { var outputPath = Application.streamingAssetsPath + "/AssetBundles/" + ResKitUtil.GetPlatformName(); if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } BuildPipeline.BuildAssetBundles(outputPath, BuildAssetBundleOptions.ChunkBasedCompression, EditorUserBuildSettings.activeBuildTarget); AssetDatabase.Refresh(); }
public string[] GetAllDependenciesByUrl(string url) { var abName = ResKitUtil.AssetBundleUrl2Name(url); for (var i = mActiveAssetDataGroup.Count - 1; i >= 0; --i) { string[] depends; if (!mActiveAssetDataGroup[i].GetAssetBundleDepends(abName, out depends)) { continue; } return(depends); } return(null); }
private void Load() { if (ResMgr.IsSimulationModeLogic) { #if UNITY_EDITOR var assetBundleNames = UnityEditor.AssetDatabase.GetAllAssetBundleNames(); foreach (var assetBundleName in assetBundleNames) { var assetPaths = UnityEditor.AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName); var assetBundleData = new AssetBundleData { Name = assetBundleName, DependencyBundleNames = UnityEditor.AssetDatabase.GetAssetBundleDependencies(assetBundleName, false) }; foreach (var assetPath in assetPaths) { var assetData = new AssetData { OwnerBundleName = assetBundleName, // 通过路径获取名字 Name = assetPath .Split('/').Last() .Split('.').First() }; assetBundleData.AssetDataList.Add(assetData); } AssetBundleDatas.Add(assetBundleData); } #endif } else { var mainBundle = AssetBundle.LoadFromFile(ResKitUtil.FullPathForAssetBundle(ResKitUtil.GetPlatformName())); mManifest = mainBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest"); } }
public IEnumerator InitResMgrAsync() { #if UNITY_EDITOR if (Res.SimulateAssetBundleInEditor) { ResKit.ResDatas = EditorRuntimeAssetDataCollector.BuildDataTable(); yield return(null); } else #endif { ResKit.ResDatas.Reset(); var outResult = new List <string>(); string pathPrefix = ""; #if UNITY_EDITOR || UNITY_IOS pathPrefix = "file://"; #endif // 未进行过热更 if (ResKit.LoadResFromStreammingAssetsPath) { string streamingPath = Application.streamingAssetsPath + "/AssetBundles/" + ResKitUtil.GetPlatformName() + "/" + ResKit.ResDatas.FileName; outResult.Add(pathPrefix + streamingPath); } // 进行过热更 else { string persistenPath = Application.persistentDataPath + "/AssetBundles/" + ResKitUtil.GetPlatformName() + "/" + ResKit.ResDatas.FileName; outResult.Add(pathPrefix + persistenPath); } foreach (var outRes in outResult) { Debug.Log(outRes); yield return(ResKit.ResDatas.LoadFromFileAsync(outRes)); } yield return(null); } }
public override IEnumerator DoLoadAsync(System.Action finishCallback) { //开启的时候已经结束了 if (RefCount <= 0) { OnResLoadFaild(); finishCallback(); yield break; } #if UNITY_EDITOR if (SimulateAssetBundleInEditor) { yield return(null); } else #endif { var url = ResKitUtil.AssetBundleName2Url(mAssetName); var abcR = AssetBundle.LoadFromFileAsync(url); mAssetBundleCreateRequest = abcR; yield return(abcR); mAssetBundleCreateRequest = null; if (!abcR.isDone) { Log.E("AssetBundleCreateRequest Not Done! Path:" + mAssetName); OnResLoadFaild(); finishCallback(); yield break; } AssetBundle = abcR.assetBundle; } State = ResState.Ready; finishCallback(); }
private static string GetPlatformName() { return(ResKitUtil.GetPlatformForAssetBundles(EditorUserBuildSettings.activeBuildTarget)); }
public IEnumerator InitResMgrAsync() { #if UNITY_EDITOR if (Res.SimulateAssetBundleInEditor) { EditorRuntimeAssetDataCollector.BuildDataTable(); yield return(null); } else #endif { ResDatas.Instance.Reset(); var outResult = new List <string>(); // 未进行过热更 if (ResKit.LoadResFromStreammingAssetsPath) { outResult.Add(Application.streamingAssetsPath + "/AssetBundles/" + ResKitUtil.GetPlatformName() + "/asset_bindle_config.bin"); } // 进行过热更 else { outResult.Add(Application.persistentDataPath + "/AssetBundles/" + ResKitUtil.GetPlatformName() + "/asset_bindle_config.bin"); } foreach (var outRes in outResult) { Debug.Log(outRes); yield return(ResDatas.Instance.LoadFromFileAsync(outRes)); } yield return(null); } ResDatas.Instance.SwitchLanguage("cn"); }