Commit ef035491 authored by lujie's avatar lujie
Browse files

feat(app): Tuanjie 1.6、1.7双向通信适配

parent ecb7b0a7
...@@ -33,6 +33,7 @@ public class HarmonyOSPostBuildScript : IPostprocessBuildWithReport ...@@ -33,6 +33,7 @@ public class HarmonyOSPostBuildScript : IPostprocessBuildWithReport
private string _tuanjieLibRedundantFileDir; private string _tuanjieLibRedundantFileDir;
private string _tuanjieLibPackageJsonPath; private string _tuanjieLibPackageJsonPath;
private string _tuanjieLibBuildProfilePath; // ✅ 核心新增:tuanjieLib的build-profile.json5路径 private string _tuanjieLibBuildProfilePath; // ✅ 核心新增:tuanjieLib的build-profile.json5路径
private string _tuanjieLibAssetsPath; // ✅ 核心新增:tuanjieLib的build-profile.json5路径
public void OnPostprocessBuild(BuildReport report) public void OnPostprocessBuild(BuildReport report)
{ {
...@@ -49,6 +50,7 @@ public class HarmonyOSPostBuildScript : IPostprocessBuildWithReport ...@@ -49,6 +50,7 @@ public class HarmonyOSPostBuildScript : IPostprocessBuildWithReport
_tuanjieLibRedundantFileDir = Path.Combine(_exportRootPath, "tuanjieLib", "libs", "arm64-v8a"); _tuanjieLibRedundantFileDir = Path.Combine(_exportRootPath, "tuanjieLib", "libs", "arm64-v8a");
_tuanjieLibPackageJsonPath = Path.Combine(_exportRootPath, "tuanjieLib", "oh-package.json5"); _tuanjieLibPackageJsonPath = Path.Combine(_exportRootPath, "tuanjieLib", "oh-package.json5");
_tuanjieLibBuildProfilePath = Path.Combine(_exportRootPath, "tuanjieLib", "build-profile.json5"); // ✅ 新增关键路径 _tuanjieLibBuildProfilePath = Path.Combine(_exportRootPath, "tuanjieLib", "build-profile.json5"); // ✅ 新增关键路径
_tuanjieLibAssetsPath = Path.Combine(_exportRootPath, "tuanjieLib","src","main","ets", "assets");
try try
{ {
...@@ -61,7 +63,7 @@ public class HarmonyOSPostBuildScript : IPostprocessBuildWithReport ...@@ -61,7 +63,7 @@ public class HarmonyOSPostBuildScript : IPostprocessBuildWithReport
ProcessConfigFiles(); ProcessConfigFiles();
// 步骤3:修改【根目录】build-profile.json5 修复版本号+添加buildOption配置 // 步骤3:修改【根目录】build-profile.json5 修复版本号+添加buildOption配置
UpdateRootBuildProfileJson5_Perfect_17(); UpdateRootBuildProfileJson5_Perfect_17();
// 步骤4:【根治1】删除tuanjieLib下的fastsdk冗余文件 // 步骤4:【根治1】删除tuanjieLib下的assets目录冗余文件
DeleteTuanjieLibRedundantFiles(); DeleteTuanjieLibRedundantFiles();
// 步骤5:【根治2】移除tuanjieLib/oh-package.json5 中的 dependencies fastsdk依赖 // 步骤5:【根治2】移除tuanjieLib/oh-package.json5 中的 dependencies fastsdk依赖
RemoveTuanjieLibPackageJsonDependencies(); RemoveTuanjieLibPackageJsonDependencies();
...@@ -69,6 +71,10 @@ public class HarmonyOSPostBuildScript : IPostprocessBuildWithReport ...@@ -69,6 +71,10 @@ public class HarmonyOSPostBuildScript : IPostprocessBuildWithReport
RemoveTuanjieLibBuildProfileArkOptions(); RemoveTuanjieLibBuildProfileArkOptions();
// 步骤7:【根治3 核心新增】替换tuanjieLib/src/main/ets/workers 中的 WorkerProxy.ets文件为自定义的WorkerProxy.ets ✅✅✅ // 步骤7:【根治3 核心新增】替换tuanjieLib/src/main/ets/workers 中的 WorkerProxy.ets文件为自定义的WorkerProxy.ets ✅✅✅
ReplaceTuanjieLibWorkerProxy(); ReplaceTuanjieLibWorkerProxy();
//步骤8:删除冗余文件夹assets
//DeleteTuanjieAssetsFolder();
//步骤8:修改SdkPlugin.ets中Tuanjie导入路径
ModifySdkPluginEtsImportPath();
Debug.Log("====================================="); Debug.Log("=====================================");
Debug.Log("✅ 所有处理完成!四重根治完成!零残留+零报错!完美导出!"); Debug.Log("✅ 所有处理完成!四重根治完成!零残留+零报错!完美导出!");
Debug.Log("====================================="); Debug.Log("=====================================");
...@@ -399,25 +405,80 @@ public class HarmonyOSPostBuildScript : IPostprocessBuildWithReport ...@@ -399,25 +405,80 @@ public class HarmonyOSPostBuildScript : IPostprocessBuildWithReport
private void ReplaceTuanjieLibWorkerProxy() private void ReplaceTuanjieLibWorkerProxy()
{ {
// 1. 自定义的WorkerProxy.ets 源文件路径 (Unity工程内的自定义文件) // 1. 自定义的WorkerProxy.ets 源文件路径 (Unity工程内的自定义文件)
string customWorkerProxySource = Path.Combine(Application.dataPath, "Plugins", "OpenHarmony", "workers", "WorkerProxy.ets"); string customWorkerProxySource = Path.Combine(CUSTOM_ROOT_DIR, "16", "WorkerProxy.txt");
string customPlatformSource = Path.Combine(CUSTOM_ROOT_DIR, "17", "HLPlatform.txt");
string customTuanjiePlayerAbilitySource = Path.Combine(CUSTOM_ROOT_DIR, "17", "TuanjiePlayerAbility.txt");
// 2. 团结引擎生成的 目标替换文件路径 (导出鸿蒙工程内) // 2. 团结引擎生成的 目标替换文件路径 (导出鸿蒙工程内)
string targetWorkerProxyPath = Path.Combine(_exportRootPath, "tuanjieLib", "src", "main", "ets", "workers", "WorkerProxy.ets"); string targetWorkerProxyPath = Path.Combine(_exportRootPath, "tuanjieLib", "src", "main", "ets", "workers", "WorkerProxy.ets");
string targetPlatformPath = Path.Combine(_exportRootPath, "tuanjieLib", "src", "main", "ets", "HLPlatform.ets");
string targetTuanjiePlayerAbilityPath = Path.Combine(_exportRootPath, "entry", "src", "main", "ets", "ability", "TuanjiePlayerAbility.ets");
try try
{ {
// 校验源文件是否存在
if (!File.Exists(customWorkerProxySource))
{
Debug.LogError($"❌ 替换失败:未找到自定义WorkerProxy.ets源文件 → {customWorkerProxySource}");
return;
}
// 校验目标文件目录是否存在,不存在则创建目录 // 校验目标文件目录是否存在,不存在则创建目录
string targetDir = Path.GetDirectoryName(targetWorkerProxyPath); string targetDir = Path.GetDirectoryName(targetWorkerProxyPath);
if (!Directory.Exists(targetDir)) if (!Directory.Exists(targetDir))
{ {
Directory.CreateDirectory(targetDir); // 校验源文件是否存在
Debug.Log($"✅ 创建目标文件目录:{targetDir}"); if (!File.Exists(customPlatformSource))
{
Debug.LogError($"❌ 替换失败:未找到自定义HLPlatform.txt源文件 → {customPlatformSource}");
return;
}
//团结引擎1.7开始没有workers目录,需要替换HLPlatform
// 解除目标文件只读属性 + 执行覆盖替换 (true = 覆盖已有文件)
if (File.Exists(targetPlatformPath))
{
File.SetAttributes(targetPlatformPath, FileAttributes.Normal);
}
//File.Copy(customPlatformSource, targetPlatformPath, true);
// 读取txt文件的全部内容
string replacePlatformContent = File.ReadAllText(customPlatformSource, Encoding.UTF8);
// 将txt内容完整写入/覆盖到 WorkerProxy.ets
File.WriteAllText(targetPlatformPath, replacePlatformContent, Encoding.UTF8);
Debug.Log($"✅ ✅ ✅ 团结引擎1.7 HLPlatform.ets 文件替换成功!");
Debug.Log($"🔹 源文件:{customPlatformSource}");
Debug.Log($"🔹 目标文件:{targetPlatformPath}");
if (!File.Exists(customTuanjiePlayerAbilitySource))
{
Debug.LogError($"❌ 替换失败:未找到自定义TuanjiePlayerAbility.txt源文件 → {customTuanjiePlayerAbilitySource}");
return;
}
if (File.Exists(targetTuanjiePlayerAbilityPath))
{
File.SetAttributes(targetTuanjiePlayerAbilityPath, FileAttributes.Normal);
}
//File.Copy(customPlatformSource, targetPlatformPath, true);
// 读取txt文件的全部内容
string replaceAbilityContent = File.ReadAllText(customTuanjiePlayerAbilitySource, Encoding.UTF8);
// 将txt内容完整写入/覆盖到 WorkerProxy.ets
File.WriteAllText(targetTuanjiePlayerAbilityPath, replaceAbilityContent, Encoding.UTF8);
Debug.Log($"✅ ✅ ✅ 团结引擎1.7 TuanjiePlayerAbility.ets 文件替换成功!");
Debug.Log($"🔹 源文件:{customTuanjiePlayerAbilitySource}");
Debug.Log($"🔹 目标文件:{targetTuanjiePlayerAbilityPath}");
return;
}
// 校验源文件是否存在
if (!File.Exists(customWorkerProxySource))
{
Debug.LogError($"❌ 替换失败:未找到自定义WorkerProxy.ets源文件 → {customWorkerProxySource}");
return;
} }
// 解除目标文件只读属性 + 执行覆盖替换 (true = 覆盖已有文件) // 解除目标文件只读属性 + 执行覆盖替换 (true = 覆盖已有文件)
...@@ -425,7 +486,12 @@ public class HarmonyOSPostBuildScript : IPostprocessBuildWithReport ...@@ -425,7 +486,12 @@ public class HarmonyOSPostBuildScript : IPostprocessBuildWithReport
{ {
File.SetAttributes(targetWorkerProxyPath, FileAttributes.Normal); File.SetAttributes(targetWorkerProxyPath, FileAttributes.Normal);
} }
File.Copy(customWorkerProxySource, targetWorkerProxyPath, true); //File.Copy(customWorkerProxySource, targetWorkerProxyPath, true);
// 读取txt文件的全部内容
string replaceProxyContent = File.ReadAllText(customWorkerProxySource, Encoding.UTF8);
// 将txt内容完整写入/覆盖到 WorkerProxy.ets
File.WriteAllText(targetWorkerProxyPath, replaceProxyContent, Encoding.UTF8);
Debug.Log($"✅ ✅ ✅ WorkerProxy.ets 文件替换成功!"); Debug.Log($"✅ ✅ ✅ WorkerProxy.ets 文件替换成功!");
Debug.Log($"🔹 源文件:{customWorkerProxySource}"); Debug.Log($"🔹 源文件:{customWorkerProxySource}");
...@@ -437,4 +503,81 @@ public class HarmonyOSPostBuildScript : IPostprocessBuildWithReport ...@@ -437,4 +503,81 @@ public class HarmonyOSPostBuildScript : IPostprocessBuildWithReport
} }
} }
#endregion #endregion
private void DeleteTuanjieAssetsFolder()
{
if (Directory.Exists(_tuanjieLibAssetsPath))
{
// 解除目标文件只读属性 + 执行覆盖替换 (true = 覆盖已有文件)
if (File.Exists(_tuanjieLibAssetsPath))
{
File.SetAttributes(_tuanjieLibAssetsPath, FileAttributes.Normal);
}
// 删除文件夹及内部所有文件+子目录,递归删除无残留
Directory.Delete(_tuanjieLibAssetsPath, true);
Debug.Log($"✅ 【重点】已完整删除冗余目录:{_tuanjieLibAssetsPath}");
}
else
{
Debug.Log($"⚠️ 未找到tuanjieLib冗余文件目录:{_tuanjieLibAssetsPath},无需删除");
}
}
#region 八、【新增核心需求】自动修改 SdkPlugin.ets 中的 Tuanjie 导入路径 【关键新增】
private void ModifySdkPluginEtsImportPath()
{
string targetWorkerProxyPath = Path.Combine(_exportRootPath, "tuanjieLib", "src", "main", "ets", "workers", "WorkerProxy.ets");
// 校验目标文件目录是否存在,不存在则创建目录,通过worker目录判断是团结引擎1.6还是1.7
string targetDir = Path.GetDirectoryName(targetWorkerProxyPath);
if (Directory.Exists(targetDir))
{
Debug.Log($"⚠️ 当前为团结引擎1.6版本,跳过导入路径修改");
return;
}
// 目标文件完整路径:tuanjieLib/entry/src/main/ets/SdkPlugin.ets
string sdkPluginEtsPath = Path.Combine(_exportRootPath, "tuanjieLib", "src", "main", "ets", "SdkPlugin.ets");
// 校验文件是否存在,不存在则打印日志跳过
if (!File.Exists(sdkPluginEtsPath))
{
Debug.Log($"⚠️ 未找到目标文件 SdkPlugin.ets → {sdkPluginEtsPath},跳过导入路径修改");
return;
}
try
{
// 解除文件只读属性,防止无法写入
File.SetAttributes(sdkPluginEtsPath, FileAttributes.Normal);
// 读取文件所有内容
string etsFileContent = File.ReadAllText(sdkPluginEtsPath, Encoding.UTF8);
// 定义需要替换的 旧导入语句 和 新导入语句
string oldImportStr = "import { Tuanjie } from \"./utils/TuanjieNative\";";
string newImportStr = "import { Tuanjie } from \"classesLib\";";
// 判断是否包含旧语句,有则替换,无则跳过
if (etsFileContent.Contains(oldImportStr))
{
string newEtsContent = etsFileContent.Replace(oldImportStr, newImportStr);
// 写入替换后的内容到原文件,覆盖原有内容
File.WriteAllText(sdkPluginEtsPath, newEtsContent, Encoding.UTF8);
Debug.Log($"✅ ✅ ✅ 成功修改 SdkPlugin.ets 导入路径!");
Debug.Log($"🔹 旧语句:{oldImportStr}");
Debug.Log($"🔹 新语句:{newImportStr}");
Debug.Log($"🔹 文件路径:{sdkPluginEtsPath}");
}
else
{
// 兼容:可能已经被修改过,或者引擎导出的默认语句不同
Debug.Log($"⚠️ SdkPlugin.ets 文件中未找到目标导入语句 → {oldImportStr},无需修改");
}
}
catch (System.Exception e)
{
Debug.LogError($"❌ 修改SdkPlugin.ets导入路径失败:{e.Message}\n{e.StackTrace}");
}
}
#endregion
} }
\ No newline at end of file
import { LogUtil } from "fastsdk"; import { StringUtils,LogUtil } from "fastsdk";
import { fastSdk, StringUtils } from "fastsdk";
import { PayParams } from "fastsdk/src/main/ets/model/PayParams"; import { PayParams } from "fastsdk/src/main/ets/model/PayParams";
import { JSON } from "@kit.ArkTS"; import { JSON } from "@kit.ArkTS";
import { PlayerInfo } from "fastsdk/src/main/ets/model/PlayerInfo"; import { PlayerInfo } from "fastsdk/src/main/ets/model/PlayerInfo";
import { DataType } from "core"; import { DataType } from "core";
import { SdkBridge } from "./SdkPlugin";
export class HLMainWorker { export class HLMainWorker {
private static instance: HLMainWorker | null = null; private static instance: HLMainWorker | null = null;
...@@ -20,15 +20,15 @@ export class HLMainWorker { ...@@ -20,15 +20,15 @@ export class HLMainWorker {
} }
receive_init(data: Record<string, string>) { receive_init(data: Record<string, string>) {
fastSdk.initSDK(); SdkBridge.initSDK();
} }
receive_login(data: Record<string, string>) { receive_login(data: Record<string, string>) {
fastSdk.login(); SdkBridge.login();
} }
receive_logout(data: Record<string, string>) { receive_logout(data: Record<string, string>) {
fastSdk.logout(); SdkBridge.logout();
} }
receive_pay(data: Record<string, string>) { receive_pay(data: Record<string, string>) {
...@@ -72,7 +72,7 @@ export class HLMainWorker { ...@@ -72,7 +72,7 @@ export class HLMainWorker {
if (StringUtils.isEmpty(notifyUrl)) { if (StringUtils.isEmpty(notifyUrl)) {
payParam.notifyUrl = ''; payParam.notifyUrl = '';
} }
fastSdk.pay(payParam); SdkBridge.pay(payParam);
} catch (e) { } catch (e) {
LogUtil.error(e); LogUtil.error(e);
} }
...@@ -80,15 +80,15 @@ export class HLMainWorker { ...@@ -80,15 +80,15 @@ export class HLMainWorker {
} }
receive_exitGame(data: Record<string, string>) { receive_exitGame(data: Record<string, string>) {
fastSdk.exit(); SdkBridge.exit();
} }
receive_account(data: Record<string, string>) { receive_account(data: Record<string, string>) {
fastSdk.openAccountCenter(); SdkBridge.openAccountCenter();
} }
receive_switchAccount(data: Record<string, string>) { receive_switchAccount(data: Record<string, string>) {
fastSdk.switchAccount(); SdkBridge.switchAccount();
} }
receive_report(data: Record<string, string>) { receive_report(data: Record<string, string>) {
...@@ -123,7 +123,7 @@ export class HLMainWorker { ...@@ -123,7 +123,7 @@ export class HLMainWorker {
for (const val of msgTypeValues) { for (const val of msgTypeValues) {
console.log("枚举值:", val); console.log("枚举值:", val);
if (val === Number(eventType)) { if (val === Number(eventType)) {
fastSdk.report(val, playerInfo); SdkBridge.report(val, playerInfo);
break; break;
} }
} }
...@@ -131,27 +131,4 @@ export class HLMainWorker { ...@@ -131,27 +131,4 @@ export class HLMainWorker {
LogUtil.error(JSON.stringify(error)); LogUtil.error(JSON.stringify(error));
} }
} }
sendPlayRoleInfo(eventType:DataType){
let playerInfo = new PlayerInfo();
playerInfo.roleId = '1235761';
playerInfo.roleName = '黑洞王者';
playerInfo.roleLevel = '11';
playerInfo.zoneId = '100';
playerInfo.zoneName = '华东大区';
playerInfo.serverId = '100';
playerInfo.serverName = '大唐战机';
playerInfo.balance = '66';
playerInfo.vip = '1';
playerInfo.partyName = '帮派名称';
playerInfo.classField = 'aaaa';
playerInfo.extendAction = 'aaaatest';
playerInfo.addExtra('a',1);
playerInfo.addExtra('b',2.1);
playerInfo.addExtra('c','3');
playerInfo.phylum = '1';
LogUtil.info(`EventType:${eventType},playerInfo:${JSON.stringify(playerInfo)}`);
// this.logText+=`EventType:${eventType},playerInfo:${JSON.stringify(playerInfo)}`;
fastSdk.report(eventType,playerInfo);
}
} }
\ No newline at end of file
import { LogUtil } from "fastsdk" import { LogUtil } from "fastsdk"
import { HLMainWorker } from "./HLMainWorker"; import { HLMainWorker } from "./HLMainWorker";
export class HLRecevie { export class HLReceive {
private static instance: HLRecevie | null = null private static instance: HLReceive | null = null
private constructor() { private constructor() {
} }
//单例 //单例
public static getInstance(): HLRecevie { public static getInstance(): HLReceive {
if (HLRecevie.instance == null) { if (HLReceive.instance == null) {
LogUtil.info('重新生成instance') LogUtil.info('重新生成instance')
HLRecevie.instance = new HLRecevie(); HLReceive.instance = new HLReceive();
} }
return HLRecevie.instance; return HLReceive.instance;
} }
//接收消息 //接收消息
...@@ -27,6 +27,10 @@ export class HLRecevie { ...@@ -27,6 +27,10 @@ export class HLRecevie {
this.gotoSDK(receiveData['params'] as Record<string, string>, funcName); this.gotoSDK(receiveData['params'] as Record<string, string>, funcName);
} }
public static receiveMessage(receiveData: Record<string, string | Object>) {
HLReceive.getInstance().receiveMessage(receiveData);
}
gotoSDK(data: Record<string, string>, func: string) { gotoSDK(data: Record<string, string>, func: string) {
LogUtil.info('receive init 参数:' + JSON.stringify(data)); LogUtil.info('receive init 参数:' + JSON.stringify(data));
switch (func) { switch (func) {
......
fileFormatVersion: 2 fileFormatVersion: 2
guid: Wi4W5CKkWnrhdcvs9TlaO6BsCh7N2Q59XCMeog0Rd4yHyMSKzB4EhRU= guid: C34dsij+UykMtHwNempzUjU3HQiPyvJpumW3lRQu25oTPXRGRplfsTo=
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}
userData: userData:
......
import { AbilityConstant, common, Want } from "@kit.AbilityKit";
import { fastSdk, InitResult, LogUtil } from "fastsdk";
import { window } from "@kit.ArkUI";
import { processMgr } from "fastsdk/src/main/ets/utils/PageManager";
import { GoodsInfo } from "fastsdk/src/main/ets/model/GoodsInfo";
import { LoginResult } from "fastsdk/src/main/ets/model/LoginResult";
import { PayParams } from "fastsdk/src/main/ets/model/PayParams";
import { PlayerInfo } from "fastsdk/src/main/ets/model/PlayerInfo";
import { DataType } from "core";
import { Tuanjie } from "./utils/TuanjieNative";
class SdkPlugin {
private static instance: SdkPlugin | null = null
private uiContext?: UIContext;
//单例
public static getInstance(): SdkPlugin {
if (SdkPlugin.instance == null) {
SdkPlugin.instance = new SdkPlugin();
}
return SdkPlugin.instance;
}
//---------------lifecycle event--------------
public onCreate(want: Want, launchParam: AbilityConstant.LaunchParam, context: common.UIAbilityContext): void {
fastSdk.onCreate(want, launchParam, context);
}
public loadContentSuccess(windowStage: window.WindowStage): void {
fastSdk.loadContentSuccess(windowStage);
this.uiContext = AppStorage.get<UIContext>('uiContext');
}
public onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void {
fastSdk.onNewWant(want, launchParam);
}
public onDestory(): void {
fastSdk.onDestory();
}
//---------------lifecycle event--------------
private register(): void {
fastSdk.hlSystemListener = {
onInitSuccess: (result: InitResult) => {
LogUtil.info('初始化成功:' + JSON.stringify(result));
let jsonString = JSON.stringify(result);
Tuanjie.TuanjieSendMessage("PlatformCallback", "onInitSuccess", jsonString);
},
onInitFailed: (reason: string) => {
LogUtil.error('初始化失败:' + reason);
Tuanjie.TuanjieSendMessage("PlatformCallback", "onInitFailed", reason);
},
onCustomExit: () => {
LogUtil.info('自定义退出流程触发');
Tuanjie.TuanjieSendMessage("PlatformCallback", "onCustomExit", "");
// this.uiContext?.showAlertDialog({
// title: '自定义退出',
// message: '确定退出游戏?',
// autoCancel: true,
// alignment: DialogAlignment.Center,
// buttons: [{
// value: "再玩一会",
// action: () => {
// LogUtil.info("点击了再玩一会");
// }
// }, {
// enabled: true,
// defaultFocus: true,
// style: DialogButtonStyle.HIGHLIGHT,
// value: '确定退出',
// action: () => {
// //自定义退出弹窗
// LogUtil.info('自定义退出成功');
// fastSdk.hlSystemListener?.onExitSuccess("");
// }
// }]
// })
},
onExitSuccess: (result: string) => {
LogUtil.info('退出成功:' + result);
processMgr.exit(0)
}
};
fastSdk.hlAccountListener = {
onRefreshUser: (result: LoginResult): void => {
//暂不使用
},
onLoginSuccess: (result: LoginResult): void => {
LogUtil.info('登录成功:' + JSON.stringify(result));
Tuanjie.TuanjieSendMessage("PlatformCallback", "onLoginSuccess", JSON.stringify(result));
},
onLoginFailed: (reason: string): void => {
LogUtil.info('登录失败:' + reason);
Tuanjie.TuanjieSendMessage("PlatformCallback", "onLoginFailed", reason);
},
onLogout: (): void => {
LogUtil.info('已登出');
Tuanjie.TuanjieSendMessage("PlatformCallback", "onLogout", "");
}
};
fastSdk.hlPaymentListener = {
onPaySuccess: (result: string): void => {
LogUtil.info(`支付成功:${result}`);
Tuanjie.TuanjieSendMessage("PlatformCallback", "onPaySuccess", result);
},
onPayFailed: (reason: string): void => {
LogUtil.info(`支付失败:${reason}`);
Tuanjie.TuanjieSendMessage("PlatformCallback", "onPayFailed", reason);
},
onQuerySuccess: (products: GoodsInfo[]): void => {
//暂不使用
}
}
}
public initSDK() {
this.register();
fastSdk.initSDK();
}
public login(){
fastSdk.login();
}
public logout(){
fastSdk.logout();
}
public switchAccount(){
fastSdk.switchAccount();
}
public exit(){
fastSdk.exit();
}
public pay(payParms:PayParams){
fastSdk.pay(payParms);
}
public openAccountCenter(){
fastSdk.openAccountCenter();
}
public report(eventType: DataType, playerInfo: PlayerInfo){
fastSdk.report(eventType,playerInfo);
}
}
export const SdkBridge = SdkPlugin.getInstance();
\ No newline at end of file
fileFormatVersion: 2 fileFormatVersion: 2
guid: Bn5Ntn//BXvyo89TgBbOv/v85N632oD10pPHqYmujStdbtuqtrPnyhA= guid: Wi8csiirVnJRzmFJQ/Cr58E9Z4k3vh4pCefZN785ooMn3INBBhf9IRI=
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}
userData: userData:
......
...@@ -2,30 +2,24 @@ import window from '@ohos.window'; ...@@ -2,30 +2,24 @@ import window from '@ohos.window';
import { AbilityConstant, Want } from '@kit.AbilityKit'; import { AbilityConstant, Want } from '@kit.AbilityKit';
import { SetToGlobalThis } from 'tuanjieLib'; import { SetToGlobalThis } from 'tuanjieLib';
import { TuanjiePlayerAbilityBase } from 'tuanjieLib'; import { TuanjiePlayerAbilityBase } from 'tuanjieLib';
import { fastSdk, InitResult, LogUtil, WindowVersionCompat } from 'fastsdk'; import { LogUtil, WindowVersionCompat } from 'fastsdk';
import { processMgr } from 'fastsdk/src/main/ets/utils/PageManager'; import { SdkBridge } from 'tuanjieLib/src/main/ets/SdkPlugin';
import { LoginResult } from 'fastsdk/src/main/ets/model/LoginResult';
import { GoodsInfo } from 'fastsdk/src/main/ets/model/GoodsInfo';
import { Tuanjie } from 'tuanjieLib/src/main/ets/utils/TuanjieNative';
import { UnityApiBridge } from 'tuanjieLib/src/main/ets/HLPlatform';
export default class TuanjiePlayerAbility extends TuanjiePlayerAbilityBase { export default class TuanjiePlayerAbility extends TuanjiePlayerAbilityBase {
uiContext?: UIContext;
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
this.setConfig(); this.setConfig();
super.onCreate(want, launchParam); super.onCreate(want, launchParam);
//fastsdk相关方法 SdkBridge.onCreate(want, launchParam, this.context);
fastSdk.onCreate(want, launchParam, this.context);
} }
onDestroy(): void { onDestroy(): void {
super.onDestroy(); super.onDestroy();
fastSdk.onDestory(); SdkBridge.onDestory();
} }
onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void { onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void {
super.onNewWant(want, launchParam); super.onNewWant(want, launchParam);
fastSdk.onNewWant(want, launchParam); SdkBridge.onNewWant(want, launchParam);
} }
onWindowStageCreate(windowStage: window.WindowStage): void { onWindowStageCreate(windowStage: window.WindowStage): void {
...@@ -35,12 +29,8 @@ export default class TuanjiePlayerAbility extends TuanjiePlayerAbilityBase { ...@@ -35,12 +29,8 @@ export default class TuanjiePlayerAbility extends TuanjiePlayerAbilityBase {
WindowVersionCompat.getInstance().getUIContextAfterLoadContent( WindowVersionCompat.getInstance().getUIContextAfterLoadContent(
windowStage, windowStage,
(uiContext: UIContext) => { (uiContext: UIContext) => {
// 获取UIContext成功,初始化SDK SdkBridge.loadContentSuccess(windowStage);
this.uiContext = uiContext; SdkBridge.initSDK();
fastSdk.loadContentSuccess(windowStage);
this.register();
//UnityApiBridge.getInstance().initSDK(uiContext);
fastSdk.initSDK();
}, },
(errorMsg: string) => { (errorMsg: string) => {
// 获取失败的兜底处理 // 获取失败的兜底处理
...@@ -66,99 +56,4 @@ export default class TuanjiePlayerAbility extends TuanjiePlayerAbilityBase { ...@@ -66,99 +56,4 @@ export default class TuanjiePlayerAbility extends TuanjiePlayerAbilityBase {
SetToGlobalThis("appSplash", $r('app.media.app_splash')); SetToGlobalThis("appSplash", $r('app.media.app_splash'));
SetToGlobalThis("showStaticSplash", $r('app.integer.ShowStaticSplashScreen')); SetToGlobalThis("showStaticSplash", $r('app.integer.ShowStaticSplashScreen'));
} }
private register(): void {
fastSdk.hlSystemListener = {
onInitSuccess: (result: InitResult) => {
LogUtil.info('初始化成功:' + JSON.stringify(result));
let jsonString = JSON.stringify(result);
Tuanjie.TuanjieSendMessage("PlatformCallback", "onInitSuccess", jsonString);
},
onInitFailed: (reason: string) => {
LogUtil.error('初始化失败:' + reason);
Tuanjie.TuanjieSendMessage("PlatformCallback", "onInitFailed", reason);
},
onCustomExit: () => {
LogUtil.info('自定义退出流程触发');
this.uiContext?.showAlertDialog({
title: '自定义退出',
message: '确定退出游戏?',
autoCancel: true,
alignment: DialogAlignment.Center,
buttons: [{
value: "再玩一会",
action: () => {
LogUtil.info("点击了再玩一会");
}
}, {
enabled: true,
defaultFocus: true,
style: DialogButtonStyle.HIGHLIGHT,
value: '确定退出',
action: () => {
//自定义退出弹窗
LogUtil.info('自定义退出成功');
fastSdk.hlSystemListener?.onExitSuccess("");
}
}]
})
},
onExitSuccess: (result: string) => {
LogUtil.info('退出成功:' + result);
processMgr.exit(0)
}
};
fastSdk.hlAccountListener = {
onRefreshUser: (result: LoginResult): void => {
//暂不使用
},
onLoginSuccess: (result: LoginResult): void => {
LogUtil.info('登录成功:' + JSON.stringify(result));
Tuanjie.TuanjieSendMessage("PlatformCallback", "onLoginSuccess", JSON.stringify(result));
},
onLoginFailed: (reason: string): void => {
LogUtil.info('登录失败:' + reason);
Tuanjie.TuanjieSendMessage("PlatformCallback", "onLoginFailed", reason);
},
onLogout: (): void => {
LogUtil.info('已登出');
Tuanjie.TuanjieSendMessage("PlatformCallback", "onLogout","");
}
};
fastSdk.hlPaymentListener = {
onPaySuccess: (result: string): void => {
LogUtil.info(`支付成功:${result}`);
Tuanjie.TuanjieSendMessage("PlatformCallback", "onPaySuccess",result);
},
onPayFailed: (reason: string): void => {
LogUtil.info(`支付失败:${reason}`);
Tuanjie.TuanjieSendMessage("PlatformCallback", "onPayFailed",reason);
},
onQuerySuccess: (products: GoodsInfo[]): void => {
//暂不使用
}
}
}
} }
// @Aspect
// export class LoadContentAop {
// // 拦截WindowStage.prototype.loadContent方法
// @Around('execution(* Window.WindowStage.loadContent(..))')
// interceptLoadContent(jp: JoinPoint) {
// console.log('子类AOP:父类即将调用loadContent方法');
// try {
// // 执行原方法(父类的loadContent调用)
// const result = jp.proceed();
// // 方法调用完成(同步结果,实际UI渲染是异步)
// console.log('子类AOP:父类loadContent方法调用完成,结果:', result);
// return result;
// } catch (err) {
// // 捕获方法调用异常
// console.error('子类AOP:父类loadContent方法调用失败', err);
// throw err;
// }
// }
// }
fileFormatVersion: 2 fileFormatVersion: 2
guid: WitJsiKuBXlQV+NvW2lCUwe53HN4tr+OmvKsrdei/yJfYrtPDLUpXCU= guid: XnxM4HyrV3MxylibL8NhLzAvQH1UQZt3UuVYz8SA7zOA8M/S0XIWAaw=
folderAsset: yes folderAsset: yes
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}
......
...@@ -9,7 +9,7 @@ import { Tuanjie } from '../utils/TuanjieNative'; ...@@ -9,7 +9,7 @@ import { Tuanjie } from '../utils/TuanjieNative';
import { PROCESS_UI_BUILTIN_MESSAGE, PROCESS_UI_HANDLER, PROCESS_UI_MESSAGE, kCustomHandler} from './MessageProcessor'; import { PROCESS_UI_BUILTIN_MESSAGE, PROCESS_UI_HANDLER, PROCESS_UI_MESSAGE, kCustomHandler} from './MessageProcessor';
import "../gen/BuiltinHostMsgRegistration"; import "../gen/BuiltinHostMsgRegistration";
import {LogUtil } from 'fastsdk'; import {LogUtil } from 'fastsdk';
import { HLRecevie } from '../HLReceive'; import { HLReceive } from '../HLReceive';
export class WorkerProxy { export class WorkerProxy {
public threadWorker: worker.ThreadWorker; public threadWorker: worker.ThreadWorker;
...@@ -49,7 +49,7 @@ export class WorkerProxy { ...@@ -49,7 +49,7 @@ export class WorkerProxy {
private sendMsgToHLSDK(msg:Record<string,object>){ private sendMsgToHLSDK(msg:Record<string,object>){
LogUtil.info('接受消息参数:'+JSON.stringify(msg)); LogUtil.info('接受消息参数:'+JSON.stringify(msg));
HLRecevie.getInstance().receiveMessage(msg['data'] as Record<string,string|Object>) HLReceive.getInstance().receiveMessage(msg['data'] as Record<string,string|Object>)
} }
......
fileFormatVersion: 2
guid: W30Zs3mrBymajtJ5rW0HAn0MuQKOhzlW4hCAyUoKjSNrIjR2xg35wpE=
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: W3pOsHj7U384kWvNOmVTvYSPLTvhtMrdiAxBqu/OWlmQmk1h3nOwchw=
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
import { LogUtil } from "fastsdk";
import { JSON } from "@kit.ArkTS";
import { POST_MESSAGE_TO_HOST } from "classesLib";
export class UnityApiBridge {
public PostMsgFunc(data: Record<string, string | number | object>) {
try {
LogUtil.info('===== 鸿蒙侧通信调试开始 =====');
LogUtil.info(`1. 进入PostMsgFunc,原始数据: ${JSON.stringify(data)}`);
const param: Array<ESObject> = [data];
let msg: ESObject = {
// modulePath: "./HLReceive.ets",
moduleName:"tuanjieLib",
funcName: "HLReceive.receiveMessage",
args: param,
callback: null,
timeoutMs: -1,
}
LogUtil.info(`2. 构造的msg消息体:${JSON.stringify(msg)}`);
// 核心调用
POST_MESSAGE_TO_HOST(msg);
LogUtil.info('3. POST_MESSAGE_TO_HOST调用完成,消息已发送');
LogUtil.info('===== 鸿蒙侧通信调试结束 =====');
} catch (e) {
LogUtil.error(`❌ 鸿蒙侧调用失败,捕获异常: ${e}`);
}
}
initSDK() {
let SDKData: Record<string, string> = {
'params': '{}',
'func': "receive_init"
};
this.sendMessage(SDKData)
}
login() {
LogUtil.info('HLPlatform login invoke');
let SDKData: Record<string, string> = {
'params': '{}',
'func': "receive_login"
};
this.sendMessage(SDKData)
}
logout() {
let SDKData: Record<string, string> = {
'params': '{}',
'func': "receive_logout"
};
this.sendMessage(SDKData);
}
switchAccount() {
let SDKData: Record<string, string> = {
'params': '{}',
'func': "receive_switchAccount"
};
this.sendMessage(SDKData);
}
exit() {
let SDKData: Record<string, string> = {
'params': '{}',
'func': "receive_exitGame"
};
this.sendMessage(SDKData)
}
startPay(parm: string) {
let paramsData: Record<string, string> = {
'payData': parm
}
let SDKData: Record<string, string | object> = {
'params': paramsData,
'func': "receive_pay"
};
this.sendMessage(SDKData);
}
sendEvent(eventType: number, jsonStr: string) {
let data: Record<string, string> = {
'type': `${eventType}`,
'content': jsonStr
};
let SDKData: Record<string, string | object> = {
'params': data,
'func': "receive_report"
};
this.sendMessage(SDKData);
}
accessParticipate() {
}
openAccount() {
let SDKData: Record<string, string | number> = {
'params': '{}',
'func': "receive_account"
};
this.sendMessage(SDKData)
}
shareData() {
}
sendMessage(data: Record<string, string | number | object>) {
this.PostMsgFunc(data);
}
}
export function RegisterHLPlatform() {
let register: Record<string, Object> = {};
register["UnityApiBridge"] = new UnityApiBridge();
return register;
}
\ No newline at end of file
fileFormatVersion: 2
guid: XHNK5iioUSmU3HlFtqTuk5dZ7HGlEeTQB5EL9/rrKP/r/iIvmXxEcgM=
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
import window from '@ohos.window';
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { SetToGlobalThis, TuanjiePlayer, TuanjieLog, SdkBridge } from 'tuanjieLib';
export default class TuanjiePlayerAbility extends UIAbility {
private defaultPageUri: string = "pages/Index"
private tuanjiePlayer: TuanjiePlayer = TuanjiePlayer.getInstance()
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
this.setConfig();
this.tuanjiePlayer.onCreate(this.context, want, launchParam)
SdkBridge.onCreate(want, launchParam, this.context);
}
onDestroy(): void {
this.tuanjiePlayer.onDestroy();
SdkBridge.onDestory();
}
onWindowStageCreate(windowStage: window.WindowStage): void {
windowStage.loadContent(this.defaultPageUri, (err: ESObject, data: ESObject) => {
if (err.code) {
TuanjieLog.error('Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
TuanjieLog.info('Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
SdkBridge.loadContentSuccess(windowStage);
SdkBridge.initSDK();
});
this.tuanjiePlayer.onWindowStageCreate(windowStage)
}
onWindowStageDestroy(): void {
this.tuanjiePlayer.onWindowStageDestroy()
}
onForeground(): void {
this.tuanjiePlayer.onForeground()
}
onBackground(): void {
this.tuanjiePlayer.onBackground()
}
onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void {
this.tuanjiePlayer.onNewWant(want, launchParam)
SdkBridge.onNewWant(want, launchParam);
}
setConfig(): void {
SetToGlobalThis("staticSplashScreenFit", $r('app.integer.StaticSplashScreenFit'));
SetToGlobalThis("appSplash", $r('app.media.app_splash'));
SetToGlobalThis("showStaticSplash", $r('app.integer.ShowStaticSplashScreen'));
}
}
fileFormatVersion: 2
guid: DnlNsCOkBShg8E+wFVjO5Gbl3EcR2mCtQOnZ+jB2gn0V/n9tGXRmNMQ=
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
Zm/tRpYBVPKjd68+DY8d9/iYxr88/AmdOfdrxzMM+MOvXEx3mf8t5yb0Rqx2tFov+tEz8YFlFvsVabMOIi1yN/Xb3dIQZQ7mep09mZaOZvvixZNJxGaBHWLDKzHh1UPIksQjc5uzsbILsMOYPPWGL4a98J5f4lSldwwWETi56ZRd54IsJ/cci1orbTjK3o/O6cFiRfo4BYVO/rUScUFNiimjQR4WbJaHjiW1E4L+z2PtiQE3KMjJ1LwnLfbHqIbbvh9TPmNP7z1+T+23d+xsEC2bJAhxmkFm2Y3467FJZM3vdET9h1IoL4XirHMmkbZ/T6HjdJg5IqShz2ikL/+8hQ==
\ No newline at end of file
fileFormatVersion: 2
guid: CClOsy34AXnpM+YzoCZQavN2bP/69ZumOGciVIZ39w9i54g2AaWy/KM=
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
OpenHarmony: OpenHarmony
second:
enabled: 1
settings: {}
userData:
assetBundleName:
assetBundleVariant:
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
"com.unity.ide.vscode": "1.2.5", "com.unity.ide.vscode": "1.2.5",
"com.unity.nuget.newtonsoft-json": "3.2.1", "com.unity.nuget.newtonsoft-json": "3.2.1",
"com.unity.test-framework": "1.1.33", "com.unity.test-framework": "1.1.33",
"com.unity.textmeshpro": "3.0.7", "com.unity.textmeshpro": "3.0.9",
"com.unity.timeline": "1.7.7", "com.unity.timeline": "1.7.7",
"com.unity.ugui": "1.0.0", "com.unity.ugui": "1.0.0",
"com.unity.visualscripting": "1.9.4", "com.unity.visualscripting": "1.9.4",
......
...@@ -70,7 +70,7 @@ ...@@ -70,7 +70,7 @@
"source": "builtin", "source": "builtin",
"dependencies": { "dependencies": {
"com.unity.ide.visualstudio": "2.0.22", "com.unity.ide.visualstudio": "2.0.22",
"com.unity.ide.rider": "3.0.35", "com.unity.ide.rider": "3.0.36",
"com.unity.ide.vscode": "1.2.5", "com.unity.ide.vscode": "1.2.5",
"com.unity.editorcoroutines": "1.0.0", "com.unity.editorcoroutines": "1.0.0",
"com.unity.performance.profile-analyzer": "1.2.3", "com.unity.performance.profile-analyzer": "1.2.3",
...@@ -140,7 +140,7 @@ ...@@ -140,7 +140,7 @@
"url": "https://packages.tuanjie.cn" "url": "https://packages.tuanjie.cn"
}, },
"com.unity.settings-manager": { "com.unity.settings-manager": {
"version": "2.0.1", "version": "2.1.0",
"depth": 2, "depth": 2,
"source": "registry", "source": "registry",
"dependencies": {}, "dependencies": {},
...@@ -168,7 +168,7 @@ ...@@ -168,7 +168,7 @@
"url": "https://packages.tuanjie.cn" "url": "https://packages.tuanjie.cn"
}, },
"com.unity.textmeshpro": { "com.unity.textmeshpro": {
"version": "3.0.7", "version": "3.0.9",
"depth": 0, "depth": 0,
"source": "registry", "source": "registry",
"dependencies": { "dependencies": {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment