DaFuWeng/assets/GlobalScript/CommonComponent/ShowNodeBorder.ts

53 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* @Author: WoNiu
* @Date: 2024-03-24 16:09:55
* @LastEditTime: 2024-03-24 16:30:46
* @LastEditors: WoNiu
* @Description: 通过边框显示node的位置和大小默认锚点01
*/
import { _decorator, Color, Component, Graphics, Node, UITransform } from 'cc';
const { ccclass, property } = _decorator;
@ccclass('ShowNodeBorder')
/**
* @description: 通过边框显示node的位置和大小默认锚点01
*/
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) {
}
}