53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
/*
|
||
* @Author: WoNiu
|
||
* @Date: 2024-03-24 16:09:55
|
||
* @LastEditTime: 2024-03-24 16:30:46
|
||
* @LastEditors: WoNiu
|
||
* @Description: 通过边框显示node的位置和大小,默认锚点(0,1)
|
||
*/
|
||
import { _decorator, Color, Component, Graphics, Node, UITransform } from 'cc';
|
||
const { ccclass, property } = _decorator;
|
||
|
||
@ccclass('ShowNodeBorder')
|
||
/**
|
||
* @description: 通过边框显示node的位置和大小,默认锚点(0,1)
|
||
*/
|
||
export class ShowNodeBorder extends Component {
|
||
|
||
graphics: Graphics;
|
||
|
||
onLoad() {
|
||
if(this.node.getComponent(Graphics)){
|
||
this.graphics = this.node.getComponent(Graphics);
|
||
}else{
|
||
this.graphics = this.node.addComponent(Graphics);
|
||
}
|
||
|
||
this.updateBorder();
|
||
}
|
||
|
||
updateBorder() {
|
||
const borderColor = Color.YELLOW;
|
||
const borderWidth = 4;
|
||
|
||
const contentSize = this.node.getComponent(UITransform).contentSize;
|
||
|
||
this.graphics.clear();
|
||
this.graphics.strokeColor = borderColor;
|
||
this.graphics.lineWidth = borderWidth;
|
||
// this.graphics.rect(-contentSize.width / 2, -contentSize.height / 2, contentSize.width, contentSize.height);// 锚点 (0,0)
|
||
this.graphics.rect(0, 0, contentSize.width, -contentSize.height); //锚点 (0,1)
|
||
this.graphics.stroke();
|
||
}
|
||
|
||
start() {
|
||
|
||
}
|
||
|
||
update(deltaTime: number) {
|
||
|
||
}
|
||
}
|
||
|
||
|