import Controller from "../../framework/controller/Controller" ; import { Config } from "../config/Config" ; import { CommonService } from "../net/CommonService" ; import { LobbyService } from "../net/LobbyService" ; import { Manager } from "./Manager" ; description const { ccclass , property , menu } = cc . _decorator ; @ ccclass @ menu ( "manager/MainController" ) export default class MainController extends Controller < CommonService > { description private _enterBackgroundTime = 0 ; onLoad ( ) { Manager . resolutionHelper . onLoad ( this . node ) ; Manager . netManager . addNetControllers ( this . node ) ; Manager . tips . preloadPrefab ( ) ; Manager . uiLoading . preloadPrefab ( ) ; Manager . alert . preLoadPrefab ( ) ; let showUI = cc . find ( "showUI" , this . node ) ; let showNode = cc . find ( "showNode" , this . node ) ; let showRes = cc . find ( "showRes" , this . node ) ; if ( showUI && showNode && showRes ) { showUI . zIndex = 9999 ; showNode . zIndex = 9999 ; showRes . zIndex = 9999 ; let isShow = false ; if ( Config . isShowDebugButton ) { isShow = true ; showUI . on ( cc . Node . EventType . TOUCH_END , ( ) => { Manager . uiManager . printViews ( ) ; } ) ; showNode . on ( cc . Node . EventType . TOUCH_END , ( ) => { Manager . uiManager . printCanvasChildren ( ) ; } ) ; showRes . on ( cc . Node . EventType . TOUCH_END , ( ) => { } ) ; } showUI . active = isShow ; showNode . active = isShow ; showRes . active = isShow ; } cc . game . on ( cc . game . EVENT_HIDE , this . onEnterBackground , this ) ; cc . game . on ( cc . game . EVENT_SHOW , this . onEnterForgeground , this ) ; cc . director . on ( cc . Director . EVENT_AFTER_DRAW , this . _onDirectorAfterDraw , this ) ; Manager . logicManager . onLoad ( this . node ) ; } description private _onDirectorAfterDraw ( ) { Manager . uiManager . onDirectorAfterDraw ( ) ; } update ( ) { LobbyService . instance . handMessage ( ) ; Manager . assetManager . remote . update ( ) ; } onDestroy ( ) { Manager . resolutionHelper . onDestroy ( ) ; Manager . netManager . removeNetControllers ( this . node ) ; cc . systemEvent . off ( cc . SystemEvent . EventType . KEY_UP ) ; cc . game . off ( cc . game . EVENT_HIDE ) ; cc . game . off ( cc . game . EVENT_SHOW ) ; Manager . logicManager . onDestroy ( this . node ) ; } private onEnterBackground ( ) { this . _enterBackgroundTime = Date . timeNow ( ) ; cc . log ( `[MainController]` , `onEnterBackground ${ this . _enterBackgroundTime }` ) ; Manager . globalAudio . onEnterBackground ( ) ; this . service && this . service . onEnterBackground ( ) ; } private onEnterForgeground ( ) { let now = Date . timeNow ( ) ; let inBackgroundTime = now - this . _enterBackgroundTime ; cc . log ( `[MainController]` , `onEnterForgeground ${ now } background total time : ${ inBackgroundTime }` ) ; Manager . globalAudio . onEnterForgeground ( inBackgroundTime ) ; this . service && this . service . onEnterForgeground ( inBackgroundTime ) ; } }