| 1234567891011121314151617181920212223242526272829303132333435 |
- import { _decorator, Component, Node, UITransform, Widget,screen, find, view } from 'cc';
- const { ccclass, property } = _decorator;
- @ccclass('MenuButtonAdapter')
- export class MenuButtonAdapter extends Component {
- protected onLoad(): void {
- // 开始适配
- let res = chsdk.getMenuButtonBoundingClientRect();
- if (!res) {
- return
- }
- console.log(res)
- let wid = this.getComponent(Widget) || this.addComponent(Widget)
- let rect = this.getComponent(UITransform).getBoundingBoxToWorld()
- // 这个是使该节点在菜单下面
- let ratio = screen.devicePixelRatio||1;
- let scale = view.getScaleY();
-
- let factor = (scale / ratio)||1;
- let frameHeight = screen.windowSize.height / screen.devicePixelRatio
- let top = frameHeight - (rect.y + rect.height) * factor;
- let c = wid.top+top - (res.bottom)
- if(c<0){
- wid.top = wid.top+Math.abs(c/factor)
- }
-
- }
- update(deltaTime: number) {
- }
- }
|