[add] CocosBridge 多個value
This commit is contained in:
parent
1606c28b5c
commit
4a2abf55f6
@ -1,3 +1,4 @@
|
||||
import { System_Eevent } from "./Engine/CatanEngine/CSharp/System/System_Eevent";
|
||||
import NativeClass from "./NativeClass";
|
||||
|
||||
const { ccclass, property } = cc._decorator;
|
||||
@ -28,7 +29,7 @@ export default class Manager extends cc.Component {
|
||||
console.log("Debug");
|
||||
}
|
||||
|
||||
new NativeClass();
|
||||
new NativeClass(this.webview);
|
||||
|
||||
let self: this = this;
|
||||
// this._text_to_Speech = new Text_to_Speech();
|
||||
@ -44,9 +45,6 @@ export default class Manager extends cc.Component {
|
||||
cc.view.setResizeCallback(this._resize.bind(this));
|
||||
this._resize();
|
||||
|
||||
const FCMToken: string = NativeClass.Instance.GetFCMToken();
|
||||
console.log(`FCMToken ${FCMToken}`);
|
||||
|
||||
// Set EventListener
|
||||
window.addEventListener("message", function (e: MessageEvent<any>): void {
|
||||
let data: any = e.data;
|
||||
@ -79,6 +77,12 @@ export default class Manager extends cc.Component {
|
||||
});
|
||||
}
|
||||
|
||||
protected start(): void {
|
||||
const FCMToken: string = NativeClass.Instance.GetFCMToken();
|
||||
console.log(`FCMToken ${FCMToken}`);
|
||||
NativeClass.Instance.CocosBridge(System_Eevent.SetFCMToken, FCMToken, 666);
|
||||
}
|
||||
|
||||
/** 跨版本溝通
|
||||
* @example
|
||||
* CallParent('Speak', '我愛豬涵')
|
||||
|
@ -1,5 +1,7 @@
|
||||
// import Text_to_Speech from "./Text_to_Speech";
|
||||
|
||||
import { System_Eevent } from "./Engine/CatanEngine/CSharp/System/System_Eevent";
|
||||
|
||||
const { ccclass } = cc._decorator;
|
||||
|
||||
@ccclass
|
||||
@ -13,6 +15,8 @@ export default class NativeClass extends cc.Component {
|
||||
|
||||
//#region public 屬性
|
||||
|
||||
public WebView: cc.WebView = null;
|
||||
|
||||
public URLscheme: Object = {};
|
||||
|
||||
public URLschemeFlags: number = 0;
|
||||
@ -27,9 +31,10 @@ export default class NativeClass extends cc.Component {
|
||||
|
||||
//#region Lifecycle
|
||||
|
||||
constructor() {
|
||||
constructor(...param: any[]) {
|
||||
super();
|
||||
NativeClass._instance = this;
|
||||
this.WebView = param[0];
|
||||
this.init();
|
||||
}
|
||||
|
||||
@ -132,6 +137,20 @@ export default class NativeClass extends cc.Component {
|
||||
|
||||
//#region Custom Function
|
||||
|
||||
/** CocosBridge */
|
||||
public CocosBridge(type: System_Eevent, ...param: any[]): void {
|
||||
let value: string = "";
|
||||
for (let i: number = 0; i < param.length; i++) {
|
||||
let element: any = param[i];
|
||||
if (element === "") {
|
||||
element = "\"\"";
|
||||
}
|
||||
value += `,${element}`;
|
||||
}
|
||||
let command: string = `window.CocosBridge(${type}${value})`;
|
||||
this.WebView.evaluateJS(command);
|
||||
}
|
||||
|
||||
/** GetFCMToken */
|
||||
public GetFCMToken(): string {
|
||||
let resp: any = "";
|
||||
|
Loading…
Reference in New Issue
Block a user