import { LogicEventData , LogicType } from "../event/LogicEvent" ; import EventComponent from "../../framework/base/EventComponent" ; import { ResourceData , ResourceCacheData , ENABLE_CHANGE_LANGUAGE } from "../../framework/base/Defines" ; import ResourceLoader , { ResourceLoaderError } from "../../framework/assetManager/ResourceLoader" ; import { EventApi } from "../../framework/event/EventApi" ; import { Config } from "../config/Config" ; import { Manager } from "../manager/Manager" ; description export class Logic extends EventComponent { protected logTag = `[Logic]` ; protected _loader : ResourceLoader = null ; protected logicType : LogicType = LogicType . UNKNOWN ; constructor ( ) { super ( ) ; this . _loader = new ResourceLoader ( ) ; this . _loader . getLoadResources = this . getLoadResources . bind ( this ) ; this . _loader . onLoadComplete = this . onLoadResourceComplete . bind ( this ) ; this . _loader . onLoadProgress = this . onLoadResourceProgress . bind ( this ) ; } protected bindingEvents ( ) { super . bindingEvents ( ) ; if ( ENABLE_CHANGE_LANGUAGE ) { this . registerEvent ( EventApi . CHANGE_LANGUAGE , this . onLanguageChange ) ; } } protected get bundle ( ) : string { cc . error ( `请子类重写protected get bundle,返回游戏的包名,即 asset bundle name` ) ; return "" ; } description public onEnterComplete ( data ) { } protected onLanguageChange ( ) { } public init ( data ) { if ( this . logicType == LogicType . UNKNOWN ) { cc . error ( `未对正确的对logicType赋值` ) ; } this . node = data ; } public onLoad ( ) { if ( ! ! this . bundle ) { Config . assetBundle [ `${ this . bundle }` ] = this . bundle ; } else { cc . error ( `请子类重写protected get bundle,返回游戏的包名,即 asset bundle name` ) ; } super . onLoad ( ) ; } public onDestroy ( ) { super . onDestroy ( ) ; this . node = null ; } description protected getLoadResources ( ) { return [ ] ; } description protected onLoadResourceComplete ( err ) { } description protected onLoadResourceProgress ( loadedCount , total , data ) { } description protected getNetControllerType ( ) { return null ; } protected removeNetComponent ( ) { let type = this . getNetControllerType ( ) ; if ( type ) { if ( this . node . getComponent ( type ) ) { this . node . removeComponent ( type ) ; Manager . gameController = null ; } } } protected addNetComponent ( ) { let type = this . getNetControllerType ( ) ; if ( type ) { let controller = this . node . getComponent ( type ) ; if ( ! controller ) { controller = this . node . addComponent ( type ) ; } Manager . gameController = controller ; return controller ; } return null ; } }