Files
fc/dev/project/library/imports/ea/ea086cf4-8305-4516-ae85-8f0ea2f2e527.js
T

71 lines
1.9 KiB
JavaScript
Raw Normal View History

2026-05-24 10:21:26 +08:00
"use strict";
cc._RF.push(module, 'ea086z0gwVFFq6Fjw6i8uUn', 'nx.fx.safeArea');
// Scripts/nx/cmp/flex/nx.fx.safeArea.js
"use strict";
/******************************************************************
* Copyright(C) 2019 - 2020 Nx Studio
*
* 安全区
*
* 2018.05.18
******************************************************************/
cc.Class({
"extends": cc.Component,
properties: {
space: {
"default": 60,
displayName: "宽度"
},
reverse: {
"default": false,
displayName: "逆向操作"
}
},
// 编辑器特性
editor: {
// 允许当前组件在编辑器模式下运行
executeInEditMode: false,
// requireComponent 参数用来指定当前组件的依赖组件
requireComponent: cc.Widget,
// 当本组件添加到节点上后,禁止同类型(含子类)的组件再添加到同一个节点,防止逻辑发生冲突
disallowMultiple: true,
// menu 用来将当前组件添加到组件菜单中,方便用户查找
menu: "Nx/组件|安全区"
},
// 首发
onEnable: function onEnable() {
// 暂时只处理横屏处理
// 暂时固定宽高比判定,不用获取safeArea来设定
var cmp = this.node.getComponent(cc.Widget);
var hor = nx.frame.vget("IsLandscape");
var rr = nx.frame.vget("RuntimeWHRate");
if (!cmp || !hor || rr <= 1.8) {
return;
}
// 逆向操作
// 作为安全区内的子节点,脱离安全区限制
if (this.reverse) {
cmp.target = game.views;
cmp.left = 0;
cmp.right = 0;
} else {
// 正向操作
cmp.left = this.space;
cmp.right = this.space;
}
cmp.updateAlignment();
this.node.children.forEach(function (_node) {
var cmp = _node.getComponent(cc.Widget);
if (cmp) {
cmp.updateAlignment();
}
});
}
});
cc._RF.pop();