import { EventApi } from "../event/EventApi" ; import EventComponent from "../base/EventComponent" ; import { Service } from "../base/Service" ; import { Message } from "../net/Message" ; description const { ccclass , property } = cc . _decorator ; @ ccclass export default class Controller < ServiceType > extends EventComponent { description public get service ( ) : ServiceType { return < any > ( this . _service ) ; } ; public set service ( value ) { this . _service = < any > value ; } protected bindingEvents ( ) { super . bindingEvents ( ) ; this . registerEvent ( EventApi . NetEvent . ON_OPEN , this . onNetOpen ) ; this . registerEvent ( EventApi . NetEvent . ON_CLOSE , this . onNetClose ) ; this . registerEvent ( EventApi . NetEvent . ON_ERROR , this . onNetError ) ; } protected onNetOpen ( ) { if ( CC_DEBUG ) cc . log ( `--Controller-- onNetOpen---` ) ; } protected onNetClose ( ev ) { if ( CC_DEBUG ) cc . log ( `--Controller-- onNetClose---` ) ; } protected onNetError ( ev ) { if ( CC_DEBUG ) cc . log ( `--Controller-- onNetError---` ) ; } description param msg public send ( msg ) { if ( this . service instanceof Service ) { this . service . send ( msg ) ; } else { cc . error ( "this.service is null" ) ; } } protected get bundle ( ) : string { cc . error ( `请子类重写protected get bundle,返回游戏的包名,即 asset bundle name` ) ; return "" ; } }