You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.9 KiB
71 lines
1.9 KiB
1 week ago
|
/*
|
||
|
* @Author: YeeChan
|
||
|
* @Date: 2020-12-23 11:46:50
|
||
|
* @Description:
|
||
|
*/
|
||
|
|
||
|
/****************************************************
|
||
|
* cc.Component 的扩展 主要增加初始方法 initView_custom __onInit_custom 和 事件
|
||
|
*****************************************************/
|
||
|
export default abstract class FMComponentExtend extends cc.Component {
|
||
|
//标记
|
||
|
protected __isInit_custom: boolean = false;
|
||
|
//回调
|
||
|
protected _listenerCallView_custom: FMListener;
|
||
|
//各个节点自定义事件
|
||
|
//@ts-ignore
|
||
|
protected abstract EventEnumView_custom: { [key: string]: string; } = {}
|
||
|
//初始方法
|
||
|
protected abstract initView_custom(): void;
|
||
|
|
||
|
|
||
|
protected onLoad() {
|
||
|
this.__onInit_custom();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 外部如果需要里面获取onload中执行的属性,需要在方法执行前调用
|
||
|
*/
|
||
|
protected __onInit_custom() {
|
||
|
if (!this.__isInit_custom) {
|
||
|
this.__isInit_custom = true;
|
||
|
this.initView_custom();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 设置监听
|
||
|
* @param listener
|
||
|
*/
|
||
|
public onListenerEventView_custom(listener: FMListener) {
|
||
|
this._listenerCallView_custom = listener;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 发送事件 (接收结构为(Event,Node,Data) )
|
||
|
* @param event 事件名 @EventEnumView_custom
|
||
|
* @param data 数据结构
|
||
|
*/
|
||
|
protected emitListenerEvent_custom(event: string, data?: any, data2?: any) {
|
||
|
//console.log("发送 " + event)
|
||
|
if (this._listenerCallView_custom) {
|
||
|
callFM_custom(this._listenerCallView_custom, event, this, data, data2);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 判断view 是否激活
|
||
|
*/
|
||
|
public isActiveView_custom(): boolean {
|
||
|
if (cc.isValid(this, true) && this.node.activeInHierarchy) { //没有被销毁 && 在场景中是激活的
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
//当该组件被销毁时调用
|
||
|
protected onDestroy(): void {
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|