### npm install 安装依赖 Source: https://github.com/1226085293/mkframework/wiki/安装框架 在项目根目录的 extensions\MKFramework 目录下执行,用于安装框架所需的 Node.js 依赖。执行成功后需重新打开编辑器。 ```bat npm install ``` -------------------------------- ### guide_manage.finish_b Source: https://github.com/1226085293/mkframework/wiki/新手引导‐暂停与完成 Gets the finish state of the guide manager. Returns true when the current step matches the end_step_n provided during initialization. When the guide is finished, the guide manager sets pause_b to true and dispatches a finish event. ```APIDOC ## guide_manage.finish_b ### Description Gets the finish state of the guide manager. Returns true when the current step matches the end_step_n provided during initialization. When the guide is finished, the guide manager sets pause_b to true and dispatches a finish event. ### Property `guide_manage.finish_b` (boolean) ### Example ```ts guide_manage.finish_b; ``` ``` -------------------------------- ### guide_manage.pause_b Source: https://github.com/1226085293/mkframework/wiki/新手引导‐暂停与完成 Gets or sets the pause state of the guide manager. When paused, set_step can still be used to set the current guide step, but the guide step lifecycle will not run. ```APIDOC ## guide_manage.pause_b ### Description Gets or sets the pause state of the guide manager. When paused, set_step can still be used to set the current guide step, but the guide step lifecycle will not run. ### Property `guide_manage.pause_b` (boolean) ### Example ```ts guide_manage.pause_b = true; ``` ``` -------------------------------- ### mk.ui_manage.open Source: https://github.com/1226085293/mkframework/wiki/运行你的第一个模块 打开已注册的动态模块。需要先注册再打开。 ```APIDOC ## mk.ui_manage.open ### Description 打开已注册的动态模块。需要先注册再打开。 ### Method open ### Parameters - **参数 1** (type) - Required - 继承于 mk.view_base 的模块类型 - **参数 2** (type) - Optional - 打开配置 ### Request Example ```ts mk.ui_manage.open(resources_test, {}); ``` ``` -------------------------------- ### 从对象添加引导步骤 Source: https://github.com/1226085293/mkframework/wiki/新手引导‐从最简单开始 通过 new guide_step_xxx() 创建步骤实例并注册到 guide_manage。 ```ts guide_manage.regis([new guide_step_xxx()]); ``` -------------------------------- ### 从节点添加引导步骤 Source: https://github.com/1226085293/mkframework/wiki/新手引导‐从最简单开始 通过 node.getComponent(guide_step_xxx) 获取节点上的组件并注册。 ```ts guide_manage.regis([node.getComponent(guide_step_xxx)]); ``` -------------------------------- ### 打开模块:mk.ui_manage.open Source: https://github.com/1226085293/mkframework/wiki/运行你的第一个模块 打开已注册的模块,传入模块类型和空配置。 ```TypeScript mk.ui_manage.open(resources_test, {}); ``` -------------------------------- ### 创建引导管理器 guide_manage Source: https://github.com/1226085293/mkframework/wiki/新手引导‐从最简单开始 初始化引导管理器实例,step_update_callback_f 回调返回 true 表示允许步骤更新。 ```typescript const guide_manage = new mk.guide_manage({ step_update_callback_f: () => true, }); ``` -------------------------------- ### 定义引导步骤类 guide_step_base Source: https://github.com/1226085293/mkframework/wiki/新手引导‐从最简单开始 继承 mk.guide_step_base 并实现 load 方法,step_n 为步骤序号。 ```typescript class guide_step_xxx extends mk.guide_step_base { // 步骤序号 step_n = 1; load(jump_b_: boolean): void | Promise { // ...进入引导步骤后的逻辑 } } ``` -------------------------------- ### mk.audio.resume_all Source: https://github.com/1226085293/mkframework/wiki/音频‐使用示例 恢复所有音频的播放。 ```APIDOC ## mk.audio.resume_all ### Description 恢复所有音频的播放。 ### Method resume_all ### Examples ```ts mk.audio.resume_all(); ``` ``` -------------------------------- ### 加载本地资源:mk.asset.get Source: https://github.com/1226085293/mkframework/wiki/资源‐加载-释放 加载本地资源,支持资源路径格式如 "xxx.png"、"xxx"、"db://assets/xxx.png"、"db://assets/xxx"。第三个参数为资源跟随释放对象,可传入 mk.release_.type_follow_release_object 类型(如 mk.view_base 对象,模块 close 后自动释放)或 null(自行管理资源)。 ```TypeScript mk.asset.get("资源路径", cc.SpriteFrame, 资源跟随释放对象); ``` -------------------------------- ### 设置暂停状态 guide_manage.pause_b Source: https://github.com/1226085293/mkframework/wiki/新手引导‐暂停与完成 设置 pause_b 为 true 可暂停引导。暂停时仍可调用 set_step 设置当前引导步骤,但不会运行引导步骤的生命周期。 ```TypeScript guide_manage.pause_b = true; ``` -------------------------------- ### 注册模块示例 2:mk.ui_manage.regis 使用 bundle 配置 Source: https://github.com/1226085293/mkframework/wiki/运行你的第一个模块 注册模块时使用 bundle 配置,指定 bundle_s 为 "resources",模块来源为相对路径。注册只需执行一次,除非跟随对象(参数 3)已释放。 ```TypeScript // 示例 2 mk.ui_manage.regis(resources_test, "module/resources_test", this, { load_config: { bundle_s: "resources", }, }); ``` -------------------------------- ### 动态加载音频(全路径和 bundle 相对路径) Source: https://github.com/1226085293/mkframework/wiki/音频‐加载 使用 mk.audio.add 动态加载音频,支持全路径和 bundle 相对路径。全路径示例使用 db://assets/resources/xxx.mp3,相对路径示例通过 load_config 指定 bundle。 ```TypeScript // 全路径 this.music = (await mk.audio.add("db://assets/resources/xxx.mp3", this))!; // bundle 相对路径 this.music = (await mk.audio.add("xxx", this, { load_config: { bundle_s: global_config.asset.bundle.resources, }, }))!; ``` -------------------------------- ### 注册操作单元到 guide_manage Source: https://github.com/1226085293/mkframework/wiki/新手引导‐重复代码?状态还原?通通解决 创建 mk.guide_manage 实例时传入操作单元集合 operate_tab,以便后续在引导步骤中通过 this.operate_tab 访问单元。 ```TypeScript const guide_manage = new mk.guide_manage({ operate_tab: operate.tab, }); ``` -------------------------------- ### mk.bundle.load_scene 预加载场景 Source: https://github.com/1226085293/mkframework/wiki/资源‐Bundle管理-热更 预加载场景,通过 preload_b: true 实现。 ```TypeScript mk.bundle.load_scene("xxx", { bundle_s: "bundle名", preload_b: true }) ``` -------------------------------- ### 发送消息 Source: https://github.com/1226085293/mkframework/wiki/网络‐Websocket 发送字符串或 protobuf 消息。test.test_c 为 protobuf 类型。 ```TypeScript socket.message.send("123") socket.message.send(test.test_c.create()) ``` -------------------------------- ### 注册模块示例 1:mk.ui_manage.regis 使用 prefab 路径 Source: https://github.com/1226085293/mkframework/wiki/运行你的第一个模块 注册模块时传入模块类型、prefab 路径、跟随释放对象和空配置。注册只需执行一次,除非跟随对象(参数 3)已释放。 ```TypeScript @ccclass("resources_test") export class resources_test extends mk.view_base { ... } // 示例 1 mk.ui_manage.regis( resources_test, "db://assets/resources/module/resources_test.prefab", this, {} ); ``` -------------------------------- ### 创建 WebSocket 实例 Source: https://github.com/1226085293/mkframework/wiki/网络‐Websocket 创建 WebSocket 实例,支持字符串消息和 protobufjs 编解码器。 ```APIDOC ## 创建 WebSocket 实例 ### Description 创建 WebSocket 实例,支持字符串消息和 protobufjs 编解码器。 ### Method constructor ### Endpoint new mk.network.websocket(options?) ### Parameters #### Options (optional) - **codec** (object) - Optional - 编解码器实例,用于 protobuf 消息。 ### Request Example ```ts const socket = new mk.network.websocket() ``` ```ts const socket = new mk.network.websocket({ codec: new tool.codec.proto_static(protobuf根对象), }); ``` ```ts const socket = new mk.network.websocket({ codec: new tool.codec.proto(json-module 或者 json 文件夹路径), }); ``` ``` -------------------------------- ### mk_asset.get - 加载编辑器资源 Source: https://github.com/1226085293/mkframework/wiki/资源‐加载-释放 加载编辑器资源,需要 db 全路径带后缀,且不能加载 cc.SpriteFrame 资源和文件夹资源。 ```APIDOC ## mk_asset.get - 加载编辑器资源 ### Description 加载编辑器资源,需要 db 全路径带后缀,且不能加载 cc.SpriteFrame 资源和文件夹资源。 ### Method GET ### Endpoint mk_asset.get ### Parameters #### Path Parameters - **资源路径** (string) - Required - 格式:`"db://assets/xxx.png"`,必须带后缀 - **资源类型** (type) - Required - 资源类型,不能为 cc.SpriteFrame - **资源跟随释放对象** (object|null) - Required - 同本地资源 ### Response #### Success Response (200) - **资源对象** (object) - 加载的资源 ### Request Example ```ts mk_asset.get("db://assets/xxx.png", cc.ImageAsset, 资源跟随释放对象) ``` ``` -------------------------------- ### mk.audio_.unit.playOneShot Source: https://github.com/1226085293/mkframework/wiki/音频‐加载 播放一次性音频,不能暂停音频。 ```APIDOC ## mk.audio_.unit.playOneShot ### Description 播放一次性音频,不能暂停音频。 ### Method playOneShot ### Endpoint mk.audio_.unit.playOneShot ### Parameters #### Request Body 无参数 ### Response 无返回数据 ``` -------------------------------- ### mk.audio_.unit.play Source: https://github.com/1226085293/mkframework/wiki/音频‐加载 播放音频单元。当 wait_play_b 为 true 时,多次调用会等待前次播放完成。 ```APIDOC ## mk.audio_.unit.play ### Description 播放音频单元。当 wait_play_b 为 true 时,多次调用会等待前次播放完成。 ### Method play ### Endpoint mk.audio_.unit.play ### Parameters #### Request Body 无参数 ### Response 无返回数据 ``` -------------------------------- ### mk.bundle.load_scene 加载场景 Source: https://github.com/1226085293/mkframework/wiki/资源‐Bundle管理-热更 加载指定 bundle 中的场景。 ```TypeScript mk.bundle.load_scene("xxx", { bundle_s: "bundle名" }) ``` -------------------------------- ### 获取完成状态 guide_manage.finish_b Source: https://github.com/1226085293/mkframework/wiki/新手引导‐暂停与完成 读取 finish_b 判断引导是否完成。当当前步骤与 end_step_n 一致时返回 true。引导完成时,引导管理器会将 pause_b 设置为 true 并派发 finish 事件。 ```TypeScript guide_manage.finish_b; ``` -------------------------------- ### mk.bundle.set 暂存远程 Bundle 配置 Source: https://github.com/1226085293/mkframework/wiki/资源‐Bundle管理-热更 用于暂存远程 bundle 配置,可多次调用。之后调用 load 时只需传递 bundle 名即可加载远程 Bundle。 ```TypeScript mk.bundle.set({ bundle_s: "bundle名", origin_s: "http://xxx", version_s: "bundle版本号" }); // 后面调用 load 就不必传递远程 bundle 的 origin_s 和 version_s mk.bundle.load("bundle名"); ``` -------------------------------- ### mk.ui_manage.regis Source: https://github.com/1226085293/mkframework/wiki/运行你的第一个模块 注册动态模块,用于提前存储参数、预加载资源和创建对象池。注册只需执行一次,除非跟随对象已释放。 ```APIDOC ## mk.ui_manage.regis ### Description 注册动态模块,用于提前存储参数、预加载资源和创建对象池。注册只需执行一次,除非跟随对象已释放。 ### Method regis ### Parameters - **参数 1** (type) - Required - 继承于 mk.view_base 的模块类型 - **参数 2** (type) - Required - 模块来源,支持 prefab, node, string - **参数 3** (type) - Required - 跟随释放对象,模块的资源将跟随这个对象的 close 后释放 - **参数 4** (type) - Optional - 加载配置 ### Request Example ```ts mk.ui_manage.regis( resources_test, "db://assets/resources/module/resources_test.prefab", this, {} ); mk.ui_manage.regis(resources_test, "module/resources_test", this, { load_config: { bundle_s: "resources", }, }); ``` ``` -------------------------------- ### mk.asset.get - 加载本地资源 Source: https://github.com/1226085293/mkframework/wiki/资源‐加载-释放 加载本地资源,支持多种路径格式。第三个参数可指定资源跟随释放对象,在对象关闭后自动释放资源;传 null 则自行管理资源。 ```APIDOC ## mk.asset.get - 加载本地资源 ### Description 加载本地资源,支持多种路径格式。第三个参数可指定资源跟随释放对象,在对象关闭后自动释放资源;传 null 则自行管理资源。 ### Method GET ### Endpoint mk.asset.get ### Parameters #### Path Parameters - **资源路径** (string) - Required - 支持格式:`"xxx.png"`、`"xxx"`、`"db://assets/xxx.png"`、`"db://assets/xxx"` - **资源类型** (type) - Required - 资源类型 - **资源跟随释放对象** (object|null) - Required - 类型为 `mk.release_.type_follow_release_object` 时,资源加载后会调用 follow_release 函数;已扩展类型包括 `mk.life_cycle`、`mk.bundle_.bundle_manage_base`;传 null 表示自行管理资源 ### Response #### Success Response (200) - **资源对象** (object) - 加载的资源 ### Request Example ```ts mk.asset.get("资源路径", cc.SpriteFrame, 资源跟随释放对象); ``` ``` -------------------------------- ### mk.asset.get - 加载远程资源 Source: https://github.com/1226085293/mkframework/wiki/资源‐加载-释放 加载远程资源,第四个参数包含 remote_option 时即为远程资源。 ```APIDOC ## mk.asset.get - 加载远程资源 ### Description 加载远程资源,第四个参数包含 remote_option 时即为远程资源。 ### Method GET ### Endpoint mk.asset.get ### Parameters #### Path Parameters - **资源路径** (string) - Required - 远程资源 URL,如 `"https://xxx"` - **资源类型** (type) - Required - 资源类型 - **资源跟随释放对象** (object|null) - Required - 同本地资源 - **remote_option** (object) - Required - 存在该参数即表示远程资源 ### Response #### Success Response (200) - **资源对象** (object) - 加载的资源 ### Request Example ```ts mk.asset.get("https://xxx", cc.SpriteFrame, 资源跟随释放对象, { remote_option: {} }); ``` ``` -------------------------------- ### mk.asset.release - 手动释放资源 Source: https://github.com/1226085293/mkframework/wiki/资源‐加载-释放 手动释放资源,当资源跟随释放对象参数为 null 时,可使用该接口释放资源。 ```APIDOC ## mk.asset.release - 手动释放资源 ### Description 手动释放资源,当资源跟随释放对象参数为 null 时,可使用该接口释放资源。 ### Method GET ### Endpoint mk.asset.release ### Parameters #### Path Parameters - **资源** (object) - Required - 要释放的资源对象 ### Response #### Success Response (200) - **无** (void) - 无返回值 ``` -------------------------------- ### 混合添加引导步骤 Source: https://github.com/1226085293/mkframework/wiki/新手引导‐从最简单开始 同时注册对象和节点组件,guide_manage.regis 可多次调用,只会覆盖而不会删除之前的步骤。 ```ts guide_manage.regis([new guide_step_xxx(), node.getComponent(guide_step_xxx)]); ``` -------------------------------- ### 插入步骤:原始代码 Source: https://github.com/1226085293/mkframework/wiki/新手引导‐步骤插入与顺序修改 原始引导步骤定义,包含两个步骤,步骤1在load中调用set_step(2)跳转到步骤2。 ```TypeScript class guide_step_xxx extends mk.guide_step_base { step_n = 1; load() { this.guide_manage.set_step(2); } } class guide_step_xxx2 extends mk.guide_step_base { step_n = 2; } ``` -------------------------------- ### 断开 WebSocket 连接 Source: https://github.com/1226085293/mkframework/wiki/网络‐Websocket 关闭 WebSocket 连接。 ```APIDOC ## 断开 WebSocket 连接 ### Description 关闭 WebSocket 连接。 ### Method close ### Endpoint socket.close() ### Request Example ```ts socket.close() ``` ``` -------------------------------- ### mk.bundle.load 加载 Bundle Source: https://github.com/1226085293/mkframework/wiki/资源‐Bundle管理-热更 加载指定名称的 Bundle 资源。 ```TypeScript mk.bundle.load("xxx") ``` -------------------------------- ### 断开 WebSocket 连接 Source: https://github.com/1226085293/mkframework/wiki/网络‐Websocket 关闭 WebSocket 连接。 ```TypeScript socket.close() ``` -------------------------------- ### 启动新手引导 set_step Source: https://github.com/1226085293/mkframework/wiki/新手引导‐从最简单开始 调用 set_step(1) 跳转到步骤序号为 1 的步骤。 ```ts // 跳转到步骤序号为 1 的步骤 guide_manage.set_step(1); ``` -------------------------------- ### 创建 WebSocket 实例(protobufjs 静态) Source: https://github.com/1226085293/mkframework/wiki/网络‐Websocket 使用 protobufjs 静态 codec 创建 WebSocket 实例。tool.codec 仅在示例项目中存在,不包含在框架代码中。 ```TypeScript const socket = new mk.network.websocket({ codec: new tool.codec.proto_static(protobuf根对象), }); ``` -------------------------------- ### 创建 WebSocket 实例(protobufjs 动态) Source: https://github.com/1226085293/mkframework/wiki/网络‐Websocket 使用 protobufjs 动态 codec 创建 WebSocket 实例。tool.codec 仅在示例项目中存在,不包含在框架代码中。 ```TypeScript const socket = new mk.network.websocket({ codec: new tool.codec.proto(json-module 或者 json 文件夹路径), }); ``` -------------------------------- ### 创建 WebSocket 实例(字符串) Source: https://github.com/1226085293/mkframework/wiki/网络‐Websocket 创建一个默认的 WebSocket 实例,使用字符串消息。 ```TypeScript const socket = new mk.network.websocket() ``` -------------------------------- ### mk.audio.play Source: https://github.com/1226085293/mkframework/wiki/音频‐使用示例 播放音频。支持正常播放、重叠播放和分组播放。 ```APIDOC ## mk.audio.play ### Description 播放音频。支持正常播放、重叠播放和分组播放。 ### Method play ### Parameters - **audio** (Audio) - Required - 要播放的音频对象。 ### Examples #### 正常播放 ```ts mk.audio.play(this.audio); ``` #### 重叠播放 ```ts // 需要最大重叠几次就包含几个 mk.audio_.unit let overlap_effect_as = [this.audio, ...this.audio.clone(4)]; mk.audio.play(overlap_effect_as.find((v) => v.state === mk.audio_.state.stop)!); ``` #### 分组播放 ```ts // 播放处于 pause 或 stop 状态的 effect 类型音频 mk.audio.get_group(global_config.audio.type.effect).play(mk.audio_.state.pause | mk.audio_.state.stop); ``` ``` -------------------------------- ### 修改步骤顺序:修改第2步为第1步 Source: https://github.com/1226085293/mkframework/wiki/新手引导‐步骤插入与顺序修改 通过修改step_n属性调整步骤顺序,原步骤2变为步骤1,原步骤1变为步骤2,并调整load中的跳转目标。 ```TypeScript class guide_step_xxx extends mk.guide_step_base { step_n = 2; } class guide_step_xxx2 extends mk.guide_step_base { step_n = 1; load() { this.guide_manage.set_step(2); } } ``` -------------------------------- ### mk.bundle.reload 热更 Bundle Source: https://github.com/1226085293/mkframework/wiki/资源‐Bundle管理-热更 重载 Bundle,自动更新脚本及资源,用于替代 manifest 热更方式,支持原生/Web。注意:构建时需勾选 MD5;不能在 bundleA 的 scene 内对 bundleA 执行 reload;reload 前需清理定时器和事件回调。 ```TypeScript mk.bundle.reload({ ... }) ``` -------------------------------- ### 加载编辑器资源:mk_asset.get Source: https://github.com/1226085293/mkframework/wiki/资源‐加载-释放 加载编辑器资源,需要 db 全路径带后缀,且不能加载 cc.SpriteFrame 资源和文件夹资源。 ```TypeScript mk_asset.get("db://assets/xxx.png", cc.ImageAsset, 资源跟随释放对象) ``` -------------------------------- ### mk.bundle.set Source: https://github.com/1226085293/mkframework/wiki/资源‐Bundle管理-热更 Stores remote bundle configuration for later use with load. Can be called multiple times. ```APIDOC ## mk.bundle.set ### Description Stores remote bundle configuration for later use with load. Can be called multiple times. ### Method set ### Parameters #### Request Body - **bundle_s** (string) - Required - Bundle name - **origin_s** (string) - Required - Remote origin URL - **version_s** (string) - Required - Bundle version ### Request Example ```ts mk.bundle.set({ bundle_s: "bundle名", origin_s: "http://xxx", version_s: "bundle版本号" }); ``` ``` -------------------------------- ### 设置音频分组(方式2:加载时指定分组) Source: https://github.com/1226085293/mkframework/wiki/音频‐加载 在 mk.audio.add 的配置中通过 group_ns 指定音频分组,加载时即设置分组。 ```TypeScript this.effect = (await mk.audio.add("xxx.mp3", this, { group_ns: [resources_config.audio.group.test], }))!; ``` -------------------------------- ### 请求消息(等待返回) Source: https://github.com/1226085293/mkframework/wiki/网络‐Websocket 发送请求并等待返回结果。 ```TypeScript // 指定消息 this._ws2.message.request(test.test_c.create())?.then((value) => { ... }); ``` -------------------------------- ### mk.audio.get_group Source: https://github.com/1226085293/mkframework/wiki/音频‐加载 获取音频分组对象,用于向分组中添加音频单元。 ```APIDOC ## mk.audio.get_group ### Description 获取音频分组对象,用于向分组中添加音频单元。 ### Method get_group ### Endpoint mk.audio.get_group ### Parameters #### Path Parameters - **group** (enum) - Required - 音频分组枚举值 ### Response #### Success Response 返回音频分组对象,包含 add_audio 方法 ### Request Example ``` mk.audio.get_group(resources_config.audio.group.test).add_audio([this.effect, this.effect2, ...]); ``` ``` -------------------------------- ### 连接 WebSocket Source: https://github.com/1226085293/mkframework/wiki/网络‐Websocket 连接到指定的 WebSocket 服务器地址。 ```TypeScript socket.connect("ws://127.0.0.1:8848"); ``` -------------------------------- ### 切换语言为中文(mk.language_manage.type_s) Source: https://github.com/1226085293/mkframework/wiki/多语言‐切换语言及配置 通过设置 mk.language_manage.type_s 为 global_config.language.type.zh_cn 来切换语言。全局配置位于 global_config.ts 的 language 字段。 ```TypeScript mk.language_manage.type_s = global_config.language.type.zh_cn; ``` -------------------------------- ### 脚本内使用多语言图片组件 Source: https://github.com/1226085293/mkframework/wiki/多语言‐图片 在脚本中获取 Sprite 上的 mk.language.texture 组件,设置 type_s 为配置类型(如 "resources_language"),设置 mark_s 为多语言键(如 resources_language_texture.key.示例)。 ```TypeScript const texture = this.nodes.texture.getComponent(mk.language.texture)!; // 设置类型 texture.type_s = "resources_language"; // 设置标记 texture.mark_s = resources_language_texture.key.示例; ``` -------------------------------- ### 设置音频分组(方式1:通过分组添加音频) Source: https://github.com/1226085293/mkframework/wiki/音频‐加载 通过 mk.audio.get_group 获取分组并添加音频单元,支持一次添加多个音频。 ```TypeScript mk.audio.get_group(resources_config.audio.group.test).add_audio([this.effect, this.effect2, ...]); ``` -------------------------------- ### 框架自动释放示例:mk.asset.get 带跟随释放对象 Source: https://github.com/1226085293/mkframework/wiki/资源‐加载-释放 框架自动释放:资源将在 mk.view_base 对象的 close 回调后释放。 ```TypeScript mk.asset.get("assets/xxx", cc.SpriteFrame, mk.view_base 对象); ``` -------------------------------- ### 手动调用 close 关闭模块 Source: https://github.com/1226085293/mkframework/wiki/认识模块 在模块类中,close 可被手动调用,调用后模块将被关闭。示例展示了如何通过模块实例调用 close 函数,等同于执行 mk.ui_manage.close(test)。 ```TypeScript // 示例模块 @ccclass("module") export class module extends mk.view_base { ... } // 如果 test 是一个 module 类型对象 let test: module; // 手动调用 test.close 函数等同于执行 mk.ui_manage.close(test) test.close(); ``` -------------------------------- ### 插入步骤:插入步骤3到第2步 Source: https://github.com/1226085293/mkframework/wiki/新手引导‐步骤插入与顺序修改 在步骤2之前插入新步骤3,原步骤2的step_n改为3,新步骤3的load中调用set_step(2)跳转到原步骤2。 ```TypeScript class guide_step_xxx extends mk.guide_step_base { step_n = 1; load() { this.guide_manage.set_step(3); } } class guide_step_xxx2 extends mk.guide_step_base { step_n = 2; } class guide_step_xxx3 extends mk.guide_step_base { step_n = 3; load() { this.guide_manage.set_step(2); } } ``` -------------------------------- ### 创建消息潮 Source: https://github.com/1226085293/mkframework/wiki/网络‐Websocket 创建用于间隔批量发送消息的 send_tide 对象,可以使用定时器或手动触发。 ```TypeScript // socket对象:mk.network.websocket | mk.network.wx_websocket new mk.network.base_.send_tide(socket对象, -1); ``` -------------------------------- ### 接收消息 Source: https://github.com/1226085293/mkframework/wiki/网络‐Websocket 监听指定消息或全局消息。使用事件式消息收发结构。 ```TypeScript // 指定消息 socket.message.on(test.test_c, (value) => { ... }, this); // 全局消息 socket.event.on(socket.event.key.recv, (value) => { ... }, this); ``` -------------------------------- ### 定义操作单元集合 tab 与 key Source: https://github.com/1226085293/mkframework/wiki/新手引导‐重复代码?状态还原?通通解决 将不同操作(如清理桌面、对话框)封装为操作单元,每个单元包含 load、reset、unload 回调。回调仅在切换引导步骤时调用:load 在上个步骤不存在该单元时调用,unload 在下个步骤不存在时调用,reset 在上下步骤都存在时调用。key 通过 Proxy 生成,用于类型安全的单元 key 引用。 ```TypeScript import * as cc from "cc"; const tab = { 清理桌面: { load() {}, reset() {}, unload() {} }, 对话框: { load() { ... }, }, }; const key: { [k in keyof typeof tab]: k;} = new Proxy(Object.create(null), { get: (target, key) => key, }); export default { tab, key }; ``` -------------------------------- ### 属性面板加载音频 Source: https://github.com/1226085293/mkframework/wiki/音频‐加载 在属性面板中声明音频单元属性,使用 mk.audio_.unit 类型。 ```TypeScript @property(mk.audio_.unit) music = new mk.audio_.unit(); ``` -------------------------------- ### mk.audio.pause Source: https://github.com/1226085293/mkframework/wiki/音频‐使用示例 暂停音频。支持暂停单个音频、分组音频或所有音频。 ```APIDOC ## mk.audio.pause ### Description 暂停音频。支持暂停单个音频、分组音频或所有音频。 ### Method pause ### Parameters - **audio** (Audio) - Required - 要暂停的音频对象。 ### Examples #### 正常暂停 ```ts mk.audio.pause(this.audio); ``` #### 暂停分组音频 ```ts mk.audio.get_group(global_config.audio.type.effect).pause(); ``` #### 暂停所有音频 ```ts mk.audio.pause_all(); ``` ``` -------------------------------- ### 脚本内使用多语言组件 Source: https://github.com/1226085293/mkframework/wiki/多语言‐文本 在脚本中获取多语言组件,设置参数、类型和标记,用于动态更新文本。 ```TypeScript const label = this.nodes.label.getComponent(mk.language.label)!; // 设置参数 label.args_ss = ["xxx"]; // 设置类型 label.type_s = "resources_language"; // 设置标记 label.mark_s = resources_language_label.key.示例; ``` -------------------------------- ### 重载 Bundle 接口 mk.bundle.reload Source: https://github.com/1226085293/mkframework/wiki/教程‐大厅子游戏 用于重载子游戏 Bundle 以实现热更新。重载前需清理定时器和注册的事件,且不能在 Bundle 内的场景中调用。若 BundleB 依赖 BundleA,重载 BundleA 时 BundleB 也需要重载。 ```TypeScript mk.bundle.reload ``` -------------------------------- ### mk.audio.stop Source: https://github.com/1226085293/mkframework/wiki/音频‐使用示例 停止音频。支持停止单个音频、分组音频或所有音频。 ```APIDOC ## mk.audio.stop ### Description 停止音频。支持停止单个音频、分组音频或所有音频。 ### Method stop ### Parameters - **audio** (Audio) - Required - 要停止的音频对象。 ### Examples #### 正常停止 ```ts mk.audio.stop(this.audio); ``` #### 停止分组音频 ```ts mk.audio.get_group(global_config.audio.type.effect).stop(); ``` #### 停止所有音频 ```ts mk.audio.stop_all(); ``` ``` -------------------------------- ### 加载远程资源:mk.asset.get 带 remote_option Source: https://github.com/1226085293/mkframework/wiki/资源‐加载-释放 加载远程资源,第四个参数存在 remote_option 即为远程资源。 ```TypeScript mk.asset.get("https://xxx", cc.SpriteFrame, 资源跟随释放对象, { remote_option: {} }); ``` -------------------------------- ### 多语言图片配置示例 (resources_language_texture.ts) Source: https://github.com/1226085293/mkframework/wiki/多语言‐图片 在模块下创建脚本,使用 mk.language_.texture_data 注册多语言图片配置。第一个参数为模块类名(可用 cc.js.getClassName 获取或替换为字符串),第二个参数为键值对,键为多语言键,值为对应语言图片路径。 ```TypeScript import mk from "mk"; import * as cc from "cc"; export default new mk.language_.texture_data(cc.js.getClassName(替换为模块class), { 示例: { en_us: "db://assets/resources/module/language/texture/en", zh_cn: "db://assets/resources/module/language/texture/cn", }, }); ``` -------------------------------- ### 事件监听示例:mk.event_target 自动释放 Source: https://github.com/1226085293/mkframework/wiki/模块‐生命周期(mk.life_cycle) 在生命周期组件中,监听事件时第三个参数传入事件目标(如 this),组件会在 close 后自动释放事件,避免手动注销。 ```TypeScript main_bundle.event.on(main_bundle.event.key.template, this._event_template, this) ``` -------------------------------- ### 重叠播放音频 Source: https://github.com/1226085293/mkframework/wiki/音频‐使用示例 通过克隆音频实例实现重叠播放,需要最大重叠几次就包含几个 mk.audio_.unit。 ```TypeScript // 需要最大重叠几次就包含几个 mk.audio_.unit let overlap_effect_as = [this.audio, ...this.audio.clone(4)]; mk.audio.play(overlap_effect_as.find((v) => v.state === mk.audio_.state.stop)!); ``` -------------------------------- ### mk.bundle.reload Source: https://github.com/1226085293/mkframework/wiki/资源‐Bundle管理-热更 Reloads a bundle to apply hot updates. Automatically updates the bundle's scripts and resources, replacing the manifest hot update method. Supports native and Web platforms. ```APIDOC ## mk.bundle.reload ### Description Reloads a bundle to apply hot updates. Automatically updates the bundle's scripts and resources, replacing the manifest hot update method. Supports native and Web platforms. ### Method reload ### Parameters #### Request Body - **...** (object) - Required - Configuration object for reload ### Request Example ```ts mk.bundle.reload({ ... }) ``` ``` -------------------------------- ### 恢复所有音频 Source: https://github.com/1226085293/mkframework/wiki/音频‐使用示例 恢复所有音频。 ```TypeScript mk.audio.resume_all(); ``` -------------------------------- ### 暂停所有音频 Source: https://github.com/1226085293/mkframework/wiki/音频‐使用示例 暂停所有音频。 ```TypeScript mk.audio.pause_all(); ``` -------------------------------- ### 正常暂停音频 Source: https://github.com/1226085293/mkframework/wiki/音频‐使用示例 暂停单个音频实例。 ```TypeScript mk.audio.pause(this.audio); ``` -------------------------------- ### 正常播放音频 Source: https://github.com/1226085293/mkframework/wiki/音频‐使用示例 播放单个音频实例。 ```TypeScript mk.audio.play(this.audio); ``` -------------------------------- ### 多语言文本配置示例 (resources_language_label.ts) Source: https://github.com/1226085293/mkframework/wiki/多语言‐文本 定义多语言文本配置,使用 mk.language_.label_data 构造函数,第一个参数为模块类名或字符串,第二个参数为键值对,键为多语言键,值为不同语言对应的文本,支持 {0} 占位符。 ```TypeScript import mk from "mk"; import * as cc from "cc"; export default new mk.language_.label_data(cc.js.getClassName(替换为模块class), { 示例: { en_us: "template-{0}", zh_cn: "示例-{0}", }, }); ``` -------------------------------- ### 停止所有音频 Source: https://github.com/1226085293/mkframework/wiki/音频‐使用示例 停止所有音频。 ```TypeScript mk.audio.stop_all(); ``` -------------------------------- ### 正常停止音频 Source: https://github.com/1226085293/mkframework/wiki/音频‐使用示例 停止单个音频实例。 ```TypeScript mk.audio.stop(this.audio); ``` -------------------------------- ### 在引导步骤中使用操作单元 Source: https://github.com/1226085293/mkframework/wiki/新手引导‐重复代码?状态还原?通通解决 在引导步骤类中通过 operate_ss 数组按顺序指定要加载的操作单元 key,并在 load 方法中通过 this.operate_tab[operate.key.xxx] 获取对应单元的 load 函数返回值。 ```TypeScript class guide_step_1 extends mk.guide_step_base { operate_ss = [operate.key.清理桌面, operate.key.对话框]; load() { const window = await this.operate_tab[operate.key.对话框]; window.xxx = "你好"; } } ``` -------------------------------- ### 暂停分组音频 Source: https://github.com/1226085293/mkframework/wiki/音频‐使用示例 暂停 effect 类型音频分组。 ```TypeScript mk.audio.get_group(global_config.audio.type.effect).pause(); ``` -------------------------------- ### 恢复分组音频 Source: https://github.com/1226085293/mkframework/wiki/音频‐使用示例 恢复播放 effect 类型音频分组中处于 pause 状态的音频。 ```TypeScript mk.audio.get_group(global_config.audio.type.effect).play(mk.audio_.state.pause); ``` -------------------------------- ### 停止分组音频 Source: https://github.com/1226085293/mkframework/wiki/音频‐使用示例 停止 effect 类型音频分组。 ```TypeScript mk.audio.get_group(global_config.audio.type.effect).stop(); ``` -------------------------------- ### 分组播放音频 Source: https://github.com/1226085293/mkframework/wiki/音频‐使用示例 播放处于 pause 或 stop 状态的 effect 类型音频。 ```TypeScript // 播放处于 pause 或 stop 状态的 effect 类型音频 mk.audio.get_group(global_config.audio.type.effect).play(mk.audio_.state.pause | mk.audio_.state.stop); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.