import { _decorator, Component, Node, sys, screen, view, Widget } from 'cc'; const { ccclass, property } = _decorator; declare var wx: any; declare var tt: any; @ccclass('SafeAreaAdapter') export class SafeAreaAdapter extends Component { protected onLoad(): void { // 开始适配 // let res = this.getWindowInfo(); // if (!res) { // return // } // if (!res.safeArea) { // return // } // console.log(res) let widget = this.getComponent(Widget) || this.addComponent(Widget) // // 这个是使该节点在菜单下面 // let scale = view.getScaleY(); // let ratio = screen.devicePixelRatio || 1; // let factor = (scale / ratio) || 1; // let len = Math.abs(res.safeArea.top) widget.top =Math.max(getSafeLen(),widget.top) } // getWindowInfo() { // if (sys.platform === sys.Platform.WECHAT_GAME) { // return wx.getWindowInfo() // } else if (sys.platform === sys.Platform.BYTEDANCE_MINI_GAME) { // return tt.getSystemInfoSync() // } else { // } // } } export function getSafeLen():number{ let getWindowInfo =() =>{ if (sys.platform === sys.Platform.WECHAT_GAME) { return wx.getWindowInfo() } else if (sys.platform === sys.Platform.BYTEDANCE_MINI_GAME) { return tt.getSystemInfoSync() } else { } } let res = getWindowInfo(); if (!res) { return 0 } if (!res.safeArea) { return 0 } console.log(res) // 这个是使该节点在菜单下面 let scale = view.getScaleY(); let ratio = screen.devicePixelRatio || 1; let factor = (scale / ratio) || 1; let len = Math.abs(res.safeArea.top) return len / factor }