web手机端横竖屏切换问题

import * as cc from "cc";
import {_decorator, Component} from "cc";

const {ccclass, property} = _decorator;

@ccclass("FixCocos")
export class FixCocos extends Component {

update(deltaTime: number) {
    if(!this._fixed){
        try {
            let root = cc.director.root as any;
            if(root){
                let ExecutorContext = root["_pipeline"]["_executor"]["_context"];
                let rawRootResize = root.resize.bind(root);
                root.resize = (width:number, height:number)=>{
                    rawRootResize(width, height);

                    root["__handleResize"] = false;
                }
                let rawExecutorContextResize = ExecutorContext.resize.bind(ExecutorContext);
                ExecutorContext.resize = (width:number, height:number)=>{
                    if(root["__handleResize"] == false){
                        root["__handleResize"] = true;
                        ExecutorContext.devicePasses.clear();
                    }
                    rawExecutorContextResize(width, height);
                }
                this._fixed = true;
            }
        } catch (e: any) {

        }
    }
}

private _fixed = false;
}

挂在启动脚本就行

你这个方案会导致slider和scrollview无法正常工作