mirror of
https://github.com/blanking003/cx-cocos.git
synced 2024-12-26 11:49:01 +00:00
39 lines
774 B
TypeScript
39 lines
774 B
TypeScript
|
|
||
|
import {_decorator, Component, Widget, UITransform, CCInteger} from 'cc';
|
||
|
const {ccclass, property} = _decorator;
|
||
|
|
||
|
@ccclass('cxui.safearea')
|
||
|
class CxuiSafearea extends Component
|
||
|
{
|
||
|
@property
|
||
|
private safeHeight = 170;
|
||
|
|
||
|
@property
|
||
|
private safeWidgetTop = 0;
|
||
|
|
||
|
@property
|
||
|
private safeWidgetBottom = 0;
|
||
|
|
||
|
onLoad ()
|
||
|
{
|
||
|
if (cx.os.native && !cx.os.android && cx.sh/cx.sw > 1.8)
|
||
|
{
|
||
|
if (this.safeHeight)
|
||
|
{
|
||
|
var uiTransform = this.node.getComponent(UITransform);
|
||
|
uiTransform?.setContentSize(uiTransform.width, this.safeHeight);
|
||
|
}
|
||
|
|
||
|
if (this.safeWidgetTop || this.safeWidgetBottom)
|
||
|
{
|
||
|
var widget = this.node.getComponent(Widget);
|
||
|
if (widget)
|
||
|
{
|
||
|
widget.top = this.safeWidgetTop;
|
||
|
widget.bottom = this.safeWidgetBottom;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|