You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.9 KiB
64 lines
1.9 KiB
import { _decorator,Node, Rect, rect, Mat4, mat4, Component, Camera, director, View, view, UITransform, Vec3 } from "cc";
|
|
import { Utils } from "../ExUtils/Utils";
|
|
|
|
|
|
const {ccclass, property, menu, requireComponent, executeInEditMode, playOnFocus} = _decorator;
|
|
|
|
let _rect_temp_visible: Rect = rect();
|
|
let _rect_temp_child: Rect = rect();
|
|
|
|
let _mat4_temp: Mat4 = mat4();
|
|
let _mat4_camera_temp: Mat4 = mat4();
|
|
|
|
@ccclass
|
|
export default class VisibleRangeClippingSelf extends Component {
|
|
|
|
@property(Node)
|
|
selfNode:Node;
|
|
|
|
@property(Node)
|
|
mTarget:Node;
|
|
|
|
left:Vec3 = new Vec3();
|
|
right:Vec3 = new Vec3();
|
|
mid:Vec3 = new Vec3();
|
|
|
|
private _checkContentNode: Node;
|
|
|
|
// LIFE-CYCLE CALLBACKS:
|
|
|
|
protected onLoad(): void {
|
|
this._initCheck();
|
|
}
|
|
|
|
private _initCheck() {
|
|
this._checkContentNode = this.mTarget;
|
|
}
|
|
|
|
private _updateOpacity () {
|
|
const viewNode = this._checkContentNode;
|
|
if (!viewNode || !this.selfNode) return;
|
|
_rect_temp_visible = this.selfNode.uiTrans.getBoundingBoxToWorld();
|
|
_rect_temp_visible.y-=206;
|
|
_rect_temp_visible.height+=206;
|
|
const children = viewNode.children;
|
|
let isShow = true;
|
|
//Utils.PerUtils.start()
|
|
for (let i = 0, ilen = children?.length; i < ilen; i++) {
|
|
// 参考 getBoundingBox 算法计算包围盒.
|
|
const tNode = children[i];
|
|
//if (c.name == 'tipCenter' || c['clip']) continue;
|
|
if (tNode.getComponent(VisibleRangeClippingSelf)) continue;
|
|
_rect_temp_child = tNode.uiTrans.getBoundingBoxToWorld();
|
|
isShow = _rect_temp_visible.intersects(_rect_temp_child);
|
|
CNodeUtils.setOpacity(tNode,isShow ? 255 : 0);
|
|
}
|
|
//Utils.PerUtils.End("透明度处理")
|
|
}
|
|
|
|
update (dt) {
|
|
if (!(director.getTotalFrames() % 6)) {
|
|
this._updateOpacity();
|
|
}
|
|
}
|
|
}
|
|
|