123456789101112131415161718192021222324252627282930313233343536373839 |
- /** @format */
- import {Mgr} from '../GameControl'
- import {EVENT} from '../enums/Enum'
- import {ConstValue} from '../data/ConstValue'
- import property = cc._decorator.property
- const {ccclass, disallowMultiple, menu} = cc._decorator
- @ccclass
- @disallowMultiple()
- @menu('自定义组件/BgAdaptor')
- export default class BgAdaptor extends cc.Component {
- @property({
- displayName: '宽度自适应',
- })
- widthFit: boolean = true
- @property({
- displayName: '高度自适应',
- })
- heightFit: boolean = true
- protected onLoad() {
- this.changeSize()
- }
- public onEnable() {
- Mgr.event.add(EVENT.canvasResize, this, this.changeSize)
- }
- public onDisable() {
- Mgr.event.removeAll(this)
- }
- changeSize() {
- // 只拉伸,适配黑边
- if (ConstValue.REAL_WIDTH > this.node.width && this.widthFit) this.node.width = ConstValue.REAL_WIDTH
- if (ConstValue.REAL_HEIGHT > this.node.height && this.heightFit) this.node.height = ConstValue.REAL_HEIGHT
- }
- }
|