[add] 3.6 first
This commit is contained in:
		| @@ -1,119 +1,129 @@ | ||||
| import Text_to_Speech from "./Text_to_Speech"; | ||||
| import { Component, game, macro, Node, screen, size, Size, view, WebView, _decorator } from 'cc'; | ||||
| import { DEBUG } from 'cc/env'; | ||||
| const { ccclass, property } = _decorator; | ||||
|  | ||||
| const { ccclass, property } = cc._decorator; | ||||
| @ccclass('Manager') | ||||
| export class Manager extends Component { | ||||
| 	//#region 外調參數 | ||||
|  | ||||
| @ccclass | ||||
| export default class Manager extends cc.Component { | ||||
|     //#region 外調參數 | ||||
| 	@property({ type: WebView }) | ||||
| 	public webview: WebView = null; | ||||
|  | ||||
|     @property({ type: cc.WebView }) | ||||
|     public webview: cc.WebView = null; | ||||
| 	@property({ type: Node }) | ||||
| 	public BG: Node = null; | ||||
|  | ||||
|     @property({ type: cc.Node }) | ||||
|     public BG: cc.Node = null; | ||||
| 	//#endregion | ||||
|  | ||||
|     //#endregion | ||||
| 	//#region private | ||||
|  | ||||
|     //#region private | ||||
| 	// private _text_to_Speech: Text_to_Speech; | ||||
|  | ||||
|     private _text_to_Speech: Text_to_Speech; | ||||
| 	private _isSetResize: boolean = false; | ||||
|  | ||||
|     //#endregion | ||||
| 	//#endregion | ||||
|  | ||||
|     //#region Lifecycle | ||||
| 	//#region Lifecycle | ||||
|  | ||||
|     protected onLoad(): void { | ||||
|         if (CC_DEBUG) { | ||||
|             console.log("Debug"); | ||||
|         } | ||||
|         let self: this = this; | ||||
|         this._text_to_Speech = new Text_to_Speech(); | ||||
|         window.addEventListener("message", function (e: MessageEvent<any>): void { | ||||
|             let data: any = e.data; | ||||
|             let method: string = data.method; | ||||
|             let value: any = data.value; | ||||
|             self.Birdge(method, ...value); | ||||
|         }, false); | ||||
| 	protected onLoad(): void { | ||||
| 		if (DEBUG) { | ||||
| 			console.log("Debug"); | ||||
| 		} | ||||
| 		let self: this = this; | ||||
| 		// this._text_to_Speech = new Text_to_Speech(); | ||||
| 		window.addEventListener("message", function (e: MessageEvent<any>): void { | ||||
| 			let data: any = e.data; | ||||
| 			let method: string = data.method; | ||||
| 			let value: any = data.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; | ||||
| 		if (!window["Bridge"]) { | ||||
| 			window["Bridge"] = function (method: string = "", value: string = ""): void { | ||||
| 				self.Birdge(method, value); | ||||
| 			}; | ||||
| 		} | ||||
| 		let href: string = window.location.href; | ||||
|  | ||||
|         // let url: string = `https://karolchang.github.io/jm-expense-vue-ts/?host=${href}&ignore=${Date.now()}`; | ||||
|         // let url: string = `http://220.134.195.1/public/bonus_casino/html5/jianmiau/BJ_Casino_Rank/?v=${Date.now()}`; | ||||
|         // let url: string = `http://karol.jianmiau.cf/jm-expense-vue-ts/?v=${Date.now()}`; | ||||
|         let url: string = `https://jm-expense-2022.firebaseapp.com/login?v=${Date.now()}`; | ||||
|         this.webview.url = url; | ||||
|         // this.webview.url = `http://localhost:8080/jm-expense-vue-ts/?host=${href}&ignore=${Date.now()}`; | ||||
|         this.webview.node.active = true; | ||||
| 		// let url: string = `https://karolchang.github.io/jm-expense-vue-ts/?host=${href}&ignore=${Date.now()}`; | ||||
| 		// let url: string = `http://220.134.195.1/public/bonus_casino/html5/jianmiau/BJ_Casino_Rank/?v=${Date.now()}`; | ||||
| 		// let url: string = `http://karol.jianmiau.cf/jm-expense-vue-ts/?v=${Date.now()}`; | ||||
| 		let url: string = `https://jm-expense-2022.firebaseapp.com/login?v=${Date.now()}`; | ||||
| 		this.webview.url = url; | ||||
| 		// this.webview.url = `http://localhost:8080/jm-expense-vue-ts/?host=${href}&ignore=${Date.now()}`; | ||||
| 		this.webview.node.active = true; | ||||
|  | ||||
|         cc.view.setResizeCallback(this._resize.bind(this)); | ||||
|         this._resize(); | ||||
|     } | ||||
| 		view.setResizeCallback(this._resize.bind(this)); | ||||
| 		this._resize(); | ||||
| 	} | ||||
|  | ||||
|     /** 跨版本溝通 | ||||
|      * @example | ||||
|      * CallParent('Speak', '我愛豬涵') | ||||
|      */ | ||||
|     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}`); | ||||
|     } | ||||
| 	/** 跨版本溝通 | ||||
| 	 * @example | ||||
| 	 * CallParent('Speak', '我愛豬涵') | ||||
| 	 */ | ||||
| 	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}`); | ||||
| 	} | ||||
|  | ||||
|     public CloseBG(): void { | ||||
|         this.BG.destroy(); | ||||
|     } | ||||
| 	public CloseBG(): void { | ||||
| 		if (this.BG) { | ||||
| 			this.BG.destroy(); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
|     public Log(msg: string): void { | ||||
|         console.log(msg); | ||||
|     } | ||||
| 	public Log(msg: string): void { | ||||
| 		console.log(msg); | ||||
| 	} | ||||
|  | ||||
|     public Speak(msg: string): void { | ||||
|         this._text_to_Speech.speak(msg); | ||||
|     } | ||||
| 	public Speak(msg: string): void { | ||||
| 		// this._text_to_Speech.speak(msg); | ||||
| 	} | ||||
|  | ||||
|     public Alert(msg: string): void { | ||||
|         alert(msg); | ||||
|     } | ||||
| 	public Alert(msg: string): void { | ||||
| 		alert(msg); | ||||
| 	} | ||||
|  | ||||
|     private _resize(): void { | ||||
|         let Canvas: cc.Canvas = cc.Canvas.instance; | ||||
|         let rect: DOMRect = cc.game.canvas.getBoundingClientRect(); | ||||
|         /** 判断是否是横屏 */ | ||||
|         let landscape: boolean = false; | ||||
|         if (rect.width > rect.height) { | ||||
|             landscape = true; | ||||
|         } | ||||
|         // 根据横竖屏调整节点的位置适配等 | ||||
|         let frameSize: cc.Size = cc.view.getFrameSize(); | ||||
|         if (landscape) { | ||||
|             // 横屏 | ||||
|             cc.view.setOrientation(cc.macro.ORIENTATION_LANDSCAPE); | ||||
|             if (frameSize.height > frameSize.width) { | ||||
|                 cc.view.setFrameSize(frameSize.height, frameSize.width); | ||||
|             } | ||||
|             Canvas.designResolution = cc.size(1920, 1080); | ||||
|         } else { | ||||
|             // 竖屏 | ||||
|             cc.view.setOrientation(cc.macro.ORIENTATION_PORTRAIT); | ||||
|             if (frameSize.width > frameSize.height) { | ||||
|                 cc.view.setFrameSize(frameSize.height, frameSize.width); | ||||
|             } | ||||
|             Canvas.designResolution = cc.size(1080, 1920); | ||||
|         } | ||||
|     } | ||||
| 	private _resize(): void { | ||||
| 		if (this._isSetResize) { | ||||
| 			return; | ||||
| 		} | ||||
| 		this._isSetResize = true; | ||||
| 		let rect: DOMRect = game.canvas.getBoundingClientRect(); | ||||
| 		/** 判断是否是横屏 */ | ||||
| 		let landscape: boolean = false; | ||||
| 		if (rect.width > rect.height) { | ||||
| 			landscape = true; | ||||
| 		} | ||||
| 		// 根据横竖屏调整节点的位置适配等 | ||||
| 		let frameSize: Size = screen.windowSize; | ||||
| 		if (landscape) { | ||||
| 			// 横屏 | ||||
| 			view.setOrientation(macro.ORIENTATION_LANDSCAPE); | ||||
| 			if (frameSize.height > frameSize.width) { | ||||
| 				view.setFrameSize(frameSize.height, frameSize.width); | ||||
| 				screen.windowSize = size(frameSize.height, frameSize.width); | ||||
| 			} | ||||
| 			view.setDesignResolutionSize(1920, 1080, view.getResolutionPolicy()); | ||||
| 		} else { | ||||
| 			// 竖屏 | ||||
| 			view.setOrientation(macro.ORIENTATION_PORTRAIT); | ||||
| 			if (frameSize.width > frameSize.height) { | ||||
| 				// view.setFrameSize(frameSize.height, frameSize.width); | ||||
| 				screen.windowSize = size(frameSize.height, frameSize.width); | ||||
| 			} | ||||
| 			view.setDesignResolutionSize(1080, 1920, view.getResolutionPolicy()); | ||||
| 		} | ||||
| 		this._isSetResize = false; | ||||
| 	} | ||||
|  | ||||
|     //#endregion | ||||
| 	//#endregion | ||||
| } | ||||
|   | ||||
| @@ -1,9 +1,9 @@ | ||||
| { | ||||
|   "ver": "1.0.8", | ||||
|   "uuid": "e1b90feb-a217-4493-849d-9a611900d683", | ||||
|   "isPlugin": false, | ||||
|   "loadPluginInWeb": true, | ||||
|   "loadPluginInNative": true, | ||||
|   "loadPluginInEditor": false, | ||||
|   "subMetas": {} | ||||
| } | ||||
|   "ver": "4.0.23", | ||||
|   "importer": "typescript", | ||||
|   "imported": true, | ||||
|   "uuid": "6deac97e-4a6e-4a3a-bc1c-f5b4ad80c26a", | ||||
|   "files": [], | ||||
|   "subMetas": {}, | ||||
|   "userData": {} | ||||
| } | ||||
|   | ||||
| @@ -1,9 +1,9 @@ | ||||
| { | ||||
|   "ver": "1.0.8", | ||||
|   "uuid": "99fa9c05-c449-4a27-b629-42f77916556a", | ||||
|   "isPlugin": false, | ||||
|   "loadPluginInWeb": true, | ||||
|   "loadPluginInNative": true, | ||||
|   "loadPluginInEditor": false, | ||||
|   "subMetas": {} | ||||
| } | ||||
|   "ver": "4.0.23", | ||||
|   "importer": "typescript", | ||||
|   "imported": true, | ||||
|   "uuid": "28a462ab-67b9-43c2-8a68-5fa11e66e17e", | ||||
|   "files": [], | ||||
|   "subMetas": {}, | ||||
|   "userData": {} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user