[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";
|
import NativeClass from "./NativeClass";
|
||||||
|
|
||||||
const { ccclass, property } = cc._decorator;
|
const { ccclass, property } = cc._decorator;
|
||||||
@ -28,7 +29,7 @@ export default class Manager extends cc.Component {
|
|||||||
console.log("Debug");
|
console.log("Debug");
|
||||||
}
|
}
|
||||||
|
|
||||||
new NativeClass();
|
new NativeClass(this.webview);
|
||||||
|
|
||||||
let self: this = this;
|
let self: this = this;
|
||||||
// this._text_to_Speech = new Text_to_Speech();
|
// 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));
|
cc.view.setResizeCallback(this._resize.bind(this));
|
||||||
this._resize();
|
this._resize();
|
||||||
|
|
||||||
const FCMToken: string = NativeClass.Instance.GetFCMToken();
|
|
||||||
console.log(`FCMToken ${FCMToken}`);
|
|
||||||
|
|
||||||
// Set EventListener
|
// Set EventListener
|
||||||
window.addEventListener("message", function (e: MessageEvent<any>): void {
|
window.addEventListener("message", function (e: MessageEvent<any>): void {
|
||||||
let data: any = e.data;
|
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
|
* @example
|
||||||
* CallParent('Speak', '我愛豬涵')
|
* CallParent('Speak', '我愛豬涵')
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
// import Text_to_Speech from "./Text_to_Speech";
|
// import Text_to_Speech from "./Text_to_Speech";
|
||||||
|
|
||||||
|
import { System_Eevent } from "./Engine/CatanEngine/CSharp/System/System_Eevent";
|
||||||
|
|
||||||
const { ccclass } = cc._decorator;
|
const { ccclass } = cc._decorator;
|
||||||
|
|
||||||
@ccclass
|
@ccclass
|
||||||
@ -13,6 +15,8 @@ export default class NativeClass extends cc.Component {
|
|||||||
|
|
||||||
//#region public 屬性
|
//#region public 屬性
|
||||||
|
|
||||||
|
public WebView: cc.WebView = null;
|
||||||
|
|
||||||
public URLscheme: Object = {};
|
public URLscheme: Object = {};
|
||||||
|
|
||||||
public URLschemeFlags: number = 0;
|
public URLschemeFlags: number = 0;
|
||||||
@ -27,9 +31,10 @@ export default class NativeClass extends cc.Component {
|
|||||||
|
|
||||||
//#region Lifecycle
|
//#region Lifecycle
|
||||||
|
|
||||||
constructor() {
|
constructor(...param: any[]) {
|
||||||
super();
|
super();
|
||||||
NativeClass._instance = this;
|
NativeClass._instance = this;
|
||||||
|
this.WebView = param[0];
|
||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,6 +137,20 @@ export default class NativeClass extends cc.Component {
|
|||||||
|
|
||||||
//#region Custom Function
|
//#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 */
|
/** GetFCMToken */
|
||||||
public GetFCMToken(): string {
|
public GetFCMToken(): string {
|
||||||
let resp: any = "";
|
let resp: any = "";
|
||||||
|
Loading…
Reference in New Issue
Block a user