import { _decorator, Component } from 'cc'; import { UICloseReason } from './UILayer'; import { AppKernel } from '../../app/AppKernel'; import type { UIViewID } from '../../define/UIDefine'; const { ccclass } = _decorator; @ccclass('UIView') export class UIView extends Component { /** UIManager 用它识别并接管场景中预放置的 UIView。 */ readonly viewId: UIViewID | null = null; public getViewID(): UIViewID { if (!this.viewId) { return (this?.node?.name || "") as UIViewID; } return this.viewId; } async internalCreate(): Promise { await this.onCreate(); } async internalOpen(params: TParams): Promise { this.node.setSiblingIndex await this.onOpen(params); } async internalBeforeClose(reason: UICloseReason): Promise { return this.onBeforeClose(reason); } async internalClose(reason: UICloseReason): Promise { await this.onClose(reason); } internalDispose(): void { this.onDispose(); } protected onDestroy(): void { AppKernel.events.offTarget(this); } protected onCreate(): void | Promise { } protected onOpen(_params: TParams): void | Promise { } protected onFocus(): void { } protected onBlur(): void { } protected onBeforeClose(_reason: UICloseReason): boolean | Promise { return true; } protected onClose(_reason: UICloseReason): void | Promise { } protected onDispose(): void { } }