import { _decorator,Constructor, Node } from 'cc'; import { UIController } from '../easy_ui_framework/UIController'; // 打包之后有问题不支持名称注入 export class UIControllerAnnotation { private static initMap = new Map() private static initElement = new Map>() static UI(param: { bundleName?: any, path: any } | string) { return function (target: Constructor) { // 首字母小写注入 if(typeof param == 'string'){ UIControllerAnnotation.initMap.set(target,{path:param}) }else{ UIControllerAnnotation.initMap.set(target,param) } } } static getElement(target:Constructor){ // 这里还要找到父类的结果 if(!target){ return null } if(target == UIController){ return UIControllerAnnotation.initElement.get(target) } let res = new Map let parent = Object.getPrototypeOf(target) let parentMap = this.getElement(parent) let myMap = UIControllerAnnotation.initElement.get(target) if(parentMap){ parentMap.forEach((vlaue,key)=>res.set(key,vlaue)) } if(myMap){ myMap.forEach((vlaue,key)=>res.set(key,vlaue)) } return res } static getUI(ui:Constructor){ return UIControllerAnnotation.initMap.get(ui) } static element(type: Constructor|{type:any,prefix?:string,path?:string} = Node) { let res: PropertyDecorator = function (target:Object, prop: string) { // 首字母小写注入 let map =UIControllerAnnotation.initElement.get(target.constructor) if(!map){ map= new Map UIControllerAnnotation.initElement.set(target.constructor,map) } if(map.get(prop)){ console.warn("存在同名注入,请检查代码,prop==>",prop) } if(typeof type == 'object'){ map.set(prop,type) }else{ map.set(prop,{type:type,prefix:'#'}) } } return res } }