IEnumerator InitAppVersion() { var appVersionRequest = AssetBundleManager.Instance.RequestAssetFileAsync(UtilityBuild.AppVersionFileName); yield return(appVersionRequest); var streamingAppVersion = appVersionRequest.text; appVersionRequest.Dispose(); var appVersionPath = AssetBundleUtility.GetPersistentDataPath(UtilityBuild.AppVersionFileName); var persistentAppVersion = UtilityGame.SafeReadAllText(appVersionPath); Logger.Log(string.Format("streamingAppVersion = {0}, persistentAppVersion = {1}", streamingAppVersion, persistentAppVersion)); // 如果persistent目录版本比streamingAssets目录app版本低,说明是大版本覆盖安装,清理过时的缓存 if (!string.IsNullOrEmpty(persistentAppVersion) && UtilityBuild.CheckIsNewVersion(persistentAppVersion, streamingAppVersion)) { var path = AssetBundleUtility.GetPersistentDataPath(); UtilityGame.SafeDeleteDir(path); } UtilityGame.SafeWriteAllText(appVersionPath, streamingAppVersion); ChannelManager.instance.appVersion = streamingAppVersion; yield break; }
public static void CopyLuaFilesToAssetsPackage() { string destination = Path.Combine(Application.dataPath, AssetBundleConfig.AssetsFolderName); destination = Path.Combine(destination, XLuaManager.luaAssetbundleAssetName); string source = Path.Combine(Application.dataPath, XLuaManager.luaScriptsFolder); UtilityGame.SafeDeleteDir(destination); FileUtil.CopyFileOrDirectoryFollowSymlinks(source, destination); var notLuaFiles = UtilityGame.GetSpecifyFilesInFolder(destination, new string[] { ".lua" }, true); if (notLuaFiles != null && notLuaFiles.Length > 0) { for (int i = 0; i < notLuaFiles.Length; i++) { UtilityGame.SafeDeleteFile(notLuaFiles[i]); } } var luaFiles = UtilityGame.GetSpecifyFilesInFolder(destination, new string[] { ".lua" }, false); if (luaFiles != null && luaFiles.Length > 0) { for (int i = 0; i < luaFiles.Length; i++) { UtilityGame.SafeRenameFile(luaFiles[i], luaFiles[i] + ".bytes"); } } AssetDatabase.Refresh(); Debug.Log("Copy lua files over"); }
public static void CopyAssetBundlesToStreamingAssets(BuildTarget buildTarget, string channelName) { string source = GetAssetBundleOutputPath(buildTarget, channelName); string destination = AssetBundleUtility.GetStreamingAssetsDataPath(); // 有毒,竟然在有的windows系统这个函数删除不了目录,不知道是不是Unity的Bug // UtilityGame.SafeDeleteDir(destination); AssetDatabase.DeleteAsset(UtilityGame.FullPathToAssetPath(destination)); AssetDatabase.Refresh(); try { FileUtil.CopyFileOrDirectoryFollowSymlinks(source, destination); } catch (System.Exception ex) { Debug.LogError("Something wrong, you need manual delete AssetBundles folder in StreamingAssets, err : " + ex); return; } var allManifest = UtilityGame.GetSpecifyFilesInFolder(destination, new string[] { ".manifest" }); if (allManifest != null && allManifest.Length > 0) { for (int i = 0; i < allManifest.Length; i++) { UtilityGame.SafeDeleteFile(allManifest[i]); } } AssetDatabase.Refresh(); }
public static void CopyAndroidSDKResources(string channelName) { string targetPath = Path.Combine(Application.dataPath, "Plugins"); targetPath = Path.Combine(targetPath, "Android"); UtilityGame.SafeClearDir(targetPath); string channelPath = Path.Combine(Environment.CurrentDirectory, "Channel"); string resPath = Path.Combine(channelPath, "UnityCallAndroid_" + channelName); if (!Directory.Exists(resPath)) { resPath = Path.Combine(channelPath, "UnityCallAndroid"); } EditorUtility.DisplayProgressBar("提示", "正在拷贝SDK资源,请稍等", 0f); PackageUtils.CopyJavaFolder(resPath + "/assets", targetPath + "/assets"); EditorUtility.DisplayProgressBar("提示", "正在拷贝SDK资源,请稍等", 0.3f); PackageUtils.CopyJavaFolder(resPath + "/libs", targetPath + "/libs"); EditorUtility.DisplayProgressBar("提示", "正在拷贝SDK资源,请稍等", 0.6f); PackageUtils.CopyJavaFolder(resPath + "/res", targetPath + "/res"); if (File.Exists(resPath + "/bin/UnityCallAndroid.jar")) { File.Copy(resPath + "/bin/UnityCallAndroid.jar", targetPath + "/libs/UnityCallAndroid.jar", true); } if (File.Exists(resPath + "/AndroidManifest.xml")) { File.Copy(resPath + "/AndroidManifest.xml", targetPath + "/AndroidManifest.xml", true); } EditorUtility.DisplayProgressBar("提示", "正在拷贝SDK资源,请稍等", 1f); EditorUtility.ClearProgressBar(); AssetDatabase.Refresh(); }
public static string GetChannelOutputPath(BuildTarget target, string channelName) { string outputPath = Path.Combine(Application.dataPath, $"../Build/{target.ToString()}"); UtilityGame.CheckDirAndCreateWhenNeeded(outputPath); return(outputPath); }
public static string GetAssetBundleOutputPath(BuildTarget target, string channelName) { string outputPath = Path.Combine(AssetBundleConfig.AssetBundlesBuildOutputPath, GetAssetBundleRelativePath(target, channelName)); UtilityGame.CheckDirAndCreateWhenNeeded(outputPath); return(outputPath); }
public static void ClearAssetBundleServerURL() { var path = GetStreamingAssetBundleServerUrl(); UtilityGame.SafeDeleteFile(path); AssetDatabase.Refresh(); }
public static void WriteAssetBundleServerURL() { var path = GetStreamingAssetBundleServerUrl(); UtilityGame.SafeWriteAllText(path, GetAssetBundleServerURL()); AssetDatabase.Refresh(); }
IEnumerator UpdateFinish() { statusText.text = "正在准备资源..."; // 保存服务器资源版本号与Manifest UtilityGame.SafeWriteAllText(resVersionPath, serverResVersion); clientResVersion = serverResVersion; hostManifest.SaveToDiskCahce(); // 重启资源管理器 yield return(AssetBundleManager.Instance.Cleanup()); yield return(AssetBundleManager.Instance.Initialize()); //i重启图集管理 yield return(Sword.SpriteAtlasManager.Instance.Reset()); // 重启Lua虚拟机 string luaAssetbundleName = XLuaManager.Instance.AssetbundleName; AssetBundleManager.Instance.SetAssetBundleResident(luaAssetbundleName, true); var abloader = AssetBundleManager.Instance.LoadAssetBundleAsync(luaAssetbundleName); yield return(abloader); abloader.Dispose(); XLuaManager.Instance.Restart(); XLuaManager.Instance.StartHotfix(); yield break; }
public static byte[] CustomLoader(ref string filepath) { string scriptPath = string.Empty; filepath = filepath.Replace(".", "/") + ".lua"; #if UNITY_EDITOR if (AssetBundleConfig.IsEditorMode) { scriptPath = Path.Combine(Application.dataPath, luaScriptsFolder); scriptPath = Path.Combine(scriptPath, filepath); //Logger.Log("Load lua script : " + scriptPath); return(UtilityGame.SafeReadAllBytes(scriptPath)); } #endif scriptPath = string.Format("{0}/{1}.bytes", luaAssetbundleAssetName, filepath); string assetbundleName = null; string assetName = null; bool status = AssetBundleManager.Instance.MapAssetPath(scriptPath, out assetbundleName, out assetName); if (!status) { Logger.LogError("MapAssetPath failed : " + scriptPath); return(null); } var asset = AssetBundleManager.Instance.GetAssetCache(assetName) as TextAsset; if (asset != null) { //Logger.Log("Load lua script : " + scriptPath); return(asset.bytes); } Logger.LogError("Load lua script failed : " + scriptPath + ", You should preload lua assetbundle first!!!"); return(null); }
public static string GetPersistentDataPath(string assetPath = null, bool isIndependent = false) { string folderName; if (isIndependent) { folderName = AssetBundleConfig.AssetBundlesIndependentFolderName; } else { folderName = AssetBundleConfig.AssetBundlesFolderName; } // string outputPath = Path.Combine(Application.persistentDataPath, folderName); string outputPath = Core.Resource.FileUtil.GetWritePath(folderName); //修改了写目录 if (!string.IsNullOrEmpty(assetPath)) { outputPath = Path.Combine(outputPath, assetPath); } #if UNITY_EDITOR return(UtilityGame.FormatToSysFilePath(outputPath)); #else return(outputPath); #endif }
public static string ReadResVersionFile(BuildTarget target, ChannelType channel) { // 从资源版本号文件(当前渠道AB输出目录中)加载资源版本号 string rootPath = PackageUtils.GetAssetBundleOutputPath(target, channel.ToString()); return(UtilityGame.SafeReadAllText(Path.Combine(rootPath, UtilityBuild.ResVersionFileName))); }
public void SaveToDiskCahce() { if (manifestBytes != null && manifestBytes.Length > 0) { string path = AssetBundleUtility.GetPersistentDataPath(AssetbundleName); UtilityGame.SafeWriteAllBytes(path, manifestBytes); } }
public static byte[] CustomLoader(ref string filepath) { string scriptPath = string.Empty; filepath = filepath.Replace(".", "/") + ".lua"; scriptPath = "LuaScripts/" + filepath; #if UNITY_EDITOR if (AssetBundleConfig.IsEditorMode || AssetBundleConfig.IsSimulateMode_UseLuaScripts) { scriptPath = Path.Combine(Application.dataPath, luaScriptsFolder); scriptPath = Path.Combine(scriptPath, filepath); //Logger.Log("Load lua script : " + scriptPath); return(UtilityGame.SafeReadAllBytes(scriptPath)); } #endif //优先读取可写目录文件 string realPath = FileUtil.GetWritePath(scriptPath); if (File.Exists(realPath)) { return(UtilityGame.SafeReadAllBytes(realPath)); } #if UNITY_ANDROID && !UNITY_EDITOR byte[] bytes = AndroidAssetLoadSDK.LoadFile(scriptPath); if (bytes != null) { return(bytes); } #else //优先读取可写目录文件 realPath = FileUtil.GetReadOnlyPath(scriptPath); if (File.Exists(realPath)) { return(UtilityGame.SafeReadAllBytes(realPath)); } #endif Logger.LogError($"Lua File Not Found:({scriptPath})"); // scriptPath = string.Format("{0}/{1}.bytes", luaAssetbundleAssetName, filepath); // string assetbundleName = null; // string assetName = null; // bool status = AssetBundleManager.Instance.MapAssetPath(scriptPath, out assetbundleName, out assetName); // if (!status) // { // Logger.LogError("MapAssetPath failed : " + scriptPath); // return null; // } // var asset = AssetBundleManager.Instance.GetAssetCache(assetName) as TextAsset; // if (asset != null) // { // //Logger.Log("Load lua script : " + scriptPath); // return asset.bytes; // } // Logger.LogError("Load lua script failed : " + scriptPath + ", You should preload lua assetbundle first!!!"); return(null); }
void Remove() { UtilityGame.SafeDeleteFile(databaseAssetPath); AssetDatabase.Refresh(); Initialize(); Repaint(); configChanged = false; }
public static void SaveAllVersionFile(BuildTarget target, ChannelType channel) { // 保存所有版本号信息到资源版本号文件(当前渠道AB输出目录中) string rootPath = PackageUtils.GetAssetBundleOutputPath(target, channel.ToString()); UtilityGame.SafeWriteAllText(Path.Combine(rootPath, UtilityBuild.ResVersionFileName), resVersion); UtilityGame.SafeWriteAllText(Path.Combine(rootPath, UtilityBuild.NoticeVersionFileName), resVersion); UtilityGame.SafeWriteAllText(Path.Combine(rootPath, UtilityBuild.AppVersionFileName), bundleVersion); }
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 (!UtilityGame.SafeWriteAllLines(outputFilePath, mappingList.ToArray())) { Debug.LogError("BuildVariantMapping failed!!! try rebuild it again!"); } else { AssetDatabase.Refresh(); AssetBundleEditorHelper.CreateAssetbundleForCurrent(outputFilePath); Debug.Log("BuildVariantMapping success..."); } AssetDatabase.Refresh(); }
void Update() { if (!isDownloading) { return; } for (int i = downloadingRequest.Count - 1; i >= 0; i--) { var request = downloadingRequest[i]; if (request.isDone) { if (!string.IsNullOrEmpty(request.error)) { Logger.LogError("Error when downloading file : " + request.assetbundleName + "\n from url : " + request.url + "\n err : " + request.error); hasError = true; needDownloadList.Add(request.assetbundleName); } else { // TODO:是否需要显示下载流量进度? Logger.Log("Finish downloading file : " + request.assetbundleName + "\n from url : " + request.url); downloadingRequest.RemoveAt(i); finishedDownloadCount++; var filePath = AssetBundleUtility.GetPersistentDataPath(request.assetbundleName); UtilityGame.SafeWriteAllBytes(filePath, request.bytes); } request.Dispose(); } } if (!hasError) { while (downloadingRequest.Count < MAX_DOWNLOAD_NUM && needDownloadList.Count > 0) { var fileName = needDownloadList[needDownloadList.Count - 1]; needDownloadList.RemoveAt(needDownloadList.Count - 1); var request = AssetBundleManager.Instance.DownloadAssetBundleAsync(fileName); downloadingRequest.Add(request); } } if (downloadingRequest.Count == 0) { isDownloading = false; } float progressSlice = 1.0f / totalDownloadCount; float progressValue = finishedDownloadCount * progressSlice; for (int i = 0; i < downloadingRequest.Count; i++) { progressValue += (progressSlice * downloadingRequest[i].progress); } slider.normalizedValue = progressValue; }
public static void SwitchChannel(string channelName) { var channelFolderPath = AssetBundleUtility.PackagePathToAssetsPath(AssetBundleConfig.ChannelFolderName); var guids = AssetDatabase.FindAssets("t:textAsset", new string[] { channelFolderPath }); foreach (var guid in guids) { var path = AssetDatabase.GUIDToAssetPath(guid); UtilityGame.SafeWriteAllText(path, channelName); } AssetDatabase.Refresh(); }
private string FullPathToAssetPath(string fullPath) { string retPath = UtilityGame.FullPathToAssetPath(fullPath); if (retPath.Equals(UtilityGame.AssetsFolderName)) { return(null); } else { return(retPath); } }
public static string GetPersistentDataPath(string assetPath = null) { string outputPath = Path.Combine(Application.persistentDataPath, AssetBundleConfig.AssetBundlesFolderName); if (!string.IsNullOrEmpty(assetPath)) { outputPath = Path.Combine(outputPath, assetPath); } #if UNITY_EDITOR return(UtilityGame.FormatToSysFilePath(outputPath)); #else return(outputPath); #endif }
public static void BuildWindows() { string savePath = KVPackageHelper.GetChannelOutputPath(buildTarget, channelName); UtilityGame.SafeDeleteFile(savePath); string appPath = $"{savePath}/XURGame.exe"; BuildPipeline.BuildPlayer( KVPackageHelper.GetBuildScenes(), appPath, buildTarget, BuildOptions.None); Debug.Log(string.Format("Build windows player for : {0} done! output :{1}", channelName, savePath)); }
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); UtilityGame.SafeDeleteDir(outputPath); Debug.Log(string.Format("Clear {0} assetbundle persistent assets done!", PackageUtils.GetCurPlatformName())); }
public void CheckChannelName() { string channelAssetPath = Path.Combine(AssetBundleConfig.ChannelFolderName, config.PackagePath); channelAssetPath = AssetBundleUtility.PackagePathToAssetsPath(channelAssetPath) + ".bytes"; if (!File.Exists(channelAssetPath)) { UtilityGame.SafeWriteAllText(channelAssetPath, "None"); AssetDatabase.Refresh(); } var imp = AssetBundleImporter.GetAtPath(channelAssetPath); imp.assetBundleName = assetsPath; }
public static void BuildAndroid(string channelName, bool isTest = false) { BuildTarget buildTarget = BuildTarget.Android; string savePath = KVPackageHelper.GetChannelOutputPath(buildTarget, channelName); string appName = "sot_dev.apk"; savePath = Path.Combine(savePath, appName); UtilityGame.SafeDeleteDir(savePath); UtilityGame.SafeDeleteFile(savePath); BuildPipeline.BuildPlayer( KVPackageHelper.GetBuildScenes(), savePath, buildTarget, BuildOptions.None | BuildOptions.Development | BuildOptions.ConnectWithProfiler | BuildOptions.BuildScriptsOnly); Debug.Log(string.Format("Build android player for : {0} done! output :{1}", channelName, savePath)); }
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); UtilityGame.SafeClearDir(outputPath); AssetDatabase.Refresh(); Debug.Log(string.Format("Clear {0} assetbundle streaming assets done!", PackageUtils.GetCurPlatformName())); }
public static void CopyLuaFilesToAssetsPackage() { string destination = Path.Combine(Application.dataPath, AssetBundleConfig.AssetsFolderName); destination = Path.Combine(destination, XLuaManager.luaAssetbundleAssetName); string source = Path.Combine(Application.dataPath, XLuaManager.luaScriptsFolder); UtilityGame.SafeDeleteDir(destination); // if (AssetBundleConfig.IsPackLuaAb == false) // { // Directory.CreateDirectory(destination); // Logger.Log("------------------------------------ 没有拷贝lua目录"); // FileStream f = File.OpenWrite(destination + "/main.lua.bytes"); // var str = "print('test')"; // f.Write( System.Text.Encoding.Default.GetBytes(str), 0, str.Length); // f.Close(); // AssetDatabase.Refresh(); // return; // } FileUtil.CopyFileOrDirectoryFollowSymlinks(source, destination); var notLuaFiles = UtilityGame.GetSpecifyFilesInFolder(destination, new string[] { ".lua" }, true); if (notLuaFiles != null && notLuaFiles.Length > 0) { for (int i = 0; i < notLuaFiles.Length; i++) { UtilityGame.SafeDeleteFile(notLuaFiles[i]); } } var luaFiles = UtilityGame.GetSpecifyFilesInFolder(destination, new string[] { ".lua" }, false); if (luaFiles != null && luaFiles.Length > 0) { for (int i = 0; i < luaFiles.Length; i++) { UtilityGame.SafeRenameFile(luaFiles[i], luaFiles[i] + ".bytes"); } } AssetDatabase.Refresh(); Debug.Log("Copy lua files over"); }
static public void ToolsClearOutput() { var buildTargetName = PackageUtils.GetCurPlatformName(); var channelName = PackageUtils.GetCurSelectedChannel().ToString(); bool checkClear = EditorUtility.DisplayDialog("ClearOutput Warning", string.Format("Clear output assetbundles will force to rebuild all : \n\nplatform : {0} \nchannel : {1} \n\n continue ?", buildTargetName, channelName), "Yes", "No"); if (!checkClear) { return; } string outputPath = PackageUtils.GetCurBuildSettingAssetBundleOutputPath(); UtilityGame.SafeDeleteDir(outputPath); Debug.Log(string.Format("Clear done : {0}", outputPath)); }
public static void CopyLuaScriptsToStreamingAssets() { string path = "LuaScripts"; string destination = Path.Combine(Application.streamingAssetsPath, path); string source = Path.Combine(Application.dataPath, "../" + path); AssetDatabase.DeleteAsset(UtilityGame.FullPathToAssetPath(destination)); try { FileUtil.CopyFileOrDirectoryFollowSymlinks(source, destination); } catch (System.Exception ex) { Debug.LogError("Something wrong, you need manual delete LuaScripts folder in StreamingAssets, err : " + ex); return; } Debug.Log("Copy LuaScripts assetbundles to streaming assets done!"); }
void DrawCreateAssetBundleDispatcher() { if (GUILayout.Button("Create AssetBundle Dispatcher")) { var dir = Path.GetDirectoryName(databaseAssetPath); UtilityGame.CheckDirAndCreateWhenNeeded(dir); var instance = CreateInstance <AssetBundleDispatcherConfig>(); AssetDatabase.CreateAsset(instance, databaseAssetPath); AssetDatabase.Refresh(); Initialize(); Repaint(); isNewCreate = true; MarkChanged(); } }