This commit is contained in:
建喵 2022-01-21 11:01:58 +08:00
parent 506d8b69e9
commit b1dffd1f6b
5 changed files with 81 additions and 37 deletions

12
assets/Plugins.meta Normal file
View File

@ -0,0 +1,12 @@
{
"ver": "1.1.2",
"uuid": "9e28a2e5-f683-4157-bfc5-f19dd02440b1",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}

View File

@ -0,0 +1,9 @@
{
"ver": "1.0.8",
"uuid": "9f49e939-dfca-4a26-81e2-e22c98a61c90",
"isPlugin": true,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": true,
"subMetas": {}
}

View File

@ -1,3 +1,5 @@
import Text_to_Speech from "./Text_to_Speech";
const { ccclass, property } = cc._decorator;
@ccclass
@ -12,6 +14,12 @@ export default class Manager extends cc.Component {
//#endregion
//#region private
private _text_to_Speech: Text_to_Speech = new Text_to_Speech();
//#endregion
//#region Lifecycle
protected onLoad(): void {
@ -20,17 +28,14 @@ export default class Manager extends cc.Component {
let data: any = e.data;
let method: string = data.method;
let value: any = data.value;
if (method && self[method]) {
if (value) {
self[method](...value);
return;
} else if (self[method]) {
self[method]();
return;
}
}
console.log(`not function: ${method}, value: ${value}`);
self.Birdge(method, value)
}, false);
if (!window["Bridge"]) {
window["Bridge"] = function (method: string = "", value: string = ""): void {
self.Birdge(method, value)
};
}
let href: string = window.location.href;
this.webview.url = `https://karolchang.github.io/jm-expense-vue-ts/?host=${href}&ignore=${Date.now()}`;
@ -41,6 +46,20 @@ export default class Manager extends cc.Component {
this._resize();
}
public Birdge(method: string, value: string = ""): void {
let self: this = this;
if (method && self[method]) {
if (value) {
self[method](value);
return;
} else if (self[method]) {
self[method]();
return;
}
}
console.log(`not function: ${method}, value: ${value}`);
}
private _closeBG(): void {
if (this.webview.node.opacity === 0) {
this.BG.destroy();
@ -54,6 +73,10 @@ export default class Manager extends cc.Component {
console.log(msg);
}
private _speak(msg: string): void {
this._text_to_Speech.speak(msg);
}
private _alert(msg: string): void {
alert(msg);
}

View File

@ -1,36 +1,27 @@
const { ccclass, property } = cc._decorator;
export default class Text_to_Speech {
//#region 外調參數
@ccclass
export default class Text_to_Speech extends cc.Component {
private _responsiveVoice: any = window["responsiveVoice"];
// LIFE-CYCLE CALLBACKS:
//#endregion
start(): void {
//#region Custom
constructor() {
this._responsiveVoice.speak("hello world");
}
public speak(msg: string): void {
let self: this = this;
let url: string = window.location.search;
let request: object = [];
if (url.indexOf("?") !== -1) {
let str: string = url.substr(1);
let strs: string[] = str.split("&");
for (let i: number = 0; i < strs.length; i++) {
request[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
}
}
let ResponsiveVoice: any = responsiveVoice;
// var voicelist: any = ResponsiveVoice.getVoices();
// let voice: string = this.EditBox.string;
// let voice: string = "傻B豆豆";
let voice: string = request["voice"];
ResponsiveVoice.speak(voice, "Chinese Female", {
this._responsiveVoice.speak(msg, "Chinese Female", {
onstart: function (Callback: any): void {
// IsEnd = true;
self.node.getChildByName("Label").getComponent(cc.Label).string = voice;
console.log(`onstart msg: ${msg}`);
},
onend: function (Callback: any): void {
console.log(`onstart msg: ${msg}`);
},
// onend: function (Callback: any): void {
// // IsEnd = true;
// },
});
}
//#endregion
}

View File

@ -0,0 +1,9 @@
{
"ver": "1.0.8",
"uuid": "99fa9c05-c449-4a27-b629-42f77916556a",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}