diff --git a/assets/_Game/Scripts/Gizmos/ExecuteGizmos.ts b/assets/_Game/Scripts/Gizmos/ExecuteGizmos.ts index c9177eb..794d901 100644 --- a/assets/_Game/Scripts/Gizmos/ExecuteGizmos.ts +++ b/assets/_Game/Scripts/Gizmos/ExecuteGizmos.ts @@ -15,6 +15,7 @@ if (Editor) { function gizmosUpdate() { if (!root) return; + if (!w._componentsGizmos) return; const selectedList: string[] = Editor.Selection.getSelected('node'); for (let i = 0; i < w._componentsGizmos.length; i++) { const comps: Component[] = root.getComponentsInChildren(w._componentsGizmos[i]); diff --git a/assets/_Game/Scripts/Gizmos/Gizmos2D.ts b/assets/_Game/Scripts/Gizmos/Gizmos2D.ts index b5c9cc1..30ed477 100644 --- a/assets/_Game/Scripts/Gizmos/Gizmos2D.ts +++ b/assets/_Game/Scripts/Gizmos/Gizmos2D.ts @@ -1,5 +1,4 @@ import { _decorator, CCObject, Color, Component, Graphics, IVec2Like, Layers, Node, toRadian, Vec3 } from 'cc'; -import { Editor } from './Define'; const { ccclass, executeInEditMode } = _decorator; @@ -39,12 +38,8 @@ class GizmosDebugDraw extends Component { private _color: Color = Gizmos2D.DEFAULT_COLOR; private _useLocalPosition: boolean = false; private _layer: Layers.Enum = Gizmos2D.DEFAULT_LAYER; - private _components: (new () => Component)[] = []; protected update(dt: number): void { - //only call in editor - this.callNodeDrawGizmos(); - this._renderers.forEach((renderer) => { renderer.clear(); renderer.draw(); @@ -55,19 +50,6 @@ class GizmosDebugDraw extends Component { 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) { const hex = color.toHEX(); const g = new Node(`color ${hex}`).addComponent(Graphics); @@ -96,10 +78,6 @@ class GizmosDebugDraw extends Component { return local; } - public registerDrawGizmos(component: new () => Component) { - this._components.push(component); - } - public setColor(color: Color) { this._color = color; } @@ -112,10 +90,6 @@ class GizmosDebugDraw extends Component { this._layer = layer; } - public clearAll() { - this._renderers.forEach((renderer) => renderer.clear()); - } - public drawLine(point1: IVec2Like, point2: IVec2Like) { const color = this._color.clone(); const renderer = this.getRenderer(color); @@ -317,10 +291,6 @@ export default class Gizmos2D { return debugNode; } - public static registerDrawGizmos(node: Node, component: new () => Component) { - this.getDebugNode(node).registerDrawGizmos(component); - } - public static beginColor(node: Node, color: Color) { this.getDebugNode(node).setColor(color); } @@ -337,10 +307,6 @@ export default class Gizmos2D { this.getDebugNode(node).setLayer(layer); } - public static clearAll(node: Node) { - this.getDebugNode(node).clearAll(); - } - public static drawLine(node: Node, point1: IVec2Like, point2: IVec2Like) { const debugNode = this.getDebugNode(node); debugNode.drawLine(point1, point2); diff --git a/assets/_Game/Scripts/Gizmos/Gizmos3D.ts b/assets/_Game/Scripts/Gizmos/Gizmos3D.ts index 3e87858..d0d493a 100644 --- a/assets/_Game/Scripts/Gizmos/Gizmos3D.ts +++ b/assets/_Game/Scripts/Gizmos/Gizmos3D.ts @@ -15,7 +15,7 @@ import { toRadian, Vec3, } from 'cc'; -import { cce, Editor } from './Define'; +import { cce } from './Define'; const { ccclass, executeInEditMode } = _decorator; @@ -46,26 +46,10 @@ class GizmosDebugDraw extends Component { } protected update(dt: number): void { - //only call in editor - this.callNodeDrawGizmos(); - this._color = Gizmos3D.DEFAULT_COLOR; 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 { const local = new Vec3(); Vec3.add(local, this.node.worldPosition, world); @@ -395,10 +379,6 @@ export default class Gizmos3D { return debugNode; } - public static registerDrawGizmos(node: Node, component: new () => Component) { - this.getDebugNode(node).registerDrawGizmos(component); - } - public static beginColor(node: Node, color: Color) { this.getDebugNode(node)?.setColor(color); }