void CheckChildren() { string[] subFolders = AssetDatabase.GetSubFolders(assetsPath); var checkerConfig = new AddressableCheckerConfig(); foreach (string f in subFolders) { var packPath = AssetBundleUtility.AssetsPathToPackagePath(f); if (config.Type == AddressableDispatcherFilterType.ChildrenFilesOnly && !File.Exists(f)) { //continue; } else if (config.Type == AddressableDispatcherFilterType.ChildrenFoldersOnly && File.Exists(f)) { //continue; } checkerConfig.CheckerFilters = config.CheckerFilters; checkerConfig.PackagePath = packPath; AddressableChecker.Run(checkerConfig); } }
protected bool CreateAssetBundleAsync(string assetbundleName, bool isIndependent = false) { #if UNITY_EDITOR // EditorApplication.isPaused = true; #endif if (IsAssetBundleLoaded(assetbundleName) || webRequesting.ContainsKey(assetbundleName)) { return(false); } var creater = ResourceWebRequester.Get(); var url = AssetBundleUtility.GetAssetBundleFileUrl(assetbundleName); if (!manifest.GetAssetBundleHash(assetbundleName).isValid&& idpManifest.GetAssetBundleHash(assetbundleName).isValid) { url = AssetBundleUtility.GetIndependentAssetBundleFileUrl(assetbundleName); } creater.Init(assetbundleName, url); webRequesting.Add(assetbundleName, creater); webRequesterQueue.Enqueue(creater); // 创建器持有的引用:创建器对每个ab来说是全局唯一的 IncreaseReferenceCount(assetbundleName); return(true); }
public IEnumerator PreLoadLua() { #if UNITY_EDITOR if (AssetBundleConfig.IsEditorMode) { yield break; } #endif string luaAssetbundleName = XLuaManager.Instance.AssetbundleName; var abloader = LoadAssetBundleAsync(luaAssetbundleName); yield return(abloader); luaCaching.Clear(); AssetBundle curAssetbundle = abloader.assetbundle; var allAssetNames = assetsPathMapping.GetAllAssetNames(luaAssetbundleName); for (int i = 0; i < allAssetNames.Count; i++) { var assetName = allAssetNames[i]; if (luaCaching.ContainsKey(assetName)) { continue; } var assetPath = AssetBundleUtility.PackagePathToAssetsPath(assetName); var asset = curAssetbundle == null ? null : curAssetbundle.LoadAsset(assetPath); luaCaching[assetName] = asset; } abloader.Dispose(); }
public static void BuildStandalonePlayer() { var outputPath = EditorUtility.SaveFolderPanel("Choose Location of the Built Game", "", ""); if (outputPath.Length == 0) { return; } string[] levels = GetLevelsFromBuildSettings(); if (levels.Length == 0) { Debug.Log("Nothing to build."); return; } string targetName = GetBuildTargetName(EditorUserBuildSettings.activeBuildTarget); if (targetName == null) { return; } GameUtility.SafeDeleteFile(outputPath + targetName); // Build and copy AssetBundles. BuildAssetBundles(); AssetBundleUtility.CopyPlatformAssetBundlesToStreamingAssets(); // makesure the local server URL is up-to-dat AssetBundleUtility.WriteAssetBundleServerURL(); AssetDatabase.Refresh(); BuildOptions option = EditorUserBuildSettings.development ? BuildOptions.Development : BuildOptions.None; BuildPipeline.BuildPlayer(levels, outputPath + targetName, EditorUserBuildSettings.activeBuildTarget, option); }
public BaseAssetAsyncLoader LoadAssetAsync(string assetPath, System.Type assetType) { #if UNITY_EDITOR if (AssetBundleConfig.IsEditorMode) { string path = AssetBundleUtility.PackagePathToAssetsPath(assetPath); UnityEngine.Object target = AssetDatabase.LoadAssetAtPath(path, assetType); return new EditorAssetAsyncLoader(target); } #endif string assetbundleName = null; string assetName = null; bool status = MapAssetPath(assetPath, out assetbundleName, out assetName); if (!status) { Logger.LogError("No assetbundle at asset path :" + assetPath); return null; } var loader = AssetAsyncLoader.Get(); prosessingAssetAsyncLoader.Add(loader); if (IsAssetLoaded(assetName)) { Logger.LogError(">>>> IsAssetLoaded {0}", assetName); loader.Init(assetName, GetAssetCache(assetName)); return loader; } var assetbundleLoader = LoadAssetBundleAsync(assetbundleName); loader.Init(assetName, assetbundleLoader); return loader; }
private IEnumerator LoadLuaData(string luaAssetbundleName) { var abloader = LoadAssetBundleAsync(luaAssetbundleName); yield return(abloader); AssetBundle curAssetbundle = abloader.assetbundle; #if UNITY_EDITOR Logger.Log("当前内存占用 name = " + luaAssetbundleName + " " + EditorUtility.FormatBytes(UnityEngine.Profiling.Profiler.GetRuntimeMemorySizeLong(curAssetbundle))); #endif var allAssetNames = assetsPathMapping.GetAllAssetNames(luaAssetbundleName); long total = 0; for (int i = 0; i < allAssetNames.Count; i++) { var assetName = allAssetNames[i]; if (luaCaching.ContainsKey(assetName)) { continue; } var assetPath = AssetBundleUtility.PackagePathToAssetsPath(assetName); var asset = curAssetbundle == null ? null : curAssetbundle.LoadAsset(assetPath); total += UnityEngine.Profiling.Profiler.GetRuntimeMemorySizeLong(asset); luaCaching[assetName] = asset; } #if UNITY_EDITOR Logger.Log("解析后内存占用 " + EditorUtility.FormatBytes(total)); #endif abloader.Dispose(); }
public void SaveToDiskCahce() { if (manifestBytes != null && manifestBytes.Length > 0) { string path = AssetBundleUtility.GetPersistentDataPath(AssetbundleName); UtilityGame.SafeWriteAllBytes(path, manifestBytes); } }
public void AddAssetbundleAssetsCache(string assetbundleName, string postfix = null) { #if UNITY_EDITOR if (AssetBundleConfig.IsEditorMode) { return; } #endif if (!IsAssetBundleLoaded(assetbundleName)) { Logger.LogError("Try to add assets cache from unloaded assetbundle : " + assetbundleName); return; } var curAssetbundle = GetAssetBundleCache(assetbundleName); var allAssetNames = assetsPathMapping.GetAllAssetNames(assetbundleName); for (int i = 0; i < allAssetNames.Count; i++) { var assetName = allAssetNames[i]; if (IsAssetLoaded(assetName)) { continue; } if (!string.IsNullOrEmpty(postfix) && !assetName.EndsWith(postfix)) { continue; } var assetPath = AssetBundleUtility.PackagePathToAssetsPath(assetName); var asset = curAssetbundle == null ? null : curAssetbundle.LoadAsset(assetPath); AddAssetCache(assetName, asset); #if UNITY_EDITOR // 说明:在Editor模拟时,Shader要重新指定 var go = asset as GameObject; if (go != null) { var renderers = go.GetComponentsInChildren<Renderer>(); for (int j = 0; j < renderers.Length; j++) { var mat = renderers[j].sharedMaterial; if (mat == null) { continue; } var shader = mat.shader; if (shader != null) { var shaderName = shader.name; mat.shader = Shader.Find(shaderName); } } } #endif } }
// 本地异步请求Assetbundle资源,不计引用计数、不缓存,Creater使用后记得回收 public ResourceWebRequester RequestAssetBundleAsync(string assetbundleName) { var creater = ResourceWebRequester.Get(); var url = AssetBundleUtility.GetAssetBundleFileUrl(assetbundleName); creater.Init(assetbundleName, url, true); webRequesting.Add(assetbundleName, creater); webRequesterQueue.Enqueue(creater); return creater; }
public static void BuildVariantMapping(AssetBundleManifest manifest) { mappingList.Clear(); string outputFilePath = AssetBundleUtility.PackagePathToAssetsPath(AssetBundleConfig.VariantsMapFileName); string[] allVariants = manifest.GetAllAssetBundlesWithVariant(); // 处理带variants的assetbundle foreach (string assetbundle in allVariants) { // 该assetbundle中包含的所有asset的路径(相对于Assets文件夹),如: // Assets/AssetsPackage/UI/Prefabs/Language/[Chinese]/TestVariant.prefab // Assets/AssetsPackage/UI/Prefabs/Language/[English]/TestVariant.prefab // 在代码使用的加载路径中,它们被统一处理为 // Assets/AssetsPackage/UI/Prefabs/Language/[Variant]/TestVariant.prefab // 这里的variant为chinese、english,在AssetBundleManager中设置启用的variant会自动对路径进行正确还原 string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundle(assetbundle); if (assetPaths == null || assetPaths.Length == 0) { UnityEngine.Debug.LogError("Empty assetbundle with variant : " + assetbundle); continue; } // 自本节点向上找到Assetbundle所在 AssetBundleImporter assetbundleImporter = AssetBundleImporter.GetAtPath(assetPaths[0]); while (assetbundleImporter != null && string.IsNullOrEmpty(assetbundleImporter.assetBundleVariant)) { assetbundleImporter = assetbundleImporter.GetParent(); } if (assetbundleImporter == null || string.IsNullOrEmpty(assetbundleImporter.assetBundleVariant)) { UnityEngine.Debug.LogError("Can not find assetbundle with variant : " + assetbundle); continue; } string assetbundlePath = assetbundleImporter.assetPath; if (assetbundlePath.EndsWith("/")) { assetbundlePath = assetbundlePath.Substring(0, assetbundlePath.Length - 1); } // 由于各个Variant的内部结构必须完全一致,而Load时也必须完全填写,所以这里不需要关注到assetbundle具体的每个资源 string nowNode = System.IO.Path.GetFileName(assetbundlePath); string mappingItem = string.Format("{0}{1}{2}", assetbundle, PATTREN, nowNode); mappingList.Add(mappingItem); } mappingList.Sort(); if (!GameUtility.SafeWriteAllLines(outputFilePath, mappingList.ToArray())) { Debug.LogError("BuildVariantMapping failed!!! try rebuild it again!"); } else { AssetDatabase.Refresh(); AssetBundleEditorHelper.CreateAssetbundleForCurrent(outputFilePath); Debug.Log("BuildVariantMapping success..."); } AssetDatabase.Refresh(); }
public AssetBundleChecker(AssetBundleCheckerConfig config) { this.config = config; assetsPath = AssetBundleUtility.PackagePathToAssetsPath(config.PackagePath); importer = AssetBundleImporter.GetAtPath(assetsPath); if (importer == null || !importer.IsValid) { Logger.LogError($"定义的Package信息path:({assetsPath}) 没有找不到,请对比Asset/Editor/AssetBundle/xxx和Asset/AssetsPackage/xxx"); } }
public AssetBundleDispatcher(AssetBundleDispatcherConfig config) { this.config = config; assetsPath = AssetBundleUtility.PackagePathToAssetsPath(config.PackagePath); importer = AssetBundleImporter.GetAtPath(assetsPath); if (importer == null) { Debug.LogError("Asset path err : " + assetsPath); } }
// 异步请求非Assetbundle资源,不缓存,无依赖 public ResourceWebRequester RequestFileAssetAsync(string filePath) { var creater = ResourceWebRequester.Get(); var url = AssetBundleUtility.GetPlatformFileUrl(filePath); creater.Init(filePath, url, true); webRequesting.Add(filePath, creater); webRequesterQueue.Enqueue(creater); return(creater); }
private bool LoadTempVersionHash() { string versionTxt = GameUtility.SafeReadAllText(AssetBundleUtility.GetPersistentTempPath(BuildUtils.VersionsFileName)); if (!string.IsNullOrEmpty(versionTxt)) { LoadText2Map(versionTxt, ref tempData); return(true); } return(false); }
// 本地异步请求Assetbundle资源,不计引用计数、不缓存,Creater使用后记得回收 public ResourceWebRequester RequestAssetBundleAsync(string assetbundleName) { var creater = ResourceWebRequester.Get(); var url = AssetBundleUtility.GetAssetBundleFileUrl(assetbundleName); #if UNITY_CLIENT Debug.Log("RequestAssetBundleAsync:" + url); #endif creater.Init(assetbundleName, url, true); webRequesting.Add(assetbundleName, creater); webRequesterQueue.Enqueue(creater); return(creater); }
public void AddAssetbundleAssetsCache(string assetbundleName) { #if UNITY_EDITOR // if (AssetBundleConfig.IsEditorMode) // { // return; // } #endif if (!IsAssetBundleLoaded(assetbundleName)) { Logger.LogError("Try to add assets cache from unloaded assetbundle : " + assetbundleName); return; } var curAssetbundle = GetAssetBundleCache(assetbundleName); if (curAssetbundle.isStreamedSceneAssetBundle) { // LoadScene(assetbundleName, curAssetbundle); return; } var allAssetNames = assetsPathMapping.GetAllAssetNames(assetbundleName); if (allAssetNames.Count == 0) { allAssetNames = idpAssetsPathMapping.GetAllAssetNames(assetbundleName); } for (int i = 0; i < allAssetNames.Count; i++) { var assetName = allAssetNames[i]; if (IsAssetLoaded(assetName)) { continue; } var assetPath = AssetBundleUtility.PackagePathToAssetsPath(assetName); UnityEngine.Object asset = null; asset = curAssetbundle == null ? null : curAssetbundle.LoadAsset(assetPath); AddAssetCache(assetName, asset); var go = asset as GameObject; if (go != null) { #if UNITY_EDITOR ResetEditorShader(go); // 说明:在Editor模拟时,Shader要重新指定 #endif //多语言转换 TranslateAsset(go); ResetPostProcess(go); } } }
void SaveToDiskCahce(Dictionary <string, string> dict) { StringBuilder sb = new StringBuilder(); foreach (var item in dict) { sb.AppendLine(string.Format("{0}|{1}", item.Key, item.Value)); } //save to disk var versionsPath = AssetBundleUtility.GetPersistentTempPath(BuildUtils.VersionsFileName); GameUtility.SafeWriteAllText(versionsPath, sb.ToString()); }
static public void ToolsClearOutput() { bool checkClear = EditorUtility.DisplayDialog("ClearOutput Warning", "Clear output assetbundles will force to rebuild all assetbundles, continue ?", "Yes", "No"); if (!checkClear) { return; } string outputPath = Path.Combine(AssetBundleConfig.AssetBundlesBuildOutputPath, AssetBundleUtility.GetCurPlatformName()); GameUtility.SafeDeleteDir(outputPath); Debug.Log(string.Format("Clear {0} assetbundle output done!", AssetBundleUtility.GetCurPlatformName())); }
public void CheckChannelName() { string channelAssetPath = Path.Combine(AssetBundleConfig.ChannelFolderName, config.PackagePath); channelAssetPath = AssetBundleUtility.PackagePathToAssetsPath(channelAssetPath) + ".bytes"; if (!File.Exists(channelAssetPath)) { GameUtility.SafeWriteAllText(channelAssetPath, "None"); AssetDatabase.Refresh(); } var imp = AssetBundleImporter.GetAtPath(channelAssetPath); imp.assetBundleName = assetsPath; }
public static void BuildAssetBundles(BuildTarget buildTarget) { string outputPath = AssetBundleUtility.GetBuildPlatformOutputPath(buildTarget); BuildAssetBundleOptions buildOption = BuildAssetBundleOptions.IgnoreTypeTreeChanges; AssetBundleManifest manifest = BuildPipeline.BuildAssetBundles(outputPath, buildOption, buildTarget); if (manifest != null) { AssetsPathMappingEditor.BuildPathMapping(buildTarget, manifest); VariantMappingEditor.BuildVariantMapping(buildTarget, manifest); BuildPipeline.BuildAssetBundles(outputPath, buildOption, buildTarget); Debug.Log("BuildAssetBundles success!!!"); } AssetDatabase.Refresh(); }
void DrawAssetDispatcherConfig() { GUILayoutUtils.BeginContents(false); GUILayoutUtils.DrawProperty("Path:", AssetBundleUtility.AssetsPathToPackagePath(targetAssetPath), 300f, 80f); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("FilterType:", GUILayout.MaxWidth(80f)); var selectType = (AssetBundleDispatcherFilterType)EditorGUILayout.EnumPopup(filterType); if (selectType != filterType) { filterType = selectType; MarkChanged(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Separator(); var filtersCount = dispatcherConfig.CheckerFilters.Count; if (GUILayoutUtils.DrawSubHeader(0, "CheckerFilters:", inspectorSate, "CheckerFilters", filtersCount.ToString())) { DrawFilterTypesList(dispatcherConfig.CheckerFilters); } Color color = GUI.color; if (configChanged) { GUI.color = color * new Color(1, 1, 0.5f); } EditorGUILayout.Separator(); GUILayout.BeginHorizontal(); if (GUILayout.Button("Apply")) { Apply(); } GUI.color = new Color(1, 0.5f, 0.5f); if (GUILayout.Button("Remove")) { ConfirmRemove(); } GUI.color = color; GUILayout.EndHorizontal(); EditorGUILayout.Separator(); GUILayoutUtils.EndContents(false); }
private bool CreateAssetBundleAsync(string assetbundleName) { if (IsAssetBundleLoaded(assetbundleName) || assetbundleRequesting.ContainsKey(assetbundleName)) { return(false); } var creater = ResourceAssetBundleRequester.Get(); var url = AssetBundleUtility.GetAssetBundleFileUrl(assetbundleName); creater.Init(assetbundleName, url); assetbundleRequesting.Add(assetbundleName, creater); assetbundleRequesterQueue.Enqueue(creater); return(true); }
protected bool CreateAssetBundleAsync(string assetbundleName) { if (IsAssetBundleLoaded(assetbundleName) || webRequesting.ContainsKey(assetbundleName)) { return false; } var creater = ResourceWebRequester.Get(); var url = AssetBundleUtility.GetAssetBundleFileUrl(assetbundleName); creater.Init(assetbundleName, url); webRequesting.Add(assetbundleName, creater); webRequesterQueue.Enqueue(creater); // 创建器持有的引用:创建器对每个ab来说是全局唯一的 IncreaseReferenceCount(assetbundleName); return true; }
/// <summary> /// 写入地址 /// </summary> /// <param name="outFile"></param> /// <param name="outLines"></param> public static void WriteAssetsAddress() { string assetsaddress = AssetBundleUtility.PackagePathToAssetsPath(AssetBundleConfig.AssetsaddressConfig); if (!GameUtility.SafeWriteAllLines(assetsaddress, addressList.ToArray())) { Debug.LogError("BuildPathMapping failed!!! try rebuild it again!"); } else { AssetDatabase.Refresh(); AssetBundleEditorHelper.CreateAssetbundleForCurrent(assetsaddress); Debug.Log("BuildPathMapping success..."); } AssetDatabase.Refresh(); }
static public void ToolsClearPersistentAssets() { bool checkClear = EditorUtility.DisplayDialog("ClearPersistentAssets Warning", "Clear persistent assetbundles will force to update all assetbundles that difference with streaming assets assetbundles, continue ?", "Yes", "No"); if (!checkClear) { return; } string outputPath = Path.Combine(Application.persistentDataPath, AssetBundleConfig.AssetBundlesFolderName); outputPath = Path.Combine(outputPath, AssetBundleUtility.GetCurPlatformName()); GameUtility.SafeDeleteDir(outputPath); Debug.Log(string.Format("Clear {0} assetbundle persistent assets done!", AssetBundleUtility.GetCurPlatformName())); }
static public void ToolsClearStreamingAssets() { bool checkClear = EditorUtility.DisplayDialog("ClearStreamingAssets Warning", "Clear streaming assets assetbundles will lost the latest player build info, continue ?", "Yes", "No"); if (!checkClear) { return; } string outputPath = Path.Combine(Application.streamingAssetsPath, AssetBundleConfig.AssetBundlesFolderName); outputPath = Path.Combine(outputPath, AssetBundleUtility.GetCurPlatformName()); GameUtility.SafeDeleteDir(outputPath); AssetDatabase.Refresh(); Debug.Log(string.Format("Clear {0} assetbundle streaming assets done!", AssetBundleUtility.GetCurPlatformName())); }
// 本地异步请求非Assetbundle资源,非AB(不计引用计数、不缓存),Creater使用后记得回收 public ResourceWebRequester RequestAssetFileAsync(string filePath, bool streamingAssetsOnly = true) { var creater = ResourceWebRequester.Get(); string url = null; if (streamingAssetsOnly) { url = AssetBundleUtility.GetStreamingAssetsFilePath(filePath); } else { url = AssetBundleUtility.GetAssetBundleFileUrl(filePath); } creater.Init(filePath, url, true); webRequesting.Add(filePath, creater); webRequesterQueue.Enqueue(creater); return creater; }
// 从资源服务器下载非Assetbundle资源,非AB(不计引用计数、不缓存),Creater使用后记得回收 public ResourceWebRequester DownloadAssetFileAsync(string filePath) { if (string.IsNullOrEmpty(DownloadUrl)) { Logger.LogError("You should set download url first!!!"); return(null); } var creater = ResourceWebRequester.Get(); var url = DownloadUrl + filePath; var saveUrl = AssetBundleUtility.GetPersistentFilePathWWW(filePath); creater.Init(filePath, url, new DownloadHandlerBuffer(), true); webRequesterQueue.Enqueue(creater); return(creater); }
// 本地异步请求非Assetbundle资源,非AB(不计引用计数、不缓存),Creater使用后记得回收 public ResourceWebRequester RequestAssetFileAsync(string filePath, bool streamingAssetsOnly = true) { var creater = ResourceWebRequester.Get(); string url = null; if (streamingAssetsOnly) { url = AssetBundleUtility.GetStreamingAssetsFilePathWWW(filePath); } else { url = AssetBundleUtility.GetAssetFileUrlWWW(filePath); } creater.Init(filePath, url, new DownloadHandlerBuffer(), true); webRequesterQueue.Enqueue(creater); return(creater); }
void Initialize() { configChanged = false; filterType = AssetBundleDispatcherFilterType.Root; targetAssetPath = AssetDatabase.GetAssetPath(target); if (!AssetBundleUtility.IsPackagePath(targetAssetPath)) { return; } packagePath = AssetBundleUtility.AssetsPathToPackagePath(targetAssetPath); databaseAssetPath = AssetBundleInspectorUtils.AssetPathToDatabasePath(targetAssetPath); dispatcherConfig = AssetDatabase.LoadAssetAtPath <AssetBundleDispatcherConfig>(databaseAssetPath); if (dispatcherConfig != null) { dispatcherConfig.Load(); filterType = dispatcherConfig.Type; } }