mirror of
https://github.com/blanking003/cx-cocos.git
synced 2025-12-09 22:28:54 +00:00
init
This commit is contained in:
38
cx3-demo/assets/cx/scripts/cxui.safearea.ts
Normal file
38
cx3-demo/assets/cx/scripts/cxui.safearea.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user