mirror of
https://github.com/szrpf/DataBoardDemo.git
synced 2025-11-03 04:45:43 +00:00
v2.3
This commit is contained in:
@@ -598,7 +598,7 @@
|
||||
"_is3DNode": false,
|
||||
"_groupIndex": 0,
|
||||
"groupIndex": 0,
|
||||
"_id": "3d8RDqQvVEfJkF7nWvrxTE"
|
||||
"_id": "76KDntjjFLVKmtFHxYwrV6"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
@@ -660,7 +660,7 @@
|
||||
"_is3DNode": false,
|
||||
"_groupIndex": 0,
|
||||
"groupIndex": 0,
|
||||
"_id": "c3XyfYRgRPB5iyAa58aSsW"
|
||||
"_id": "80Ey3vT8tOoKasdL4WSmVR"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Sprite",
|
||||
@@ -690,7 +690,7 @@
|
||||
"_fillRange": 0,
|
||||
"_isTrimmedMode": true,
|
||||
"_atlas": null,
|
||||
"_id": "8e55OmQuJIBYeXHoG9wTyk"
|
||||
"_id": "cfdPG7L1VJi5XF5TaYomyp"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
@@ -752,7 +752,7 @@
|
||||
"_is3DNode": false,
|
||||
"_groupIndex": 0,
|
||||
"groupIndex": 0,
|
||||
"_id": "d9CzwxVqJA5btSqQ2zxAtr"
|
||||
"_id": "0ccJcWYaxEw6CAV6LDgwBF"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Sprite",
|
||||
@@ -782,7 +782,7 @@
|
||||
"_fillRange": 0,
|
||||
"_isTrimmedMode": true,
|
||||
"_atlas": null,
|
||||
"_id": "28BN/vYpdA75aVQgtJV85T"
|
||||
"_id": "a2z7GHvbBJtbeFFKuZMp8r"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
@@ -844,7 +844,7 @@
|
||||
"_is3DNode": false,
|
||||
"_groupIndex": 0,
|
||||
"groupIndex": 0,
|
||||
"_id": "e1SVVBs6pDmI52ltKoFD6d"
|
||||
"_id": "f7EXG9BGNEv6AWXdMTqWbb"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Sprite",
|
||||
@@ -874,7 +874,7 @@
|
||||
"_fillRange": 0,
|
||||
"_isTrimmedMode": true,
|
||||
"_atlas": null,
|
||||
"_id": "025qCDItxA57ThVMG5sWtQ"
|
||||
"_id": "2aE+3035tDJqfns9wb+A8e"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
@@ -917,7 +917,7 @@
|
||||
"ctor": "Float64Array",
|
||||
"array": [
|
||||
0,
|
||||
150,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
@@ -939,7 +939,7 @@
|
||||
"_is3DNode": false,
|
||||
"_groupIndex": 0,
|
||||
"groupIndex": 0,
|
||||
"_id": "81cIITpURBEbMcOPB7cb6x"
|
||||
"_id": "2b4Sev3gxKqbyDuqgotK3s"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Label",
|
||||
@@ -972,7 +972,7 @@
|
||||
"_N$fontFamily": "Arial",
|
||||
"_N$overflow": 0,
|
||||
"_N$cacheMode": 0,
|
||||
"_id": "08NYYNx61NF42Hhp8PMtsi"
|
||||
"_id": "cbby0qHztEJKoa9kkCSPhN"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.LabelOutline",
|
||||
@@ -990,7 +990,7 @@
|
||||
"a": 255
|
||||
},
|
||||
"_width": 6,
|
||||
"_id": "caGnJok0NK/o3JsDAm2Z52"
|
||||
"_id": "9bWro31eJKybmJGCrePXSg"
|
||||
},
|
||||
{
|
||||
"__type__": "9285eM4YhBJhL8+C569X294",
|
||||
@@ -1029,12 +1029,12 @@
|
||||
},
|
||||
"_collideBoxOpacity": 100,
|
||||
"_isCustomLabelActive": true,
|
||||
"customComponentName": "Hero",
|
||||
"_customComponentName": "Hero",
|
||||
"_customLabelString": "坐标:x,y\n角度:angle,弧度:radian\n世界坐标:wp\nhp:#hp mp:#mp\n#equip.shoe.attr.speed",
|
||||
"_customLabelOffset": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 150
|
||||
"y": 0
|
||||
},
|
||||
"_customLabelColor": {
|
||||
"__type__": "cc.Color",
|
||||
|
||||
@@ -87,8 +87,15 @@ export default class DataBoard extends cc.Component {
|
||||
this._isCustomLabelActive = value;
|
||||
this.customLabelNode.active = value;
|
||||
}
|
||||
@property
|
||||
private _customComponentName: string = '';
|
||||
@property({ displayName: CC_DEV && '······脚本', tooltip: CC_DEV && '监控哪个脚本', visible() { return this.isCustomLabelActive; } })
|
||||
private customComponentName: string = '';
|
||||
private get customComponentName() { return this._customComponentName };
|
||||
private set customComponentName(value: string) {
|
||||
this._customComponentName = value;
|
||||
value ||= this.node.name;
|
||||
value && (this.monitorComp = this.node.getComponent(value));
|
||||
}
|
||||
@property
|
||||
private _customLabelString: string = 'x,y';
|
||||
@property({ multiline: true, displayName: CC_DEV && '······参数', tooltip: CC_DEV && "—————支持的参数————\nwp:世界坐标\nradian:节点弧度(单位:π)\nmatrix:变换矩阵\n自身属性:x,y,parent,children等\n脚本属性:脚本实例对象的属性\n↓↓参数可以用3种分隔符隔开↓↓\n英文逗号、英文冒号、空格\n————举个栗子————\n脚本:Hero\n参数:wp,scale,angle,#angle,#hp\n显示结果:\n世界坐标,节点scale,节点angle,Hero对象的angle,Hero对象的hp\n————温馨提示————\n初始化的时候,设置全局变量\nwindow['DATABOARD'] = false\n可屏蔽本项目所有DataBoard,不会产生任何额外开销", visible() { return this.isCustomLabelActive } })
|
||||
@@ -96,7 +103,7 @@ export default class DataBoard extends cc.Component {
|
||||
private set customLabelString(value: string) {
|
||||
this._customLabelString = value;
|
||||
this.customLabelStringSplit = value
|
||||
.replace(/,|,/g, '_~_').replace(/:|:/g, '_!_').replace(/ /g, '_@_')
|
||||
.replace(/,/g, '_~_').replace(/:/g, '_!_').replace(/ /g, '_@_')
|
||||
.replace(/_*\n_*/g, '_\n_').split('_');
|
||||
}
|
||||
@property
|
||||
@@ -143,21 +150,20 @@ export default class DataBoard extends cc.Component {
|
||||
private monitorComp: cc.Component = null;
|
||||
|
||||
protected start() {
|
||||
this.boardNode = this.node.getChildByName('DataBoard');
|
||||
if (!CC_EDITOR && !window['DATABOARD']) {
|
||||
this.destroy();
|
||||
return;
|
||||
}
|
||||
this.boardNode = this.node.getChildByName('DataBoard');
|
||||
if (cc.isValid(this.boardNode)) {
|
||||
this.boardNode.removeFromParent();
|
||||
this.boardNode.destroy();
|
||||
this.boardNode.removeFromParent();
|
||||
}
|
||||
let texture = new cc.Texture2D();
|
||||
texture.initWithData(new Uint8Array([255, 255, 255]), cc.Texture2D.PixelFormat.RGB888, 1, 1);
|
||||
|
||||
this.boardNode = new cc.Node('DataBoard');
|
||||
this.boardNode.setParent(this.node);
|
||||
this.boardNode.x = this.boardNode.y = 0;
|
||||
this.boardNode.zIndex = cc.macro.MAX_ZINDEX;
|
||||
this.boardNode['_objFlags'] |= cc.Object['Flags'].HideInHierarchy;
|
||||
this.boardNode['_objFlags'] |= cc.Object['Flags'].LockedInEditor;
|
||||
@@ -193,6 +199,7 @@ export default class DataBoard extends cc.Component {
|
||||
this.customLabelNode.y = this.customLabelOffset.y;
|
||||
this.customLabelNode.color = this.customLabelColor;
|
||||
this.customLabelSize = this._customLabelSize;
|
||||
this.customComponentName = this._customComponentName;
|
||||
|
||||
this.updateAngle();
|
||||
this.updateScale();
|
||||
@@ -235,18 +242,8 @@ export default class DataBoard extends cc.Component {
|
||||
protected update() {
|
||||
if (!this.isCustomLabelActive) return;
|
||||
if (!this.customLabelStringSplit) return;
|
||||
if (this.customLabelOffset.x !== 0 || this.customLabelOffset.y !== 0) {
|
||||
let radian = -this.node.angle * Math.PI / 180;
|
||||
let cos = Math.cos(radian);
|
||||
let sin = Math.sin(radian);
|
||||
this.customLabelNode.x = this.customLabelOffset.x * cos - this.customLabelOffset.y * sin;
|
||||
this.customLabelNode.y = this.customLabelOffset.x * sin + this.customLabelOffset.y * cos;
|
||||
}
|
||||
let str = '';
|
||||
let strs = this.customLabelStringSplit;
|
||||
if (!this.monitorComp && this.customComponentName) {
|
||||
this.monitorComp = this.node.getComponent(this.customComponentName);
|
||||
}
|
||||
let str = '';
|
||||
for (let i = 0, len = strs.length; i < len; ++i) {
|
||||
let tmp = null;
|
||||
switch (strs[i]) {
|
||||
@@ -265,7 +262,7 @@ export default class DataBoard extends cc.Component {
|
||||
tmp = '';
|
||||
for (let i = 0; i < 4; ++i) {
|
||||
for (let j = 0; j < 4; ++j) {
|
||||
let m = matrix[j * 4 + i];
|
||||
let m = matrix[(j<<2) + i];
|
||||
tmp += (m < 0 ? '\t\t' : '\t\t\t') + m.toFixed(this.customLabelDigit);
|
||||
}
|
||||
i !== 3 && (tmp += '\n');
|
||||
@@ -303,11 +300,10 @@ export default class DataBoard extends cc.Component {
|
||||
|
||||
private parseString(str: string) {
|
||||
let strs = str.split('.');
|
||||
let ret = this.monitorComp[strs[0]];
|
||||
ret === undefined && (ret = `#${strs[0]}`);
|
||||
let ret = this.monitorComp[strs[0]] ?? `#${strs[0]}`;
|
||||
for (let i = 1, len = strs.length; i < len; ++i) {
|
||||
if (ret[strs[i]] === undefined) {
|
||||
return `${ret.name ? ret.name : ret}.${strs[i]}`;
|
||||
return `${ret.name ?? ret}.${strs[i]}`;
|
||||
}
|
||||
ret = ret[strs[i]];
|
||||
}
|
||||
@@ -316,8 +312,8 @@ export default class DataBoard extends cc.Component {
|
||||
|
||||
protected onDestroy() {
|
||||
if (cc.isValid(this.boardNode)) {
|
||||
this.boardNode.removeFromParent();
|
||||
this.boardNode.destroy();
|
||||
this.boardNode.removeFromParent();
|
||||
}
|
||||
this.node.targetOff(this);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user