From 33484b3406ab3a6afd48c09b01b6395e16275182 Mon Sep 17 00:00:00 2001 From: WoNiu Date: Sun, 24 Mar 2024 17:57:19 +0800 Subject: [PATCH] =?UTF-8?q?1=20=E4=BF=AE=E6=94=B9=E5=9D=90=E6=A0=87?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=20=E7=BB=84=E4=BB=B6=202=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E6=98=BE=E7=A4=BAnode=E4=BD=8D=E7=BD=AE=E5=92=8C?= =?UTF-8?q?=E5=A4=A7=E5=B0=8F=E7=9A=84=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LocationImportComponent.ts | 9 +++- .../CommonComponent/ShowNodeBorder.ts | 52 +++++++++++++++++++ .../CommonComponent/ShowNodeBorder.ts.meta | 9 ++++ 3 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 assets/GlobalScript/CommonComponent/ShowNodeBorder.ts create mode 100644 assets/GlobalScript/CommonComponent/ShowNodeBorder.ts.meta diff --git a/assets/GlobalScript/CommonComponent/LocationImportComponent.ts b/assets/GlobalScript/CommonComponent/LocationImportComponent.ts index 37a670e..5c612ef 100644 --- a/assets/GlobalScript/CommonComponent/LocationImportComponent.ts +++ b/assets/GlobalScript/CommonComponent/LocationImportComponent.ts @@ -1,9 +1,9 @@ /* * @Author: WoNiu * @Date: 2024-03-23 13:22:27 - * @LastEditTime: 2024-03-23 16:12:16 + * @LastEditTime: 2024-03-24 16:04:20 * @LastEditors: WoNiu - * @Description: + * @Description: node坐标控制 */ import { _decorator, @@ -22,6 +22,9 @@ import { const { ccclass, property } = _decorator; @ccclass("LocationImportComponent") +/** + * @description: node坐标控制 + */ export class LocationImportComponent extends Component { editBox: EditBox; @@ -66,6 +69,8 @@ export class LocationImportComponent extends Component { textLabel.color = Color.RED; textLabel.node.setPosition(0, 50); textLabel.node.getComponent(UITransform).anchorPoint = v2(0, 2); + + } update(deltaTime: number) {} diff --git a/assets/GlobalScript/CommonComponent/ShowNodeBorder.ts b/assets/GlobalScript/CommonComponent/ShowNodeBorder.ts new file mode 100644 index 0000000..13daa92 --- /dev/null +++ b/assets/GlobalScript/CommonComponent/ShowNodeBorder.ts @@ -0,0 +1,52 @@ +/* + * @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) { + + } +} + + diff --git a/assets/GlobalScript/CommonComponent/ShowNodeBorder.ts.meta b/assets/GlobalScript/CommonComponent/ShowNodeBorder.ts.meta new file mode 100644 index 0000000..96378ef --- /dev/null +++ b/assets/GlobalScript/CommonComponent/ShowNodeBorder.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "9ef9c0ff-8d63-448d-b95f-89b02e1455f3", + "files": [], + "subMetas": {}, + "userData": {} +}