diff --git a/CHANGELOG.md b/CHANGELOG.md index 1246efa2d..3c597a3fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,11 +6,20 @@ Removed - 删除功能/接口 Fixed - 修复问题 Others - 其他 --> -## 2024-4-26 【普通更新】 +## 2024-5-15 【普通更新】 +### Feature +* 普通:支持JS构建模板,请查阅[模板文档](https://wechat-miniprogram.github.io/minigame-unity-webgl-transform/Design/BuildTemplate.html) +* 普通:调整启动封面表现,默认进度动画加速 +* 普通:writeFile/unlink操作文件时同步更新启动插件维护的缓存信息 +* 普通:支持自定义微信系统字体字符集 +* 普通:网络接口如UnityWebRequest支持通过添加特殊请求头`request.SetRequestHeader("wechatminigame-preload", "1")`做预下载,缓存到用户目录但不增加unity内存。当需要使用时不增加请求头重新请求即可从用户目录读取缓存使用。 +* 普通:网络接口如UnityWebRequest支持通过添加特殊请求头`request.SetRequestHeader("wechatminigame-skipclean", "1")`不做旧缓存淘汰。 +* 普通:适配插件版本升级到1.2.50 + ### Fixed -* 普通:修复Unity2018/2019的兼容 -* 普通:兼容Windows 1.0.4版本template问题 -* 普通:修复Android平台导出时的 +* 普通:修复团结版dotnet wasm加载报错 +* 普通:修复音频的长度为负数时的异常stop +* 普通:修复配置文件重置bug ## 2024-4-17 【普通更新】 ### Feature diff --git a/Editor/WXConvertCore.cs b/Editor/WXConvertCore.cs index 20c9bd768..13244d5eb 100644 --- a/Editor/WXConvertCore.cs +++ b/Editor/WXConvertCore.cs @@ -10,6 +10,7 @@ using UnityEngine.Rendering; using LitJson; using UnityEditor.Build; using System.Linq; +using static WeChatWASM.LifeCycleEvent; namespace WeChatWASM { @@ -18,7 +19,7 @@ namespace WeChatWASM static WXConvertCore() { - // Init(); + } public static void Init() @@ -94,11 +95,18 @@ namespace WeChatWASM // 可以调用这个来集成 public static WXExportError DoExport(bool buildWebGL = true) { + LifeCycleEvent.Init(); + Emit(LifeCycle.beforeExport); if (!CheckSDK()) { Debug.LogError("若游戏曾使用旧版本微信SDK,需删除 Assets/WX-WASM-SDK 文件夹后再导入最新工具包。"); return WXExportError.BUILD_WEBGL_FAILED; } + if (!CheckBuildTemplate()) + { + Debug.LogError("因构建模板检查失败终止导出。"); + return WXExportError.BUILD_WEBGL_FAILED; + } CheckBuildTarget(); Init(); // JSLib @@ -129,7 +137,7 @@ namespace WeChatWASM { // 如果是2021版本,官方symbols产生有BUG,这里需要用工具将函数名提取出来 var symFile1 = ""; - if(!UseIL2CPP) + if (!UseIL2CPP) { symFile1 = Path.Combine(config.ProjectConf.DST, webglDir, "Code", "wwwroot", "_framework", "dotnet.native.js.symbols"); } @@ -162,7 +170,7 @@ namespace WeChatWASM } File.Copy(dataFilePath, dataFilePathBackupPath); - if (UseIL2CPP && config.CompileOptions.fbslim && !IsInstantGameAutoStreaming()) + if (UnityUtil.GetEngineVersion() == 0 && config.CompileOptions.fbslim && !IsInstantGameAutoStreaming()) { WXAssetsTextTools.FirstBundleSlim(dataFilePath, (result, info) => { @@ -184,6 +192,7 @@ namespace WeChatWASM private static void CheckBuildTarget() { + Emit(LifeCycle.beforeSwitchActiveBuildTarget); if (UnityUtil.GetEngineVersion() == UnityUtil.EngineVersion.Unity) { EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.WebGL, BuildTarget.WebGL); @@ -194,6 +203,7 @@ namespace WeChatWASM EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.WeixinMiniGame, BuildTarget.WeixinMiniGame); #endif } + Emit(LifeCycle.afterSwitchActiveBuildTarget); } public static void UpdateGraphicAPI() @@ -270,7 +280,26 @@ namespace WeChatWASM return output.ToString(); } - + private static bool CheckBuildTemplate() + { + string[] res = BuildTemplate.CheckCustomCoverBaseConflict( + Path.Combine(UnityUtil.GetWxSDKRootPath(), "Runtime", "wechat-default"), + Path.Combine(Application.dataPath, "WX-WASM-SDK-V2", "Editor", "template"), + new string[]{ @"\.(js|ts|json)$" } + ); + if (res.Length != 0) + { + Debug.LogError("系统发现自定义构建模板中存在以下文件对应的基础模板已被更新,为确保游戏导出正常工作请自行解决可能存在的冲突:"); + for (int i = 0; i < res.Length; i++) + { + Debug.LogError($"自定义模板文件 [{i}]: [ {res[i]} ]"); + } + Debug.LogError("有关上述警告产生原因及处理办法请阅读:https://wechat-miniprogram.github.io/minigame-unity-webgl-transform/Design/BuildTemplate.html#%E6%96%B0%E7%89%88%E6%9C%ACsdk%E5%BC%95%E8%B5%B7%E7%9A%84%E5%86%B2%E7%AA%81%E6%8F%90%E9%86%92"); + return false; + } + return true; + } + private static void ConvertDotnetCode() { CompressAssemblyBrotli(); @@ -298,7 +327,8 @@ namespace WeChatWASM }; foreach (var rule in rules) { - if (ShowMatchFailedWarning(dotnetJs, rule.old, "runtime") == false) { + if (ShowMatchFailedWarning(dotnetJs, rule.old, "runtime") == false) + { dotnetJs = Regex.Replace(dotnetJs, rule.old, rule.newStr); } } @@ -318,188 +348,17 @@ namespace WeChatWASM Path.Combine(config.ProjectConf.DST, webglDir, "Code", "wwwroot", "_framework", "dotnet.js"); var dotnetJs = File.ReadAllText(dotnetJsPath, Encoding.UTF8); // todo: handle dotnet js - Rule[] rules = - { - new Rule() - { - old = "import\\.meta\\.url", - newStr = $"pathToFileURL('/{frameworkDir}/webgl.wasm.framework.unityweb.js')", - }, - new Rule() - { - old = " *(\\w*) *= *(\\w*)\\(\"js-module-runtime\"\\) *, *(\\w*) *= *(\\w*)\\(\"js-module-native\"\\)", - newStr = $" $1 = $2(\"js-module-runtime\"), $3 = $4(\"js-module-native\"); $1.resolvedUrl = \"{Path.GetFileName(GetWeixinMiniGameFilePath("jsModuleRuntime")[0])}\";$3.resolvedUrl = \"{Path.GetFileName(GetWeixinMiniGameFilePath("jsModuleNative")[0])}\";", - }, - new Rule() - { - old = "export *\\{ *(.*) *as *default *,(.*) *as *dotnet *,(.*) *as *exit *\\} *;", - newStr = "return {legacyEntrypoint: $1, dotnet: $2, exit: $3}", - }, - new Rule() - { // add symbol property for monoToBlazorAssetTypeMap - old = "\"js-module-runtime\": *\"dotnetjs\", *\"js-module-threads\": *\"dotnetjs\"", - newStr = "\"js-module-runtime\": \"dotnetjs\", \"js-module-threads\": \"dotnetjs\", \"symbols\": \"symbols\"", - }, - new Rule() - { - old = "_e *\\|\\| *\"function\" *== *typeof *globalThis.URL[\\s\\S]*asm-features\"\\);", - newStr = "" - }, - new Rule() - { - old = "if *\\(!\\(ENVIRONMENT_IS_SHELL *\\|\\| *typeof *globalThis.URL *=== *\"function\"\\)\\)[\\s\\S]*BigInt64Array *API. *Please *use *a *modern *version. *See *also *https:\\/\\/aka.ms\\/dotnet\\-wasm\\-features\"\\);", - newStr = "" - } - }; - foreach (var rule in rules) + foreach (var rule in ReplaceRules.DoenetRules(new string[] { frameworkDir, + Path.GetFileName(GetWeixinMiniGameFilePath("jsModuleRuntime")[0]), + Path.GetFileName(GetWeixinMiniGameFilePath("jsModuleNative")[0]), + })) { - if (ShowMatchFailedWarning(dotnetJs, rule.old, "dotnet") == false) { + if (ShowMatchFailedWarning(dotnetJs, rule.old, "dotnet") == false) + { dotnetJs = Regex.Replace(dotnetJs, rule.old, rule.newStr); } } - var header = @"WebAssembly.validate = () => true; -const dotnet = (function () {"; - var footer = @"})(); - -function pathToFileURL(path) { - return `file://${path}`; -} - -const wxFetchFile = async (url, config) => new Promise((resolve, reject) => { - const folderPath = `${GameGlobal.manager.PLUGIN_CACHE_PATH}/${config.hash}`; - const filePath = `${folderPath}/${config.filename}`; - const fs = wx.getFileSystemManager(); - var readFile = fs.readFile; - const readFileInfo = { - filePath: filePath, - success: async (res) => { - resolve(res.data); - }, - fail: (err) => { - reject(err); - } - } - if (config.brotli) { - readFile = fs.readCompressedFile; - readFileInfo.compressionAlgorithm = 'br'; - } - const downloadFileInfo = { - url: url, - success: (res) => { - if (res.statusCode === 200) { - try { - fs.accessSync(folderPath); - } catch (e) { - fs.mkdirSync(folderPath, true); - } - saveFile(res.tempFilePath, filePath, res.dataLength); - } else { - reject(res); - } - }, - fail: (err) => { - reject(err); - } - }; - const saveFile = (tempFilePath, filePath, dataLength, retry = 0) => { - try { - fs.saveFileSync(tempFilePath, filePath); - readFile(readFileInfo); - } catch (e) { - if (e.message === 'saveFileSync:fail exceeded the maximum size of the file storage limit') { - if (retry < 3) { - GameGlobal.manager.cleanCache(dataLength).then(() => { - saveFile(tempFilePath, filePath, dataLength, ++retry); - }); - } else { - GameGlobal.manager.cleanAllCache().then(() => { - wx.downloadFile(downloadFileInfo); - }); - } - } else { - reject(e); - } - } - }; - // if not use cache or cache not exists, download file - fs.access({ - path: filePath, - success: (res) => { - if (config.cache && res.errMsg === 'access:ok') { - readFile(readFileInfo); - } else { - wx.downloadFile(downloadFileInfo); - } - }, - fail: (err) => { - wx.downloadFile(downloadFileInfo); - } - }); -}); - -dotnet.dotnet.withResourceLoader((resourceType, assetName, url, requestHash, behavior) => { - const remoteUrl = `${GameGlobal.unityNamespace.DATA_CDN}Code/wwwroot/_framework/${assetName}`; - switch (resourceType) { - case 'dotnetjs': - return assetName; - case 'manifest': - return new Promise((resolve, reject) => { - wx.request({ - url: remoteUrl, - success: (res) => { - resolve({ - json: async () => res.data, - headers: { - get: () => undefined - } - }); - }, - fail: (err) => { - reject(err); - } - }); - }); - case 'symbols': - case 'dotnetwasm': - return new Promise((resolve, reject) => { - resolve({ - arrayBuffer: async () => undefined, - status: 200, - ok: true - }) - }); - case 'assembly': - const config = { - filename: assetName + '.br', - cache: true, - hash: requestHash, - brotli: true - }; - return wxFetchFile(remoteUrl + '.br', config).then(res => ({ - arrayBuffer: async () => res, - status: 200, - ok: true, - })); - default: - return url; - } -}); -var executed = false; -var unityFramework = function (module) { - if (executed) return; - executed = true; - module['noInitialRun'] = true; - return (dotnet.legacyEntrypoint(module)).then(() => { - module['callMain'](); - }); -}; -if (typeof exports === 'object' && typeof module === 'object') module.exports = unityFramework; -else if (typeof define === 'function' && define['amd']) define([], function () { - return unityFramework; -}); -else if (typeof exports === 'object') exports['unityFramework'] = unityFramework; -GameGlobal.unityNamespace.UnityModule = unityFramework;"; - File.WriteAllText(Path.Combine(config.ProjectConf.DST, miniGameDir, frameworkDir, target), header + dotnetJs + footer, new UTF8Encoding(false)); + File.WriteAllText(Path.Combine(config.ProjectConf.DST, miniGameDir, frameworkDir, target), ReplaceRules.DotnetHeader + dotnetJs + ReplaceRules.DotnetFooter, new UTF8Encoding(false)); } private static void ConvertCode() @@ -529,14 +388,19 @@ GameGlobal.unityNamespace.UnityModule = unityFramework;"; int i; for (i = 0; i < ReplaceRules.rules.Length; i++) { + var current = i + 1; + var total = ReplaceRules.rules.Length; + EditorUtility.DisplayProgressBar($"Converting...,{current}/{total}", "Replace holder...", current * 1.0f / total); var rule = ReplaceRules.rules[i]; // text = Regex.Replace(text, rule.old, rule.newStr); - if (ShowMatchFailedWarning(text, rule.old, "WXReplaceRules") == false) { + if (ShowMatchFailedWarning(text, rule.old, "WXReplaceRules") == false) + { text = Regex.Replace(text, rule.old, rule.newStr); } } - string[] prefixs = - { + EditorUtility.ClearProgressBar(); + string[] prefixs = + { "_JS_Video_", //"jsVideo", "_JS_Sound_", @@ -606,7 +470,7 @@ GameGlobal.unityNamespace.UnityModule = unityFramework;"; } var header = "var OriginalAudioContext = window.AudioContext || window.webkitAudioContext;window.AudioContext = function() {if (this instanceof window.AudioContext) {return wx.createWebAudioContext();} else {return new OriginalAudioContext();}};"; - + if (config.CompileOptions.DevelopBuild) { header = header + RenderAnalysisRules.header; @@ -623,44 +487,13 @@ GameGlobal.unityNamespace.UnityModule = unityFramework;"; if (!UseIL2CPP) { targetPath = Path.Combine(config.ProjectConf.DST, miniGameDir, frameworkDir, target); - Rule[] nativeRules = + + foreach (var rule in ReplaceRules.NativeRules) { - new Rule() + if (ShowMatchFailedWarning(text, rule.old, "native") == false) { - old = "if\\(Module\\.IsWxGame\\)return Math\\.random\\(\\)\\*256\\|0;abort\\(\"randomDevice\"\\)", - newStr = "{if(Module.IsWxGame)return Math.random()*256|0;abort(\"randomDevice\")}" - }, - new Rule() - { - old = "var *_scriptDir *= *import\\.meta\\.url;", - newStr = $"var _scriptDir = \"file:///framework/webgl.wasm.framework.unityweb.js\"", - }, - new Rule() - { - old = "import\\.meta\\.url", - newStr = "_scriptDir" - }, - new Rule() - { - old = "Module\\[['\"](HEAP[U,F,1-9]*)['\"]\\] *=", - newStr = "Module['$1'] = GameGlobal.unityNamespace.Module['$1'] =", - }, - new Rule() - { - old = "return *handleException\\(e\\);?", - newStr = "return handleException(e);} finally {if (ABORT === true) return; if (Module.calledMainCb) Module.calledMainCb(); if (GameGlobal.unityNamespace.enableProfileStats) {setTimeout(() => {SendMessage('WXSDKManagerHandler', 'OpenProfileStats');}, 10000);}" - }, - new Rule() - { - old = "function *callMain\\(args *= *\\[\\]\\)", - newStr = "Object.keys(Module).forEach(key=>{if(!(key in Object.keys(GameGlobal.unityNamespace.Module))){GameGlobal.unityNamespace.Module[key]=Module[key];}});function callMain(args = [])" - }, - }; - foreach (var rule in nativeRules) - { - if (ShowMatchFailedWarning(text, rule.old, "native") == false) { text = Regex.Replace(text, rule.old, rule.newStr); - } + } } } @@ -840,6 +673,25 @@ GameGlobal.unityNamespace.UnityModule = unityFramework;"; { var bootJson = Path.Combine(config.ProjectConf.DST, webglDir, "Code", "wwwroot", "_framework", "blazor.boot.json"); var boot = JsonMapper.ToObject(File.ReadAllText(bootJson, Encoding.UTF8)); + // Disable jiterpreter if haven't set + if (!boot.ContainsKey("environmentVariables")) + { + var jd = new JsonData(); + jd["INTERP_OPTS"] = "-jiterp"; + boot["environmentVariables"] = jd; + JsonWriter writer = new JsonWriter(); + boot.ToJson(writer); + File.WriteAllText(bootJson, writer.TextWriter.ToString()); + Debug.Log("Env INTERP_OPTS added to blazor.boot.json"); + } + else if (!boot["environmentVariables"].ContainsKey("INTERP_OPTS")) + { + boot["environmentVariables"]["INTERP_OPTS"] = "-jiterp"; + JsonWriter writer = new JsonWriter(); + boot.ToJson(writer); + File.WriteAllText(bootJson, writer.TextWriter.ToString()); + Debug.Log("Env INTERP_OPTS added to blazor.boot.json"); + } return boot["resources"][key].Keys.Select(file => Path.Combine(config.ProjectConf.DST, webglDir, "Code", "wwwroot", "_framework", file)).ToArray(); } @@ -851,6 +703,7 @@ GameGlobal.unityNamespace.UnityModule = unityFramework;"; convertDataPackage(false); UnityEngine.Debug.LogFormat("[Converter] All done!"); //ShowNotification(new GUIContent("转换完成")); + Emit(LifeCycle.exportDone); } else { @@ -1032,80 +885,6 @@ GameGlobal.unityNamespace.UnityModule = unityFramework;"; } } - private static bool CopyDirectory(string SourcePath, string DestinationPath, bool overwriteexisting) - { - bool ret = false; - var separator = Path.DirectorySeparatorChar; - var ignoreFiles = new List() { "unityNamespace.js" }; - - // eventEmitter - 改名为event-emitter - // loading和libs 是可交互视频用到的文件,先下掉可交互方案 - var ignoreDirs = new List() { "eventEmitter", "loading", "libs" }; - try - { - if (Directory.Exists(SourcePath)) - { - if (Directory.Exists(DestinationPath) == false) - { - Directory.CreateDirectory(DestinationPath); - } - else - { - // 已经存在,删掉目录下无用的文件 - foreach (string filename in ignoreFiles) - { - var filepath = Path.Combine(DestinationPath, filename); - if (File.Exists(filepath)) - { - File.Delete(filepath); - } - } - - foreach (string dir in ignoreDirs) - { - var dirpath = Path.Combine(DestinationPath, dir); - if (Directory.Exists(dirpath)) - { - Directory.Delete(dirpath); - } - } - } - - foreach (string fls in Directory.GetFiles(SourcePath)) - { - FileInfo flinfo = new FileInfo(fls); - if (flinfo.Extension == ".meta" || ignoreFiles.Contains(flinfo.Name)) - { - continue; - } - flinfo.CopyTo(Path.Combine(DestinationPath, flinfo.Name), overwriteexisting); - } - - foreach (string drs in Directory.GetDirectories(SourcePath)) - { - DirectoryInfo drinfo = new DirectoryInfo(drs); - if (ignoreDirs.Contains(drinfo.Name)) - { - continue; - } - if (CopyDirectory(drs, Path.Combine(DestinationPath, drinfo.Name), overwriteexisting) == false) - { - ret = false; - } - } - } - - ret = true; - } - catch (Exception ex) - { - ret = false; - UnityEngine.Debug.LogError(ex); - } - - return ret; - } - public static string FirstBundlePath = ""; public static int GenerateBinFile(bool isFromConvert = false) { @@ -1119,8 +898,12 @@ GameGlobal.unityNamespace.UnityModule = unityFramework;"; RemoveOldAssetPackage(Path.Combine(config.ProjectConf.DST, webglDir)); RemoveOldAssetPackage(Path.Combine(config.ProjectConf.DST, webglDir + "-min")); - // CopyDirectory(Path.Combine(Application.dataPath, "WX-WASM-SDK-V2", "Runtime", "wechat-default"), Path.Combine(config.ProjectConf.DST, miniGameDir), true); - CopyDirectory(Path.Combine(UnityUtil.GetWxSDKRootPath(), "Runtime", "wechat-default"), Path.Combine(config.ProjectConf.DST, miniGameDir), true); + var buildTemplate = new BuildTemplate( + Path.Combine(UnityUtil.GetWxSDKRootPath(), "Runtime", "wechat-default"), + Path.Combine(Application.dataPath, "WX-WASM-SDK-V2", "Editor", "template"), + Path.Combine(config.ProjectConf.DST, miniGameDir) + ); + buildTemplate.start(); // FIX: 2021.2版本生成symbol有bug,导出时生成symbol报错,有symbol才copy // 代码分包需要symbol文件以进行增量更新 if (File.Exists(symbolPath)) @@ -1353,6 +1136,59 @@ GameGlobal.unityNamespace.UnityModule = unityFramework;"; return preloadList; } + private static string GetCustomUnicodeRange(string customUnicode) + { + if (customUnicode == string.Empty) + { + return "[]"; + } + + List unicodeCodes = new List(); + // 将字符串中的每个字符转换为Unicode编码并存储在数组中 + foreach (char c in customUnicode) + { + unicodeCodes.Add(char.ConvertToUtf32(c.ToString(), 0)); + } + + // 对数组进行排序 + unicodeCodes.Sort(); + + // 将连续的编码合并为范围 + List> ranges = new List>(); + int startRange = unicodeCodes[0]; + int endRange = unicodeCodes[0]; + + for (int i = 1; i < unicodeCodes.Count; i++) + { + if(unicodeCodes[i] == endRange) + { + continue; + } + else if (unicodeCodes[i] == endRange + 1) + { + endRange = unicodeCodes[i]; + } + else + { + ranges.Add(Tuple.Create(startRange, endRange)); + startRange = endRange = unicodeCodes[i]; + } + } + ranges.Add(Tuple.Create(startRange, endRange)); + + StringBuilder ret = new StringBuilder(); + // 输出范围 + foreach (var range in ranges) + { + ret.AppendFormat("[0x{0:X}, 0x{1:X}], ", range.Item1, range.Item2); + } + // 移除字符串末尾的多余", " + ret.Length -= 2; + ret.Insert(0, "["); + ret.Append("]"); + + return ret.ToString(); + } public static void ModifyWeChatConfigs(bool isFromConvert = false) { @@ -1368,6 +1204,9 @@ GameGlobal.unityNamespace.UnityModule = unityFramework;"; var screenOrientation = new List() { "portrait", "landscape", "landscapeLeft", "landscapeRight" }[(int)config.ProjectConf.Orientation]; + var customUnicodeRange = GetCustomUnicodeRange(config.FontOptions.CustomUnicode); + Debug.Log("customUnicodeRange: " + customUnicodeRange); + Rule[] replaceArrayList = ReplaceRules.GenRules(new string[] { config.ProjectConf.projectName == string.Empty ? "webgl" : config.ProjectConf.projectName, config.ProjectConf.Appid, @@ -1407,13 +1246,33 @@ GameGlobal.unityNamespace.UnityModule = unityFramework;"; config.ProjectConf.IOSDevicePixelRatio.ToString(), UseIL2CPP ? "" : "/framework", UseIL2CPP ? "false" : "true", + // FontOptions + config.FontOptions.CJK_Unified_Ideographs ? "true" : "false", + config.FontOptions.C0_Controls_and_Basic_Latin ? "true" : "false", + config.FontOptions.CJK_Symbols_and_Punctuation ? "true" : "false", + config.FontOptions.General_Punctuation ? "true" : "false", + config.FontOptions.Enclosed_CJK_Letters_and_Months ? "true" : "false", + config.FontOptions.Vertical_Forms ? "true" : "false", + config.FontOptions.CJK_Compatibility_Forms ? "true" : "false", + config.FontOptions.Miscellaneous_Symbols ? "true" : "false", + config.FontOptions.CJK_Compatibility ? "true" : "false", + config.FontOptions.Halfwidth_and_Fullwidth_Forms ? "true" : "false", + config.FontOptions.Dingbats ? "true" : "false", + config.FontOptions.Letterlike_Symbols ? "true" : "false", + config.FontOptions.Enclosed_Alphanumerics ? "true" : "false", + config.FontOptions.Number_Forms ? "true" : "false", + config.FontOptions.Currency_Symbols ? "true" : "false", + config.FontOptions.Arrows ? "true" : "false", + config.FontOptions.Geometric_Shapes ? "true" : "false", + config.FontOptions.Mathematical_Operators ? "true" : "false", + customUnicodeRange, }); List replaceList = new List(replaceArrayList); - List files = new List { "game.js", "game.json", "project.config.json", "unity-namespace.js", "check-version.js" }; + List files = new List { "game.js", "game.json", "project.config.json", "unity-namespace.js", "check-version.js", "unity-sdk/font/index.js" }; ReplaceFileContent(files.ToArray(), replaceList.ToArray()); - + Emit(LifeCycle.afterBuildTemplate); UnityEngine.Debug.LogFormat("[Converter] that to modify configs ended"); } @@ -1511,13 +1370,13 @@ GameGlobal.unityNamespace.UnityModule = unityFramework;"; string jsLibRootDir = $"Assets{DS}WX-WASM-SDK-V2{DS}Runtime{DS}Plugins{DS}"; // 下方顺序不可变动 - jsLibs = new string[] - { + jsLibs = new string[] + { $"{jsLibRootDir}SDK-WX-TextureMin-JS-WEBGL1.jslib", $"{jsLibRootDir}SDK-WX-TextureMin-JS-WEBGL2.jslib", $"{jsLibRootDir}SDK-WX-TextureMin-JS-WEBGL2-Linear.jslib", - }; - } + }; + } int index = 0; if (config.CompileOptions.Webgl2) { @@ -1575,7 +1434,8 @@ GameGlobal.unityNamespace.UnityModule = unityFramework;"; public static bool ShowMatchFailedWarning(string text, string rule, string file) { - if (Regex.IsMatch(text, rule) == false) { + if (Regex.IsMatch(text, rule) == false) + { Debug.LogWarning($"UnMatched {file} rule: {rule}"); return true; } diff --git a/Editor/WXEditorSettingHelper.cs b/Editor/WXEditorSettingHelper.cs index b68aa4d39..11f5072a2 100644 --- a/Editor/WXEditorSettingHelper.cs +++ b/Editor/WXEditorSettingHelper.cs @@ -9,7 +9,7 @@ using System.Reflection; namespace WeChatWASM { - + [InitializeOnLoad] public class WXSettingsHelperInterface { @@ -183,7 +183,7 @@ namespace WeChatWASM this.formCheckbox("deleteStreamingAssets", "Clear Streaming Assets"); this.formCheckbox("cleanBuild", "Clean WebGL Build"); // this.formCheckbox("cleanCloudDev", "Clean Cloud Dev"); - this.formCheckbox("fbslim", "首包资源优化(?)", "导出时自动清理UnityEditor默认打包但游戏项目从未使用的资源,瘦身首包资源体积,建议所有游戏启用。(Dotnet Runtime模式下该选项暂不支持)", !UseIL2CPP, (res) => + this.formCheckbox("fbslim", "首包资源优化(?)", "导出时自动清理UnityEditor默认打包但游戏项目从未使用的资源,瘦身首包资源体积。(团结引擎已无需开启该能力)", UnityUtil.GetEngineVersion() > 0, (res) => { var fbWin = EditorWindow.GetWindow(typeof(WXFbSettingWindow), false, "首包资源优化配置面板", true); fbWin.minSize = new Vector2(680, 350); @@ -242,6 +242,31 @@ namespace WeChatWASM EditorGUILayout.EndVertical(); } #endif + foldFontOptions = EditorGUILayout.Foldout(foldFontOptions, "字体配置"); + if (foldFontOptions) + { + EditorGUILayout.BeginVertical("frameBox", GUILayout.ExpandWidth(true)); + this.formCheckbox("CJK_Unified_Ideographs", "基本汉字(?)", "Unicode [0x4e00, 0x9fff]"); + this.formCheckbox("C0_Controls_and_Basic_Latin", "基本拉丁语(英文大小写、数字、英文标点)(?)", "Unicode [0x0, 0x7f]"); + this.formCheckbox("CJK_Symbols_and_Punctuation", "中文标点符号(?)", "Unicode [0x3000, 0x303f]"); + this.formCheckbox("General_Punctuation", "通用标点符号(?)", "Unicode [0x2000, 0x206f]"); + this.formCheckbox("Enclosed_CJK_Letters_and_Months", "CJK字母及月份(?)", "Unicode [0x3200, 0x32ff]"); + this.formCheckbox("Vertical_Forms", "中文竖排标点(?)", "Unicode [0xfe10, 0xfe1f]"); + this.formCheckbox("CJK_Compatibility_Forms", "CJK兼容符号(?)", "Unicode [0xfe30, 0xfe4f]"); + this.formCheckbox("Miscellaneous_Symbols", "杂项符号(?)", "Unicode [0x2600, 0x26ff]"); + this.formCheckbox("CJK_Compatibility", "CJK特殊符号(?)", "Unicode [0x3300, 0x33ff]"); + this.formCheckbox("Halfwidth_and_Fullwidth_Forms", "全角ASCII、全角中英文标点、半宽片假名、半宽平假名、半宽韩文字母(?)", "Unicode [0xff00, 0xffef]"); + this.formCheckbox("Dingbats", "装饰符号(?)", "Unicode [0x2700, 0x27bf]"); + this.formCheckbox("Letterlike_Symbols", "字母式符号(?)", "Unicode [0x2100, 0x214f]"); + this.formCheckbox("Enclosed_Alphanumerics", "带圈或括号的字母数字(?)", "Unicode [0x2460, 0x24ff]"); + this.formCheckbox("Number_Forms", "数字形式(?)", "Unicode [0x2150, 0x218f]"); + this.formCheckbox("Currency_Symbols", "货币符号(?)", "Unicode [0x20a0, 0x20cf]"); + this.formCheckbox("Arrows", "箭头(?)", "Unicode [0x2190, 0x21ff]"); + this.formCheckbox("Geometric_Shapes", "几何图形(?)", "Unicode [0x25a0, 0x25ff]"); + this.formCheckbox("Mathematical_Operators", "数学运算符号(?)", "Unicode [0x2200, 0x22ff]"); + this.formInput("CustomUnicode", "自定义Unicode(?)", "将填入的所有字符强制加入字体预加载列表"); + EditorGUILayout.EndVertical(); + } EditorGUILayout.EndScrollView(); } @@ -314,7 +339,7 @@ namespace WeChatWASM EditorGUILayout.LabelField(string.Empty); if (GUILayout.Button(new GUIContent("了解如何实现自定义构建", ""), linkStyle)) { - Application.OpenURL("https://github.com/wechat-miniprogram/minigame-unity-webgl-transform/blob/main/Design/DevelopmentQAList.md#13%E5%A6%82%E4%BD%95%E8%87%AA%E5%AE%9A%E4%B9%89%E6%8E%A5%E5%85%A5%E6%9E%84%E5%BB%BA%E6%B5%81%E7%A8%8B"); + Application.OpenURL("https://wechat-miniprogram.github.io/minigame-unity-webgl-transform/Design/DevelopmentQAList.html#_13-%E5%A6%82%E4%BD%95%E8%87%AA%E5%AE%9A%E4%B9%89%E6%8E%A5%E5%85%A5%E6%9E%84%E5%BB%BA%E6%B5%81%E7%A8%8B"); GUIUtility.ExitGUI(); } EditorGUILayout.EndHorizontal(); @@ -326,6 +351,7 @@ namespace WeChatWASM private bool foldSDKOptions = true; private bool foldDebugOptions = true; private bool foldInstantGame = false; + private bool foldFontOptions = false; private Dictionary formInputData = new Dictionary(); private Dictionary formIntPopupData = new Dictionary(); private Dictionary formCheckboxData = new Dictionary(); @@ -426,6 +452,27 @@ namespace WeChatWASM this.setData("enableProfileStats", config.CompileOptions.enableProfileStats); this.setData("enableRenderAnalysis", config.CompileOptions.enableRenderAnalysis); this.setData("autoUploadFirstBundle", true); + + // font options + this.setData("CJK_Unified_Ideographs", config.FontOptions.CJK_Unified_Ideographs); + this.setData("C0_Controls_and_Basic_Latin", config.FontOptions.C0_Controls_and_Basic_Latin); + this.setData("CJK_Symbols_and_Punctuation", config.FontOptions.CJK_Symbols_and_Punctuation); + this.setData("General_Punctuation", config.FontOptions.General_Punctuation); + this.setData("Enclosed_CJK_Letters_and_Months", config.FontOptions.Enclosed_CJK_Letters_and_Months); + this.setData("Vertical_Forms", config.FontOptions.Vertical_Forms); + this.setData("CJK_Compatibility_Forms", config.FontOptions.CJK_Compatibility_Forms); + this.setData("Miscellaneous_Symbols", config.FontOptions.Miscellaneous_Symbols); + this.setData("CJK_Compatibility", config.FontOptions.CJK_Compatibility); + this.setData("Halfwidth_and_Fullwidth_Forms", config.FontOptions.Halfwidth_and_Fullwidth_Forms); + this.setData("Dingbats", config.FontOptions.Dingbats); + this.setData("Letterlike_Symbols", config.FontOptions.Letterlike_Symbols); + this.setData("Enclosed_Alphanumerics", config.FontOptions.Enclosed_Alphanumerics); + this.setData("Number_Forms", config.FontOptions.Number_Forms); + this.setData("Currency_Symbols", config.FontOptions.Currency_Symbols); + this.setData("Arrows", config.FontOptions.Arrows); + this.setData("Geometric_Shapes", config.FontOptions.Geometric_Shapes); + this.setData("Mathematical_Operators", config.FontOptions.Mathematical_Operators); + this.setData("CustomUnicode", config.FontOptions.CustomUnicode); } private void saveData() @@ -472,6 +519,27 @@ namespace WeChatWASM config.CompileOptions.showMonitorSuggestModal = this.getDataCheckbox("showMonitorSuggestModal"); config.CompileOptions.enableProfileStats = this.getDataCheckbox("enableProfileStats"); config.CompileOptions.enableRenderAnalysis = this.getDataCheckbox("enableRenderAnalysis"); + + // font options + config.FontOptions.CJK_Unified_Ideographs = this.getDataCheckbox("CJK_Unified_Ideographs"); + config.FontOptions.C0_Controls_and_Basic_Latin = this.getDataCheckbox("C0_Controls_and_Basic_Latin"); + config.FontOptions.CJK_Symbols_and_Punctuation = this.getDataCheckbox("CJK_Symbols_and_Punctuation"); + config.FontOptions.General_Punctuation = this.getDataCheckbox("General_Punctuation"); + config.FontOptions.Enclosed_CJK_Letters_and_Months = this.getDataCheckbox("Enclosed_CJK_Letters_and_Months"); + config.FontOptions.Vertical_Forms = this.getDataCheckbox("Vertical_Forms"); + config.FontOptions.CJK_Compatibility_Forms = this.getDataCheckbox("CJK_Compatibility_Forms"); + config.FontOptions.Miscellaneous_Symbols = this.getDataCheckbox("Miscellaneous_Symbols"); + config.FontOptions.CJK_Compatibility = this.getDataCheckbox("CJK_Compatibility"); + config.FontOptions.Halfwidth_and_Fullwidth_Forms = this.getDataCheckbox("Halfwidth_and_Fullwidth_Forms"); + config.FontOptions.Dingbats = this.getDataCheckbox("Dingbats"); + config.FontOptions.Letterlike_Symbols = this.getDataCheckbox("Letterlike_Symbols"); + config.FontOptions.Enclosed_Alphanumerics = this.getDataCheckbox("Enclosed_Alphanumerics"); + config.FontOptions.Number_Forms = this.getDataCheckbox("Number_Forms"); + config.FontOptions.Currency_Symbols = this.getDataCheckbox("Currency_Symbols"); + config.FontOptions.Arrows = this.getDataCheckbox("Arrows"); + config.FontOptions.Geometric_Shapes = this.getDataCheckbox("Geometric_Shapes"); + config.FontOptions.Mathematical_Operators = this.getDataCheckbox("Mathematical_Operators"); + config.FontOptions.CustomUnicode = this.getDataInput("CustomUnicode"); } private string getDataInput(string target) @@ -598,5 +666,5 @@ namespace WeChatWASM } - + } diff --git a/Editor/WXPluginVersion.cs b/Editor/WXPluginVersion.cs index 561d534e5..1597329fd 100644 --- a/Editor/WXPluginVersion.cs +++ b/Editor/WXPluginVersion.cs @@ -2,7 +2,7 @@ { public class WXPluginVersion { - public static string pluginVersion = "202404262000"; // 这一行不要改他,导出的时候会自动替换 + public static string pluginVersion = "202405151937"; // 这一行不要改他,导出的时候会自动替换 } public class WXPluginConf diff --git a/Editor/wx-editor.dll b/Editor/wx-editor.dll index 14790a2d5..3be12a8d5 100644 Binary files a/Editor/wx-editor.dll and b/Editor/wx-editor.dll differ diff --git a/Editor/wx-editor.xml b/Editor/wx-editor.xml index c98ea4a67..f0a11695e 100644 --- a/Editor/wx-editor.xml +++ b/Editor/wx-editor.xml @@ -4,6 +4,123 @@ wx-editor + + + 构建模板工具类 + + + + + 复制覆盖时不参与覆盖的正则表达式,可动态修改 + + + + + 防止自定义模板对覆盖基础模板有覆盖在新版本更新后有代码冲突需要做此检查 + + + + + 基础模板导出至输出目录 + + + + + 检查是否存在构建模板 + + + + + 构建模板覆盖至输出目录 + + + + + 强制将 srcDir 目录中资源逐层覆盖至 dstDir 目录中 + + 源目录 + 目标目录 + 忽略规则 + 清理dstDir中没有srcDir的资源 + + + + 强制将 srcDir 目录中资源逐层覆盖至 dstDir 目录中 + + 源目录 + 目标目录 + 忽略规则 + + + + 记录处理前的 Assets 内容 + + + + + 还原最后一次 SaveAssets 内容 + + + + + 基础模板根目录,所有文件变动请勿离开该目录内 + + + + + 自定义模板根目录,所有文件变动请勿离开该目录 + + + + + 导出产物 minigame 目录,所有文件变动请勿离开该目录 + + + + + 在正式导出前 + + + + + 在完全导出后 + + + + + 在切换构建平台前 + + + + + 在切换构建平台后 + + + + + 在复制基础模板前 + + + + + 在复制基础模板完成后 + + + + + 在覆盖自定义模板前 + + + + + 在覆盖自定义模板完成后 + + + + + 在构建模板流程结束后 + + 微信团队提供的资源纹理处理工具,可对微信小游戏首包资源、AssetsBundle进行专项的纹理资源处理操作 @@ -492,6 +609,101 @@ 是否使用iOS高性能Plus + + + 基本汉字 [0x4e00, 0x9fff] https://www.unicode.org/charts/PDF/U4E00.pdf + + + + + 基本拉丁语(英文大小写、数字、英文标点) [0x0, 0x7f] https://www.unicode.org/charts/PDF/U0000.pdf + + + + + 中文标点符号 [0x3000, 0x303f] https://www.unicode.org/charts/PDF/U3000.pdf + + + + + 通用标点符号 [0x2000, 0x206f] https://www.unicode.org/charts/PDF/U2000.pdf + + + + + CJK字母及月份 [0x3200, 0x32ff] http://www.unicode.org/charts/PDF/U3200.pdf + + + + + 中文竖排标点 [0xfe10, 0xfe1f] http://www.unicode.org/charts/PDF/UFE10.pdf + + + + + CJK兼容符号 [0xfe30, 0xfe4f] http://www.unicode.org/charts/PDF/UFE30.pdf + + + + + 杂项符号 [0x2600, 0x26ff] http://www.unicode.org/charts/PDF/U2600.pdf + + + + + CJK特殊符号 [0x3300, 0x33ff] http://www.unicode.org/charts/PDF/U3300.pdf + + + + + 全角ASCII、全角中英文标点、半宽片假名、半宽平假名、半宽韩文字母 [0xff00, 0xffef] http://www.unicode.org/charts/PDF/UFF00.pdf + + + + + 装饰符号 [0x2700, 0x27bf] http://www.unicode.org/charts/PDF/U2700.pdf + + + + + 字母式符号 [0x2100, 0x214f] https://www.unicode.org/charts/PDF/U2100.pdf + + + + + 带圈或括号的字母数字 [0x2460, 0x24ff] https://www.unicode.org/charts/PDF/U2460.pdf + + + + + 数字形式 [0x2150, 0x218f] https://www.unicode.org/charts/PDF/U2150.pdf + + + + + 货币符号 [0x20a0, 0x20cf] https://www.unicode.org/charts/PDF/U20A0.pdf + + + + + 箭头 [0x2190, 0x21ff] https://www.unicode.org/charts/PDF/U2190.pdf + + + + + 几何图形 [0x25a0, 0x25ff] https://www.unicode.org/charts/PDF/U25A0.pdf + + + + + 数学运算符号 [0x2200, 0x22ff] https://www.unicode.org/charts/PDF/U2200.pdf + + + + + 自定义需要的Unicode字符 + + 压缩纹理配置 @@ -502,5 +714,10 @@ 小游戏里会预先加载的key + + + 字体配置 + + diff --git a/Runtime/Plugins/AES.jslib.meta b/Runtime/Plugins/AES.jslib.meta index 584976974..adf508e78 100644 --- a/Runtime/Plugins/AES.jslib.meta +++ b/Runtime/Plugins/AES.jslib.meta @@ -13,6 +13,36 @@ PluginImporter: platformData: - first: Any: + second: + enabled: 0 + settings: + Exclude Editor: 1 + Exclude Linux: 1 + Exclude Linux64: 1 + Exclude LinuxUniversal: 1 + Exclude OSXUniversal: 1 + Exclude WebGL: 1 + Exclude WeixinMiniGame: 0 + Exclude Win: 1 + Exclude Win64: 1 + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + - first: + Facebook: WebGL + second: + enabled: 0 + settings: {} + - first: + WebGL: WebGL + second: + enabled: 0 + settings: {} + - first: + WeixinMiniGame: WeixinMiniGame second: enabled: 1 settings: {} diff --git a/Runtime/Plugins/MD5.jslib.meta b/Runtime/Plugins/MD5.jslib.meta index 88fed3197..3f76a7662 100644 --- a/Runtime/Plugins/MD5.jslib.meta +++ b/Runtime/Plugins/MD5.jslib.meta @@ -13,6 +13,36 @@ PluginImporter: platformData: - first: Any: + second: + enabled: 0 + settings: + Exclude Editor: 1 + Exclude Linux: 1 + Exclude Linux64: 1 + Exclude LinuxUniversal: 1 + Exclude OSXUniversal: 1 + Exclude WebGL: 1 + Exclude WeixinMiniGame: 0 + Exclude Win: 1 + Exclude Win64: 1 + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + - first: + Facebook: WebGL + second: + enabled: 0 + settings: {} + - first: + WebGL: WebGL + second: + enabled: 0 + settings: {} + - first: + WeixinMiniGame: WeixinMiniGame second: enabled: 1 settings: {} diff --git a/Runtime/Plugins/crypto.jspre.meta b/Runtime/Plugins/crypto.jspre.meta index 231f01d46..cebbc7275 100644 --- a/Runtime/Plugins/crypto.jspre.meta +++ b/Runtime/Plugins/crypto.jspre.meta @@ -13,6 +13,36 @@ PluginImporter: platformData: - first: Any: + second: + enabled: 0 + settings: + Exclude Editor: 1 + Exclude Linux: 1 + Exclude Linux64: 1 + Exclude LinuxUniversal: 1 + Exclude OSXUniversal: 1 + Exclude WebGL: 1 + Exclude WeixinMiniGame: 0 + Exclude Win: 1 + Exclude Win64: 1 + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + - first: + Facebook: WebGL + second: + enabled: 0 + settings: {} + - first: + WebGL: WebGL + second: + enabled: 0 + settings: {} + - first: + WeixinMiniGame: WeixinMiniGame second: enabled: 1 settings: {} diff --git a/Runtime/Plugins/wx-runtime-editor.dll b/Runtime/Plugins/wx-runtime-editor.dll index 78966d915..a53eb222a 100644 Binary files a/Runtime/Plugins/wx-runtime-editor.dll and b/Runtime/Plugins/wx-runtime-editor.dll differ diff --git a/Runtime/Plugins/wx-runtime.dll b/Runtime/Plugins/wx-runtime.dll index c9b413006..8bc1d48a0 100644 Binary files a/Runtime/Plugins/wx-runtime.dll and b/Runtime/Plugins/wx-runtime.dll differ diff --git a/Runtime/WebAES.cs b/Runtime/WebAES.cs index d6389dfbe..5eaaf8124 100644 --- a/Runtime/WebAES.cs +++ b/Runtime/WebAES.cs @@ -1,4 +1,4 @@ -#if UNITY_WEBGL || WEIXINMINIGAME || UNITY_EDITOR +#if WEIXINMINIGAME && TUANJIE_2022_3_OR_NEWER using System.Runtime.InteropServices; using System.Security.Cryptography; using System.Text; @@ -31,7 +31,7 @@ namespace WeChatWASM public static extern void WebAesDecrypt(System.IntPtr encryptedBytesPtr, int size, int needStrip); // TODO: consider passing a unique id so that we can initialize multiple instances. - public static void Initialize(System.Security.Cryptography.CipherMode mode, byte[] key, + public static void Initialize(System.Security.Cryptography.CipherMode mode, byte[] key, byte[] iv, int counter = 0, int segmentSize = 0) { if (initialized) @@ -48,7 +48,7 @@ namespace WeChatWASM int keySize = key.Length; keyPtr = Marshal.AllocHGlobal(keySize); Marshal.Copy(key, 0, keyPtr, keySize); - + int ivSize = iv.Length; ivPtr = Marshal.AllocHGlobal(ivSize); Marshal.Copy(iv, 0, ivPtr, ivSize); @@ -59,7 +59,7 @@ namespace WeChatWASM counter, segmentSize); initialized = true; } - + [MonoPInvokeCallback(typeof(AesCallback))] public static void OnAecCrypto(int enc, System.IntPtr resPtr, int resSize) { @@ -85,13 +85,13 @@ namespace WeChatWASM initialized = false; WebAesFinalize(); } - + // Use UTF-8 as it is used as default format for StreamReader public static byte[] Encode(string plainStr, bool needPad = true) { var bytes = Encoding.UTF8.GetBytes(plainStr); var bytesPtr = Marshal.AllocHGlobal(bytes.Length); - Marshal.Copy(bytes, 0, bytesPtr, bytes.Length); + Marshal.Copy(bytes, 0, bytesPtr, bytes.Length); WebAesEncrypt(bytesPtr, bytes.Length, needPad ? 1 : 0); Marshal.FreeHGlobal(bytesPtr); return EncryptedBytes; @@ -100,7 +100,7 @@ namespace WeChatWASM public static string Decode(byte[] bytes, bool needStrip = true) { var bytesPtr = Marshal.AllocHGlobal(bytes.Length); - Marshal.Copy(bytes, 0, bytesPtr, bytes.Length); + Marshal.Copy(bytes, 0, bytesPtr, bytes.Length); WebAesDecrypt(bytesPtr, bytes.Length, needStrip ? 1 : 0); Marshal.FreeHGlobal(bytesPtr); return Encoding.UTF8.GetString(DecryptedBytes); diff --git a/Runtime/WebMD5.cs b/Runtime/WebMD5.cs index 006c97994..f376cc9e3 100644 --- a/Runtime/WebMD5.cs +++ b/Runtime/WebMD5.cs @@ -1,4 +1,4 @@ -#if UNITY_WEBGL || WEIXINMINIGAME || UNITY_EDITOR +#if WEIXINMINIGAME && TUANJIE_2022_3_OR_NEWER using System; using System.Runtime.InteropServices; @@ -6,7 +6,7 @@ namespace WeChatWASM { public class WebMD5 { - + [DllImport("__Internal", EntryPoint = "_WebMD5")] private static extern void getMD5Bytes(IntPtr byteArray, int length, IntPtr result); @@ -27,7 +27,7 @@ namespace WeChatWASM Marshal.FreeHGlobal(resultPtr); return result; - } + } } } #endif \ No newline at end of file diff --git a/Runtime/wechat-default/game.js b/Runtime/wechat-default/game.js index 1018045cd..0592e0593 100644 --- a/Runtime/wechat-default/game.js +++ b/Runtime/wechat-default/game.js @@ -94,7 +94,8 @@ checkVersion().then((enable) => { hideAfterCallmain: $HIDE_AFTER_CALLMAIN, loadingPageConfig: { // 以下是默认值 - totalLaunchTime: 15000, + totalLaunchTime: 7000, + animationDuration: 100, /** * !!注意:修改设计宽高和缩放模式后,需要修改文字和进度条样式。默认设计尺寸为667*375 */ diff --git a/Runtime/wechat-default/game.json b/Runtime/wechat-default/game.json index cf6739be4..465fa4fe0 100644 --- a/Runtime/wechat-default/game.json +++ b/Runtime/wechat-default/game.json @@ -23,7 +23,7 @@ ], "plugins": { "UnityPlugin": { - "version": "1.2.45", + "version": "1.2.50", "provider": "wxe5a48f1ed5f544b7", "contexts": [ { diff --git a/Runtime/wechat-default/unity-sdk/file-info.js b/Runtime/wechat-default/unity-sdk/file-info.js new file mode 100644 index 000000000..38ce0d509 --- /dev/null +++ b/Runtime/wechat-default/unity-sdk/file-info.js @@ -0,0 +1,47 @@ +function getObjectSize(data) { + if (data && (typeof data === 'string' || data.byteLength)) { + return data.byteLength || data.length || 0; + } + return 0; +} +export const fileInfoHandler = { + addFileInfo(filePath, data) { + if (GameGlobal.manager.fs && GameGlobal.manager.fs.addFileInfo) { + GameGlobal.manager.fs.addFileInfo({ path: filePath, size: getObjectSize(data), erasable: false }); + } + }, + modifyFileInfo(filePath, data) { + if (GameGlobal.manager.fs && GameGlobal.manager.fs.modifyFileInfo) { + GameGlobal.manager.fs.modifyFileInfo({ path: filePath, size: getObjectSize(data) }); + } + }, + removeFileInfo(filePath) { + if (GameGlobal.manager.fs && GameGlobal.manager.fs.removeFileInfo) { + GameGlobal.manager.fs.removeFileInfo(filePath); + } + }, +}; +export const fileInfoType = { + add: 0, + remove: 1, + modify: 2, +}; +export function responseWrapper(responseHandler, info) { + const { filePath, data, type } = info; + return { + success(res) { + if (type === fileInfoType.add) { + fileInfoHandler.addFileInfo(filePath, data); + } + if (type === fileInfoType.remove) { + fileInfoHandler.removeFileInfo(filePath); + } + if (type === fileInfoType.modify) { + fileInfoHandler.modifyFileInfo(filePath, data); + } + responseHandler.success(res); + }, + fail: responseHandler.fail, + complete: responseHandler.complete, + }; +} diff --git a/Runtime/wechat-default/unity-sdk/font/index.js b/Runtime/wechat-default/unity-sdk/font/index.js index 48a7eb96e..ec05a51ad 100644 --- a/Runtime/wechat-default/unity-sdk/font/index.js +++ b/Runtime/wechat-default/unity-sdk/font/index.js @@ -1,3 +1,4 @@ + import moduleHelper from '../module-helper'; import { formatJsonStr } from '../utils'; import fixCmapTable from './fix-cmap'; @@ -12,6 +13,81 @@ let getFontPromise; let isReadFromCache = false; const isIOS = platform === 'ios'; const isAndroid = platform === 'android'; +const fontOptions = { + CJK_Unified_Ideographs: { + include: $CJK_Unified_Ideographs, + unicodeRange: [0x4E00, 0x9FFF], + }, + C0_Controls_and_Basic_Latin: { + include: $C0_Controls_and_Basic_Latin, + unicodeRange: [0x0000, 0x007F], + }, + CJK_Symbols_and_Punctuation: { + include: $CJK_Symbols_and_Punctuation, + unicodeRange: [0x3000, 0x303F], + }, + General_Punctuation: { + include: $General_Punctuation, + unicodeRange: [0x2000, 0x206F], + }, + Enclosed_CJK_Letters_and_Months: { + include: $Enclosed_CJK_Letters_and_Months, + unicodeRange: [0x3200, 0x32FF], + }, + Vertical_Forms: { + include: $Vertical_Forms, + unicodeRange: [0xFE10, 0xFE1F], + }, + CJK_Compatibility_Forms: { + include: $CJK_Compatibility_Forms, + unicodeRange: [0xFE30, 0xFE4F], + }, + Miscellaneous_Symbols: { + include: $Miscellaneous_Symbols, + unicodeRange: [0x2600, 0x26FF], + }, + CJK_Compatibility: { + include: $CJK_Compatibility, + unicodeRange: [0x3300, 0x33FF], + }, + Halfwidth_and_Fullwidth_Forms: { + include: $Halfwidth_and_Fullwidth_Forms, + unicodeRange: [0xFF00, 0xFFEF], + }, + Dingbats: { + include: $Dingbats, + unicodeRange: [0x2700, 0x27BF], + }, + Letterlike_Symbols: { + include: $Letterlike_Symbols, + unicodeRange: [0x2100, 0x214F], + }, + Enclosed_Alphanumerics: { + include: $Enclosed_Alphanumerics, + unicodeRange: [0x2460, 0x24FF], + }, + Number_Forms: { + include: $Number_Forms, + unicodeRange: [0x2150, 0x218F], + }, + Currency_Symbols: { + include: $Currency_Symbols, + unicodeRange: [0x20A0, 0x20CF], + }, + Arrows: { + include: $Arrows, + unicodeRange: [0x2190, 0x21FF], + }, + Geometric_Shapes: { + include: $Geometric_Shapes, + unicodeRange: [0x25A0, 0x25FF], + }, + Mathematical_Operators: { + include: $Mathematical_Operators, + unicodeRange: [0x2200, 0x22FF], + }, + CustomUnicodeRange: $CustomUnicodeRange, +}; function handleGetFontData(config, forceLoad = false) { const canGetWxCommonFont = !!GameGlobal.manager?.font?.getCommonFont; @@ -37,6 +113,15 @@ function handleGetFontData(config, forceLoad = false) { xhr.send(); return; } + let unicodeRange = []; + + Object.keys(fontOptions).forEach((key) => { + if (fontOptions[key].include) { + unicodeRange.push(fontOptions[key].unicodeRange); + } + }); + + unicodeRange = unicodeRange.concat(fontOptions.CustomUnicodeRange); GameGlobal.manager.font.getCommonFont({ success(fontData) { @@ -53,7 +138,7 @@ function handleGetFontData(config, forceLoad = false) { resolve(); }, fail: reject, - }); + }, unicodeRange); }); } return getFontPromise; diff --git a/Runtime/wechat-default/unity-sdk/fs.js b/Runtime/wechat-default/unity-sdk/fs.js index bdfdcf19a..41593114e 100644 --- a/Runtime/wechat-default/unity-sdk/fs.js +++ b/Runtime/wechat-default/unity-sdk/fs.js @@ -1,6 +1,7 @@ import response from './response'; import moduleHelper from './module-helper'; import { cacheArrayBuffer, formatJsonStr, formatResponse } from './utils'; +import { fileInfoHandler, fileInfoType, responseWrapper } from './file-info'; function runMethod(method, option, callbackId, isString = false) { try { const fs = wx.getFileSystemManager(); @@ -82,6 +83,7 @@ export default { const fs = wx.getFileSystemManager(); fs.writeFileSync(filePath, data, encoding); + fileInfoHandler.addFileInfo(filePath, data); } catch (e) { console.error(e); @@ -139,6 +141,7 @@ export default { try { const fs = wx.getFileSystemManager(); fs.unlinkSync(filePath); + fileInfoHandler.removeFileInfo(filePath); return 'unlink:ok'; } catch (e) { @@ -153,7 +156,7 @@ export default { const fs = wx.getFileSystemManager(); fs.unlink({ filePath, - ...response.handleText(s, f, c), + ...responseWrapper(response.handleText(s, f, c), { filePath, type: fileInfoType.remove }), }); }, WXWriteFile(filePath, data, encoding, s, f, c) { @@ -162,7 +165,7 @@ export default { filePath, data: data.buffer, encoding, - ...response.handleTextLongBack(s, f, c), + ...responseWrapper(response.handleTextLongBack(s, f, c), { filePath, data: data.buffer, type: fileInfoType.add }), }); }, WXWriteStringFile(filePath, data, encoding, s, f, c) { @@ -171,7 +174,7 @@ export default { filePath, data, encoding, - ...response.handleTextLongBack(s, f, c), + ...responseWrapper(response.handleTextLongBack(s, f, c), { filePath, data, type: fileInfoType.add }), }); }, WXAppendFile(filePath, data, encoding, s, f, c) { @@ -196,6 +199,7 @@ export default { const fs = wx.getFileSystemManager(); try { fs.writeFileSync(filePath, data.buffer, encoding); + fileInfoHandler.addFileInfo(filePath, data.buffer); } catch (e) { console.error(e); diff --git a/Runtime/wechat-default/unity-sdk/texture.js b/Runtime/wechat-default/unity-sdk/texture.js index 7b4d95e16..3b58a1a93 100644 --- a/Runtime/wechat-default/unity-sdk/texture.js +++ b/Runtime/wechat-default/unity-sdk/texture.js @@ -121,6 +121,7 @@ const mod = { // err("压缩纹理下载失败!url:"+url); mod.reTryRemoteImageFile(path, width, height, limitType); }; + xmlhttp.setRequestHeader('wechatminigame-skipclean', '1'); xmlhttp.send(null); }, callbackPngFile(path, cid) { @@ -156,6 +157,7 @@ const mod = { xmlhttp.onerror = function () { mod.reTryRemoteImageFile(path, width, height); }; + xmlhttp.setRequestHeader('wechatminigame-skipclean', '1'); xmlhttp.send(null); } else { @@ -236,6 +238,7 @@ GameGlobal.ParalleLDownloadTexture = function (filename) { const p = `${GameGlobal.manager.assetPath}/Textures/${f}/${v.w}/${v.p}.txt`; http.open('GET', p, true); http.responseType = 'arraybuffer'; + http.setRequestHeader('wechatminigame-skipclean', '1'); http.send(); } }); diff --git a/WebGLTemplates/WXTemplate/index.html b/WebGLTemplates/WXTemplate/index.html index 25a501ebf..033790f21 100644 --- a/WebGLTemplates/WXTemplate/index.html +++ b/WebGLTemplates/WXTemplate/index.html @@ -54,7 +54,7 @@ delete storage[key]; }, WXStorageHasKeySync(key) { - return typeof storage[key] === 'undefined'; + return typeof storage[key] !== 'undefined'; }, WXCheckSession(s, f, c) {}, WXAuthorize(scope, s, f, c) {}, diff --git a/WebGLTemplates/WXTemplate2020/index.html b/WebGLTemplates/WXTemplate2020/index.html index 1a4d2d644..fbe967a85 100644 --- a/WebGLTemplates/WXTemplate2020/index.html +++ b/WebGLTemplates/WXTemplate2020/index.html @@ -126,7 +126,7 @@ delete storage[key]; }, WXStorageHasKeySync(key) { - return typeof storage[key] === 'undefined'; + return typeof storage[key] !== 'undefined'; }, WXCheckSession(s, f, c) {}, WXAuthorize(scope, s, f, c) {}, diff --git a/WebGLTemplates/WXTemplate2022/index.html b/WebGLTemplates/WXTemplate2022/index.html index beaeabd65..9e00e44c3 100755 --- a/WebGLTemplates/WXTemplate2022/index.html +++ b/WebGLTemplates/WXTemplate2022/index.html @@ -203,7 +203,7 @@ delete storage[key]; }, WXStorageHasKeySync(key) { - return typeof storage[key] === 'undefined'; + return typeof storage[key] !== 'undefined'; }, WXCheckSession(s, f, c) {}, WXAuthorize(scope, s, f, c) {}, diff --git a/package.json b/package.json index e04e005c2..0c7efe888 100644 --- a/package.json +++ b/package.json @@ -1 +1 @@ -{"name":"com.qq.weixin.minigame","displayName":"WXSDK","description":"WeChat Mini Game Tuanjie Engine Adapter SDK Package.","version":"0.1.10","unity":"2019.4","unityRelease":"29f1","keywords":["Tuanjie","WX"],"dependencies":{}} +{"name":"com.qq.weixin.minigame","displayName":"WXSDK","description":"WeChat Mini Game Tuanjie Engine Adapter SDK Package.","version":"0.1.11","unity":"2019.4","unityRelease":"29f1","keywords":["Tuanjie","WX"],"dependencies":{}}