feature/ads-smart-display
tiendat3699 2024-06-09 15:58:54 +07:00
parent 470d855cc2
commit 1f219422a3
3 changed files with 2 additions and 55 deletions

View File

@ -15,6 +15,7 @@ if (Editor) {
function gizmosUpdate() { function gizmosUpdate() {
if (!root) return; if (!root) return;
if (!w._componentsGizmos) return;
const selectedList: string[] = Editor.Selection.getSelected('node'); const selectedList: string[] = Editor.Selection.getSelected('node');
for (let i = 0; i < w._componentsGizmos.length; i++) { for (let i = 0; i < w._componentsGizmos.length; i++) {
const comps: Component[] = root.getComponentsInChildren(w._componentsGizmos[i]); const comps: Component[] = root.getComponentsInChildren(w._componentsGizmos[i]);

View File

@ -1,5 +1,4 @@
import { _decorator, CCObject, Color, Component, Graphics, IVec2Like, Layers, Node, toRadian, Vec3 } from 'cc'; import { _decorator, CCObject, Color, Component, Graphics, IVec2Like, Layers, Node, toRadian, Vec3 } from 'cc';
import { Editor } from './Define';
const { ccclass, executeInEditMode } = _decorator; const { ccclass, executeInEditMode } = _decorator;
@ -39,12 +38,8 @@ class GizmosDebugDraw extends Component {
private _color: Color = Gizmos2D.DEFAULT_COLOR; private _color: Color = Gizmos2D.DEFAULT_COLOR;
private _useLocalPosition: boolean = false; private _useLocalPosition: boolean = false;
private _layer: Layers.Enum = Gizmos2D.DEFAULT_LAYER; private _layer: Layers.Enum = Gizmos2D.DEFAULT_LAYER;
private _components: (new () => Component)[] = [];
protected update(dt: number): void { protected update(dt: number): void {
//only call in editor
this.callNodeDrawGizmos();
this._renderers.forEach((renderer) => { this._renderers.forEach((renderer) => {
renderer.clear(); renderer.clear();
renderer.draw(); renderer.draw();
@ -55,19 +50,6 @@ class GizmosDebugDraw extends Component {
this._layer = Gizmos2D.DEFAULT_LAYER; this._layer = Gizmos2D.DEFAULT_LAYER;
} }
private callNodeDrawGizmos() {
if (Editor) {
const selectedList: string[] = Editor.Selection.getSelected('node');
for (let i = 0; i < this._components.length; i++) {
const comp: Component = this.node.parent.getComponent(this._components[i]);
comp.onDrawGizmos?.();
if (selectedList.includes(this.node.parent.uuid)) {
comp.onDrawGizmosSelected?.();
}
}
}
}
private createRenderer(color: Color) { private createRenderer(color: Color) {
const hex = color.toHEX(); const hex = color.toHEX();
const g = new Node(`color ${hex}`).addComponent(Graphics); const g = new Node(`color ${hex}`).addComponent(Graphics);
@ -96,10 +78,6 @@ class GizmosDebugDraw extends Component {
return local; return local;
} }
public registerDrawGizmos(component: new () => Component) {
this._components.push(component);
}
public setColor(color: Color) { public setColor(color: Color) {
this._color = color; this._color = color;
} }
@ -112,10 +90,6 @@ class GizmosDebugDraw extends Component {
this._layer = layer; this._layer = layer;
} }
public clearAll() {
this._renderers.forEach((renderer) => renderer.clear());
}
public drawLine(point1: IVec2Like, point2: IVec2Like) { public drawLine(point1: IVec2Like, point2: IVec2Like) {
const color = this._color.clone(); const color = this._color.clone();
const renderer = this.getRenderer(color); const renderer = this.getRenderer(color);
@ -317,10 +291,6 @@ export default class Gizmos2D {
return debugNode; return debugNode;
} }
public static registerDrawGizmos(node: Node, component: new () => Component) {
this.getDebugNode(node).registerDrawGizmos(component);
}
public static beginColor(node: Node, color: Color) { public static beginColor(node: Node, color: Color) {
this.getDebugNode(node).setColor(color); this.getDebugNode(node).setColor(color);
} }
@ -337,10 +307,6 @@ export default class Gizmos2D {
this.getDebugNode(node).setLayer(layer); this.getDebugNode(node).setLayer(layer);
} }
public static clearAll(node: Node) {
this.getDebugNode(node).clearAll();
}
public static drawLine(node: Node, point1: IVec2Like, point2: IVec2Like) { public static drawLine(node: Node, point1: IVec2Like, point2: IVec2Like) {
const debugNode = this.getDebugNode(node); const debugNode = this.getDebugNode(node);
debugNode.drawLine(point1, point2); debugNode.drawLine(point1, point2);

View File

@ -15,7 +15,7 @@ import {
toRadian, toRadian,
Vec3, Vec3,
} from 'cc'; } from 'cc';
import { cce, Editor } from './Define'; import { cce } from './Define';
const { ccclass, executeInEditMode } = _decorator; const { ccclass, executeInEditMode } = _decorator;
@ -46,26 +46,10 @@ class GizmosDebugDraw extends Component {
} }
protected update(dt: number): void { protected update(dt: number): void {
//only call in editor
this.callNodeDrawGizmos();
this._color = Gizmos3D.DEFAULT_COLOR; this._color = Gizmos3D.DEFAULT_COLOR;
this._useLocalPosition = false; this._useLocalPosition = false;
} }
private callNodeDrawGizmos() {
if (Editor) {
const selectedList: string[] = Editor.Selection.getSelected('node');
for (let i = 0; i < this._components.length; i++) {
const comp: Component = this.node.parent.getComponent(this._components[i]);
comp.onDrawGizmos?.();
if (selectedList.includes(this.node.parent.uuid)) {
comp.onDrawGizmosSelected?.();
}
}
}
}
private worldToLocal(world: Vec3): Vec3 { private worldToLocal(world: Vec3): Vec3 {
const local = new Vec3(); const local = new Vec3();
Vec3.add(local, this.node.worldPosition, world); Vec3.add(local, this.node.worldPosition, world);
@ -395,10 +379,6 @@ export default class Gizmos3D {
return debugNode; return debugNode;
} }
public static registerDrawGizmos(node: Node, component: new () => Component) {
this.getDebugNode(node).registerDrawGizmos(component);
}
public static beginColor(node: Node, color: Color) { public static beginColor(node: Node, color: Color) {
this.getDebugNode(node)?.setColor(color); this.getDebugNode(node)?.setColor(color);
} }