feat: update gizmos update, add gizmos decorator
parent
ebf7f54603
commit
df4b171235
File diff suppressed because it is too large
Load Diff
|
@ -21,15 +21,12 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"__id__": 238
|
"__id__": 238
|
||||||
},
|
|
||||||
{
|
|
||||||
"__id__": 1222
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"_active": true,
|
"_active": true,
|
||||||
"_components": [],
|
"_components": [],
|
||||||
"_prefab": {
|
"_prefab": {
|
||||||
"__id__": 1224
|
"__id__": 1222
|
||||||
},
|
},
|
||||||
"_lpos": {
|
"_lpos": {
|
||||||
"__type__": "cc.Vec3",
|
"__type__": "cc.Vec3",
|
||||||
|
@ -60,7 +57,7 @@
|
||||||
},
|
},
|
||||||
"autoReleaseAssets": false,
|
"autoReleaseAssets": false,
|
||||||
"_globals": {
|
"_globals": {
|
||||||
"__id__": 1235
|
"__id__": 1233
|
||||||
},
|
},
|
||||||
"_id": "aa17106a-0b45-4280-a91c-9650d0c417b3"
|
"_id": "aa17106a-0b45-4280-a91c-9650d0c417b3"
|
||||||
},
|
},
|
||||||
|
@ -33457,67 +33454,6 @@
|
||||||
"_lockFlags": 0,
|
"_lockFlags": 0,
|
||||||
"_id": "c5V1EV8IpMtrIvY1OE9t2u"
|
"_id": "c5V1EV8IpMtrIvY1OE9t2u"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"__type__": "cc.Node",
|
|
||||||
"_name": "DynamicSpriteManager",
|
|
||||||
"_objFlags": 0,
|
|
||||||
"__editorExtras__": {},
|
|
||||||
"_parent": {
|
|
||||||
"__id__": 1
|
|
||||||
},
|
|
||||||
"_children": [],
|
|
||||||
"_active": true,
|
|
||||||
"_components": [
|
|
||||||
{
|
|
||||||
"__id__": 1223
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"_prefab": null,
|
|
||||||
"_lpos": {
|
|
||||||
"__type__": "cc.Vec3",
|
|
||||||
"x": 0,
|
|
||||||
"y": 0,
|
|
||||||
"z": 0
|
|
||||||
},
|
|
||||||
"_lrot": {
|
|
||||||
"__type__": "cc.Quat",
|
|
||||||
"x": 0,
|
|
||||||
"y": 0,
|
|
||||||
"z": 0,
|
|
||||||
"w": 1
|
|
||||||
},
|
|
||||||
"_lscale": {
|
|
||||||
"__type__": "cc.Vec3",
|
|
||||||
"x": 1,
|
|
||||||
"y": 1,
|
|
||||||
"z": 1
|
|
||||||
},
|
|
||||||
"_mobility": 0,
|
|
||||||
"_layer": 1073741824,
|
|
||||||
"_euler": {
|
|
||||||
"__type__": "cc.Vec3",
|
|
||||||
"x": 0,
|
|
||||||
"y": 0,
|
|
||||||
"z": 0
|
|
||||||
},
|
|
||||||
"_id": "6eV5d5gEhCDK07B8AMhhT3"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"__type__": "0276bwITM9AF7FAz3oRVNTX",
|
|
||||||
"_name": "",
|
|
||||||
"_objFlags": 0,
|
|
||||||
"__editorExtras__": {},
|
|
||||||
"node": {
|
|
||||||
"__id__": 1222
|
|
||||||
},
|
|
||||||
"_enabled": true,
|
|
||||||
"__prefab": null,
|
|
||||||
"jsonConfig": {
|
|
||||||
"__uuid__": "d3d19129-bf34-488d-9d39-737eced907ae",
|
|
||||||
"__expectedType__": "cc.JsonAsset"
|
|
||||||
},
|
|
||||||
"_id": "bbRzA428dJlYlzjSjK9Mar"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"__type__": "cc.PrefabInfo",
|
"__type__": "cc.PrefabInfo",
|
||||||
"root": null,
|
"root": null,
|
||||||
|
@ -33526,16 +33462,16 @@
|
||||||
"instance": null,
|
"instance": null,
|
||||||
"targetOverrides": [
|
"targetOverrides": [
|
||||||
{
|
{
|
||||||
"__id__": 1225
|
"__id__": 1223
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__id__": 1226
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"__id__": 1228
|
"__id__": 1228
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"__id__": 1230
|
"__id__": 1231
|
||||||
},
|
|
||||||
{
|
|
||||||
"__id__": 1233
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"nestedPrefabInstanceRoots": [
|
"nestedPrefabInstanceRoots": [
|
||||||
|
@ -33559,7 +33495,7 @@
|
||||||
"__id__": 177
|
"__id__": 177
|
||||||
},
|
},
|
||||||
"sourceInfo": {
|
"sourceInfo": {
|
||||||
"__id__": 1226
|
"__id__": 1224
|
||||||
},
|
},
|
||||||
"propertyPath": [
|
"propertyPath": [
|
||||||
"_trailModule",
|
"_trailModule",
|
||||||
|
@ -33569,7 +33505,7 @@
|
||||||
"__id__": 177
|
"__id__": 177
|
||||||
},
|
},
|
||||||
"targetInfo": {
|
"targetInfo": {
|
||||||
"__id__": 1227
|
"__id__": 1225
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -33597,7 +33533,7 @@
|
||||||
"__id__": 239
|
"__id__": 239
|
||||||
},
|
},
|
||||||
"targetInfo": {
|
"targetInfo": {
|
||||||
"__id__": 1229
|
"__id__": 1227
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -33612,7 +33548,7 @@
|
||||||
"__id__": 158
|
"__id__": 158
|
||||||
},
|
},
|
||||||
"sourceInfo": {
|
"sourceInfo": {
|
||||||
"__id__": 1231
|
"__id__": 1229
|
||||||
},
|
},
|
||||||
"propertyPath": [
|
"propertyPath": [
|
||||||
"_trailModule",
|
"_trailModule",
|
||||||
|
@ -33622,7 +33558,7 @@
|
||||||
"__id__": 158
|
"__id__": 158
|
||||||
},
|
},
|
||||||
"targetInfo": {
|
"targetInfo": {
|
||||||
"__id__": 1232
|
"__id__": 1230
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -33650,7 +33586,7 @@
|
||||||
"__id__": 470
|
"__id__": 470
|
||||||
},
|
},
|
||||||
"targetInfo": {
|
"targetInfo": {
|
||||||
"__id__": 1234
|
"__id__": 1232
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -33662,28 +33598,28 @@
|
||||||
{
|
{
|
||||||
"__type__": "cc.SceneGlobals",
|
"__type__": "cc.SceneGlobals",
|
||||||
"ambient": {
|
"ambient": {
|
||||||
"__id__": 1236
|
"__id__": 1234
|
||||||
},
|
},
|
||||||
"shadows": {
|
"shadows": {
|
||||||
"__id__": 1237
|
"__id__": 1235
|
||||||
},
|
},
|
||||||
"_skybox": {
|
"_skybox": {
|
||||||
"__id__": 1238
|
"__id__": 1236
|
||||||
},
|
},
|
||||||
"fog": {
|
"fog": {
|
||||||
"__id__": 1239
|
"__id__": 1237
|
||||||
},
|
},
|
||||||
"octree": {
|
"octree": {
|
||||||
"__id__": 1240
|
"__id__": 1238
|
||||||
},
|
},
|
||||||
"skin": {
|
"skin": {
|
||||||
"__id__": 1241
|
"__id__": 1239
|
||||||
},
|
},
|
||||||
"lightProbeInfo": {
|
"lightProbeInfo": {
|
||||||
"__id__": 1242
|
"__id__": 1240
|
||||||
},
|
},
|
||||||
"postSettings": {
|
"postSettings": {
|
||||||
"__id__": 1243
|
"__id__": 1241
|
||||||
},
|
},
|
||||||
"bakedWithStationaryMainLight": false,
|
"bakedWithStationaryMainLight": false,
|
||||||
"bakedWithHighpLightmap": false
|
"bakedWithHighpLightmap": false
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -18,11 +18,13 @@ import {
|
||||||
import GameState from '../Enum/GameState';
|
import GameState from '../Enum/GameState';
|
||||||
import ScoreType from '../Enum/ScoreType';
|
import ScoreType from '../Enum/ScoreType';
|
||||||
import GameEvent from '../Events/GameEvent';
|
import GameEvent from '../Events/GameEvent';
|
||||||
|
import { registerGizmo } from '../Gizmos/Decorator';
|
||||||
import Gizmos2D from '../Gizmos/Gizmos2D';
|
import Gizmos2D from '../Gizmos/Gizmos2D';
|
||||||
import AudioManager from '../Manager/AudioManager';
|
import AudioManager from '../Manager/AudioManager';
|
||||||
import { EventManger } from '../Manager/EventManger';
|
import { EventManger } from '../Manager/EventManger';
|
||||||
const { ccclass, property } = _decorator;
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
|
@registerGizmo
|
||||||
@ccclass('Enemy')
|
@ccclass('Enemy')
|
||||||
export class Enemy extends Component {
|
export class Enemy extends Component {
|
||||||
@property({ type: Collider2D, visible: true })
|
@property({ type: Collider2D, visible: true })
|
||||||
|
|
|
@ -10,10 +10,13 @@ import {
|
||||||
PolygonCollider2D,
|
PolygonCollider2D,
|
||||||
Prefab,
|
Prefab,
|
||||||
Vec2,
|
Vec2,
|
||||||
|
Vec3,
|
||||||
} from 'cc';
|
} from 'cc';
|
||||||
import TimeConfig from '../Enum/TimeConfig';
|
import TimeConfig from '../Enum/TimeConfig';
|
||||||
import { CameraController } from '../Environments/CameraController';
|
import { CameraController } from '../Environments/CameraController';
|
||||||
|
import { registerGizmo } from '../Gizmos/Decorator';
|
||||||
import Gizmos2D from '../Gizmos/Gizmos2D';
|
import Gizmos2D from '../Gizmos/Gizmos2D';
|
||||||
|
import Gizmos3D from '../Gizmos/Gizmos3D';
|
||||||
import AudioManager from '../Manager/AudioManager';
|
import AudioManager from '../Manager/AudioManager';
|
||||||
import { GameManager } from '../Manager/GameManager';
|
import { GameManager } from '../Manager/GameManager';
|
||||||
import ObjectPool from '../Pool/ObjectPool';
|
import ObjectPool from '../Pool/ObjectPool';
|
||||||
|
@ -21,6 +24,7 @@ import Utilities from '../Utilities';
|
||||||
import { Ball } from './Ball';
|
import { Ball } from './Ball';
|
||||||
const { ccclass, property } = _decorator;
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
|
@registerGizmo
|
||||||
@ccclass('MultiBall')
|
@ccclass('MultiBall')
|
||||||
export class MultiBall extends Component {
|
export class MultiBall extends Component {
|
||||||
@property({ type: Collider2D, visible: true })
|
@property({ type: Collider2D, visible: true })
|
||||||
|
@ -39,11 +43,9 @@ export class MultiBall extends Component {
|
||||||
private _trigged = false;
|
private _trigged = false;
|
||||||
private _fxPool: ObjectPool;
|
private _fxPool: ObjectPool;
|
||||||
|
|
||||||
private _enabled: boolean = true;
|
private _colliderEnabled: boolean = true;
|
||||||
|
|
||||||
onDrawGizmos(): void {}
|
onDrawGizmos(): void {
|
||||||
|
|
||||||
onDrawGizmosSelected(): void {
|
|
||||||
Gizmos2D.beginColor(this.node, new Color(0, 255, 0, 150));
|
Gizmos2D.beginColor(this.node, new Color(0, 255, 0, 150));
|
||||||
const points = (this._collider as PolygonCollider2D).points.map((p) => p.clone().add(this._collider.offset));
|
const points = (this._collider as PolygonCollider2D).points.map((p) => p.clone().add(this._collider.offset));
|
||||||
Gizmos2D.beginLocalPosition(this.node);
|
Gizmos2D.beginLocalPosition(this.node);
|
||||||
|
@ -80,9 +82,9 @@ export class MultiBall extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async onBeginContact(selfCollider: Collider2D, otherCollider: Collider2D) {
|
private async onBeginContact(selfCollider: Collider2D, otherCollider: Collider2D) {
|
||||||
if (!this._enabled) return;
|
if (!this._colliderEnabled) return;
|
||||||
if (this._trigged) return;
|
if (this._trigged) return;
|
||||||
this._enabled = false;
|
this._colliderEnabled = false;
|
||||||
this._originBall = otherCollider.getComponent(Ball);
|
this._originBall = otherCollider.getComponent(Ball);
|
||||||
this._trigged = true;
|
this._trigged = true;
|
||||||
const fx = this._fxPool.get(ParticleSystem, GameManager.instance.topContainer);
|
const fx = this._fxPool.get(ParticleSystem, GameManager.instance.topContainer);
|
||||||
|
@ -91,7 +93,7 @@ export class MultiBall extends Component {
|
||||||
fx.node.setWorldPosition(pos);
|
fx.node.setWorldPosition(pos);
|
||||||
AudioManager.playSfx(this._soundFX);
|
AudioManager.playSfx(this._soundFX);
|
||||||
await Utilities.delay(TimeConfig.DelayMultiBall);
|
await Utilities.delay(TimeConfig.DelayMultiBall);
|
||||||
this._enabled = true;
|
this._colliderEnabled = true;
|
||||||
await Utilities.waitUntil(() => fx.isStopped);
|
await Utilities.waitUntil(() => fx.isStopped);
|
||||||
this._fxPool.release(fx);
|
this._fxPool.release(fx);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
import { Component, director, Director, Node } from 'cc';
|
||||||
|
|
||||||
|
export function registerGizmo(constructor: new () => Component) {
|
||||||
|
const w = window as any;
|
||||||
|
if (!w._componentsGizmos) w._componentsGizmos = [];
|
||||||
|
if (w._componentsGizmos.includes(constructor)) return;
|
||||||
|
w._componentsGizmos.push(constructor);
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"ver": "4.0.23",
|
||||||
|
"importer": "typescript",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "deaa66db-9645-4a7d-b602-2d7290360927",
|
||||||
|
"files": [],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {}
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
import { Component, director, Director } from 'cc';
|
||||||
|
import { Editor } from './Define';
|
||||||
|
|
||||||
|
if (Editor) {
|
||||||
|
let root = director.getScene();
|
||||||
|
const w = window as any;
|
||||||
|
|
||||||
|
if (!sessionStorage.getItem('gizmosUpdating')) {
|
||||||
|
sessionStorage.setItem('gizmosUpdating', 'true');
|
||||||
|
director.on(Director.EVENT_BEFORE_UPDATE, gizmosUpdate);
|
||||||
|
director.on(Director.EVENT_AFTER_SCENE_LAUNCH, () => {
|
||||||
|
root = director.getScene();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function gizmosUpdate() {
|
||||||
|
if (!root) 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]);
|
||||||
|
comps.forEach((comp) => {
|
||||||
|
comp.onDrawGizmos?.();
|
||||||
|
if (selectedList.includes(comp.node.uuid)) {
|
||||||
|
comp.onDrawGizmosSelected?.();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"ver": "4.0.23",
|
||||||
|
"importer": "typescript",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "c2fbcc4f-a652-4736-82cb-64f9829b68f2",
|
||||||
|
"files": [],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {}
|
||||||
|
}
|
|
@ -1,3 +1,6 @@
|
||||||
|
import { NodeActivator } from 'cc';
|
||||||
|
import { EDITOR } from 'cc/env';
|
||||||
|
|
||||||
declare module 'cc' {
|
declare module 'cc' {
|
||||||
interface Component {
|
interface Component {
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -39,8 +39,12 @@ 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();
|
||||||
|
@ -51,6 +55,19 @@ 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);
|
||||||
|
@ -79,6 +96,10 @@ 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;
|
||||||
}
|
}
|
||||||
|
@ -293,10 +314,13 @@ export default class Gizmos2D {
|
||||||
debugNode.node.hideFlags |= CCObject.Flags.DontSave | CCObject.Flags.HideInHierarchy;
|
debugNode.node.hideFlags |= CCObject.Flags.DontSave | CCObject.Flags.HideInHierarchy;
|
||||||
debugNode.node.parent = node;
|
debugNode.node.parent = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,40 +17,16 @@ import {
|
||||||
} from 'cc';
|
} from 'cc';
|
||||||
import { cce, Editor } from './Define';
|
import { cce, Editor } from './Define';
|
||||||
|
|
||||||
const { ccclass, executeInEditMode, property } = _decorator;
|
const { ccclass, executeInEditMode } = _decorator;
|
||||||
|
|
||||||
class GizmosRenderer {
|
|
||||||
private _geometryRenderer;
|
|
||||||
private _drawCalls: ((geometry) => void)[] = [];
|
|
||||||
|
|
||||||
constructor(geometryRenderer: GeometryRenderer) {
|
|
||||||
this._geometryRenderer = geometryRenderer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public addDrawCall(drawCall: (geometry: GeometryRenderer) => void) {
|
|
||||||
this._drawCalls.push(drawCall);
|
|
||||||
}
|
|
||||||
|
|
||||||
public clear() {
|
|
||||||
this._drawCalls = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
public draw() {
|
|
||||||
this._drawCalls.forEach((drawCall) => {
|
|
||||||
drawCall(this._geometryRenderer);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ccclass('Gizmos3D.GizmosDebugDraw')
|
@ccclass('Gizmos3D.GizmosDebugDraw')
|
||||||
@executeInEditMode
|
@executeInEditMode
|
||||||
class GizmosDebugDraw extends Component {
|
class GizmosDebugDraw extends Component {
|
||||||
private _renderers: Map<string, GizmosRenderer> = new Map();
|
|
||||||
private _color: Color = Gizmos3D.DEFAULT_COLOR;
|
private _color: Color = Gizmos3D.DEFAULT_COLOR;
|
||||||
private _renderer: GeometryRenderer = null;
|
private _renderer: GeometryRenderer = null;
|
||||||
private _depthTest: boolean = false;
|
private _depthTest: boolean = true;
|
||||||
private _useLocalPosition: boolean = false;
|
private _useLocalPosition: boolean = false;
|
||||||
private _parentNode: Node;
|
private _components: (new () => Component)[] = [];
|
||||||
|
|
||||||
protected onLoad(): void {
|
protected onLoad(): void {
|
||||||
if (cce) {
|
if (cce) {
|
||||||
|
@ -73,57 +49,37 @@ class GizmosDebugDraw extends Component {
|
||||||
//only call in editor
|
//only call in editor
|
||||||
this.callNodeDrawGizmos();
|
this.callNodeDrawGizmos();
|
||||||
|
|
||||||
this._renderers.forEach((renderer) => {
|
|
||||||
renderer.draw();
|
|
||||||
renderer.clear();
|
|
||||||
});
|
|
||||||
|
|
||||||
this._color = Gizmos3D.DEFAULT_COLOR;
|
this._color = Gizmos3D.DEFAULT_COLOR;
|
||||||
this._useLocalPosition = false;
|
this._useLocalPosition = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private callNodeDrawGizmos() {
|
private callNodeDrawGizmos() {
|
||||||
if (Editor && this._parentNode) {
|
if (Editor) {
|
||||||
const selectedList: string[] = Editor.Selection.getSelected('node');
|
const selectedList: string[] = Editor.Selection.getSelected('node');
|
||||||
if (selectedList.includes(this._parentNode.uuid)) {
|
for (let i = 0; i < this._components.length; i++) {
|
||||||
const comps = this._parentNode.components;
|
const comp: Component = this.node.parent.getComponent(this._components[i]);
|
||||||
for (let i = 0; i < comps.length; i++) {
|
comp.onDrawGizmos?.();
|
||||||
const comp: Component = comps[i];
|
if (selectedList.includes(this.node.parent.uuid)) {
|
||||||
comp.onDrawGizmos?.();
|
comp.onDrawGizmosSelected?.();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private createRenderer(color: Color) {
|
|
||||||
const renderer = new GizmosRenderer(this._renderer);
|
|
||||||
return renderer;
|
|
||||||
}
|
|
||||||
|
|
||||||
private getRenderer(color: Color): GizmosRenderer {
|
|
||||||
const hex = color.toHEX();
|
|
||||||
let renderer = this._renderers.get(hex);
|
|
||||||
if (!renderer) {
|
|
||||||
renderer = this.createRenderer(color);
|
|
||||||
this._renderers.set(hex, renderer);
|
|
||||||
}
|
|
||||||
return renderer;
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
||||||
return local;
|
return local;
|
||||||
}
|
}
|
||||||
|
|
||||||
public registerDrawGizmos(node: Node) {
|
|
||||||
this._parentNode = node;
|
|
||||||
}
|
|
||||||
|
|
||||||
public setDepthTest(value: boolean) {
|
public setDepthTest(value: boolean) {
|
||||||
this._depthTest = value;
|
this._depthTest = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public registerDrawGizmos(component: new () => Component) {
|
||||||
|
this._components.push(component);
|
||||||
|
}
|
||||||
|
|
||||||
public setColor(color: Color) {
|
public setColor(color: Color) {
|
||||||
this._color = color;
|
this._color = color;
|
||||||
}
|
}
|
||||||
|
@ -132,10 +88,6 @@ class GizmosDebugDraw extends Component {
|
||||||
this._useLocalPosition = value;
|
this._useLocalPosition = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public clearAll() {
|
|
||||||
this._renderers.forEach((renderer) => renderer.clear());
|
|
||||||
}
|
|
||||||
|
|
||||||
private rotate(pos: Vec3, rot: Vec3 = Vec3.ZERO): Mat4 {
|
private rotate(pos: Vec3, rot: Vec3 = Vec3.ZERO): Mat4 {
|
||||||
let result = new Mat4();
|
let result = new Mat4();
|
||||||
let transform = new Mat4();
|
let transform = new Mat4();
|
||||||
|
@ -159,107 +111,99 @@ class GizmosDebugDraw extends Component {
|
||||||
|
|
||||||
public drawLine(point1: Vec3, point2: Vec3) {
|
public drawLine(point1: Vec3, point2: Vec3) {
|
||||||
const color = this._color.clone();
|
const color = this._color.clone();
|
||||||
const renderer = this.getRenderer(color);
|
|
||||||
const p1 = this._useLocalPosition ? this.worldToLocal(point1) : point1;
|
const p1 = this._useLocalPosition ? this.worldToLocal(point1) : point1;
|
||||||
const p2 = this._useLocalPosition ? this.worldToLocal(point2) : point2;
|
const p2 = this._useLocalPosition ? this.worldToLocal(point2) : point2;
|
||||||
renderer.addDrawCall((geometry) => {
|
this._renderer?.addLine(p1, p2, color, this._depthTest);
|
||||||
geometry?.addLine(p1, p2, color, this._depthTest);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public drawLineList(points: Vec3[], close: boolean = false) {
|
public drawLineList(points: Vec3[], close: boolean = false) {
|
||||||
const color = this._color.clone();
|
const color = this._color.clone();
|
||||||
const renderer = this.getRenderer(color);
|
|
||||||
const pointList = this._useLocalPosition ? points.map((p) => this.worldToLocal(p)) : points;
|
const pointList = this._useLocalPosition ? points.map((p) => this.worldToLocal(p)) : points;
|
||||||
renderer.addDrawCall((geometry) => {
|
if (pointList.length > 0) {
|
||||||
if (pointList.length > 0) {
|
for (let i = 0; i < pointList.length - 1; i++) {
|
||||||
for (let i = 0; i < pointList.length - 1; i++) {
|
this._renderer?.addLine(pointList[i], pointList[i + 1], color, this._depthTest);
|
||||||
geometry?.addLine(pointList[i], pointList[i + 1], color, this._depthTest);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (close) {
|
|
||||||
geometry?.addLine(pointList[pointList.length - 1], pointList[0], color, this._depthTest);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
if (close) {
|
||||||
|
this._renderer?.addLine(pointList[pointList.length - 1], pointList[0], color, this._depthTest);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public drawDashLine(point1: Vec3, point2: Vec3) {
|
public drawDashLine(point1: Vec3, point2: Vec3) {
|
||||||
const color = this._color.clone();
|
const color = this._color.clone();
|
||||||
const renderer = this.getRenderer(color);
|
|
||||||
const p1 = this._useLocalPosition ? this.worldToLocal(point1) : point1;
|
const p1 = this._useLocalPosition ? this.worldToLocal(point1) : point1;
|
||||||
const p2 = this._useLocalPosition ? this.worldToLocal(point2) : point2;
|
const p2 = this._useLocalPosition ? this.worldToLocal(point2) : point2;
|
||||||
renderer.addDrawCall((geometry) => {
|
this._renderer?.addDashedLine(p1, p2, color, this._depthTest);
|
||||||
geometry?.addDashedLine(p1, p2, color, this._depthTest);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public drawDashLineList(points: Vec3[], close: boolean = false) {
|
public drawDashLineList(points: Vec3[], close: boolean = false) {
|
||||||
const color = this._color.clone();
|
const color = this._color.clone();
|
||||||
const renderer = this.getRenderer(color);
|
|
||||||
const pointList = this._useLocalPosition ? points.map((p) => this.worldToLocal(p)) : points;
|
const pointList = this._useLocalPosition ? points.map((p) => this.worldToLocal(p)) : points;
|
||||||
renderer.addDrawCall((geometry) => {
|
if (pointList.length > 0) {
|
||||||
if (pointList.length > 0) {
|
for (let i = 0; i < pointList.length - 1; i++) {
|
||||||
for (let i = 0; i < pointList.length - 1; i++) {
|
this._renderer?.addDashedLine(pointList[i], pointList[i + 1], color, this._depthTest);
|
||||||
geometry?.addDashedLine(pointList[i], pointList[i + 1], color, this._depthTest);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (close) {
|
|
||||||
geometry?.addDashedLine(pointList[pointList.length - 1], pointList[0], color, this._depthTest);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
if (close) {
|
||||||
|
this._renderer?.addDashedLine(pointList[pointList.length - 1], pointList[0], color, this._depthTest);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public drawCircle(center: Vec3, radius: number, rot: Vec3 = Vec3.ZERO) {
|
public drawCircle(center: Vec3, radius: number, rot: Vec3 = Vec3.ZERO, segments: number = 32) {
|
||||||
const color = this._color.clone();
|
const color = this._color.clone();
|
||||||
const renderer = this.getRenderer(color);
|
|
||||||
const c = this._useLocalPosition ? this.worldToLocal(center) : center;
|
const c = this._useLocalPosition ? this.worldToLocal(center) : center;
|
||||||
const transform = this.rotate(c, rot);
|
const transform = this.rotate(c, rot);
|
||||||
renderer.addDrawCall((geometry) => {
|
this._renderer?.addCircle(c, radius, color, segments, this._depthTest, true, transform);
|
||||||
geometry?.addCircle(c, radius, color, 32, this._depthTest, true, transform);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public drawDisc(center: Vec3, radius: number, rot: Vec3 = Vec3.ZERO, wireFrame: boolean = false) {
|
public drawDisc(
|
||||||
|
center: Vec3,
|
||||||
|
radius: number,
|
||||||
|
rot: Vec3 = Vec3.ZERO,
|
||||||
|
wireFrame: boolean = false,
|
||||||
|
segments: number = 32,
|
||||||
|
) {
|
||||||
const color = this._color.clone();
|
const color = this._color.clone();
|
||||||
const renderer = this.getRenderer(color);
|
|
||||||
const c = this._useLocalPosition ? this.worldToLocal(center) : center;
|
const c = this._useLocalPosition ? this.worldToLocal(center) : center;
|
||||||
const transform = this.rotate(c, rot);
|
const transform = this.rotate(c, rot);
|
||||||
renderer.addDrawCall((geometry) => {
|
this._renderer?.addDisc(c, radius, color, segments, wireFrame, this._depthTest, true, true, transform);
|
||||||
geometry?.addDisc(c, radius, color, 32, wireFrame, this._depthTest, true, true, transform);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public drawQuad(point1: Vec3, point2: Vec3, point3: Vec3, point4: Vec3, wireFrame: boolean = false) {
|
public drawQuad(point1: Vec3, point2: Vec3, point3: Vec3, point4: Vec3, wireFrame: boolean = false) {
|
||||||
const color = this._color.clone();
|
const color = this._color.clone();
|
||||||
const renderer = this.getRenderer(color);
|
|
||||||
const p1 = this._useLocalPosition ? this.worldToLocal(point1) : point1;
|
const p1 = this._useLocalPosition ? this.worldToLocal(point1) : point1;
|
||||||
const p2 = this._useLocalPosition ? this.worldToLocal(point2) : point2;
|
const p2 = this._useLocalPosition ? this.worldToLocal(point2) : point2;
|
||||||
const p3 = this._useLocalPosition ? this.worldToLocal(point3) : point3;
|
const p3 = this._useLocalPosition ? this.worldToLocal(point3) : point3;
|
||||||
const p4 = this._useLocalPosition ? this.worldToLocal(point4) : point4;
|
const p4 = this._useLocalPosition ? this.worldToLocal(point4) : point4;
|
||||||
renderer.addDrawCall((geometry) => {
|
this._renderer?.addQuad(p1, p2, p3, p4, color, wireFrame, this._depthTest);
|
||||||
geometry?.addQuad(p1, p2, p3, p4, color, wireFrame, this._depthTest);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public drawSphere(center: Vec3, radius: number, wireFrame: boolean = false) {
|
public drawSphere(
|
||||||
|
center: Vec3,
|
||||||
|
radius: number,
|
||||||
|
wireFrame: boolean = false,
|
||||||
|
segmentsX: number = 32,
|
||||||
|
segmentsY: number = 16,
|
||||||
|
) {
|
||||||
const color = this._color.clone();
|
const color = this._color.clone();
|
||||||
const renderer = this.getRenderer(color);
|
|
||||||
const c = this._useLocalPosition ? this.worldToLocal(center) : center;
|
const c = this._useLocalPosition ? this.worldToLocal(center) : center;
|
||||||
renderer.addDrawCall((geometry) => {
|
this._renderer?.addSphere(c, radius, color, segmentsX, segmentsY, wireFrame, this._depthTest);
|
||||||
geometry?.addSphere(c, radius, color, 32, 16, wireFrame, this._depthTest);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public drawArc(center: Vec3, radius: number, startAngle: number, endAngle: number, rot: Vec3 = Vec3.ZERO) {
|
public drawArc(
|
||||||
|
center: Vec3,
|
||||||
|
radius: number,
|
||||||
|
startAngle: number,
|
||||||
|
endAngle: number,
|
||||||
|
rot: Vec3 = Vec3.ZERO,
|
||||||
|
segments: number = 32,
|
||||||
|
) {
|
||||||
const color = this._color.clone();
|
const color = this._color.clone();
|
||||||
const renderer = this.getRenderer(color);
|
|
||||||
const c = this._useLocalPosition ? this.worldToLocal(center) : center;
|
const c = this._useLocalPosition ? this.worldToLocal(center) : center;
|
||||||
const transform = this.rotate(c, rot);
|
const transform = this.rotate(c, rot);
|
||||||
renderer.addDrawCall((geometry) => {
|
this._renderer?.addArc(c, radius, color, startAngle, endAngle, segments, this._depthTest, true, transform);
|
||||||
geometry?.addArc(c, radius, color, startAngle, endAngle, 32, this._depthTest, true, transform);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public drawSolidArc(
|
public drawSolidArc(
|
||||||
|
@ -269,26 +213,24 @@ class GizmosDebugDraw extends Component {
|
||||||
endAngle: number,
|
endAngle: number,
|
||||||
rot: Vec3 = Vec3.ZERO,
|
rot: Vec3 = Vec3.ZERO,
|
||||||
wireFrame: boolean = false,
|
wireFrame: boolean = false,
|
||||||
|
segments: number = 32,
|
||||||
) {
|
) {
|
||||||
const color = this._color.clone();
|
const color = this._color.clone();
|
||||||
const renderer = this.getRenderer(color);
|
|
||||||
const c = this._useLocalPosition ? this.worldToLocal(center) : center;
|
const c = this._useLocalPosition ? this.worldToLocal(center) : center;
|
||||||
const transform = this.rotate(c, rot);
|
const transform = this.rotate(c, rot);
|
||||||
renderer.addDrawCall((geometry) => {
|
this._renderer?.addSector(
|
||||||
geometry?.addSector(
|
c,
|
||||||
c,
|
radius,
|
||||||
radius,
|
color,
|
||||||
color,
|
startAngle,
|
||||||
startAngle,
|
endAngle,
|
||||||
endAngle,
|
segments,
|
||||||
32,
|
wireFrame,
|
||||||
wireFrame,
|
this._depthTest,
|
||||||
this._depthTest,
|
true,
|
||||||
true,
|
true,
|
||||||
true,
|
transform,
|
||||||
transform,
|
);
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public drawPolygon(
|
public drawPolygon(
|
||||||
|
@ -299,31 +241,22 @@ class GizmosDebugDraw extends Component {
|
||||||
wireFrame: boolean = false,
|
wireFrame: boolean = false,
|
||||||
) {
|
) {
|
||||||
const color = this._color.clone();
|
const color = this._color.clone();
|
||||||
const renderer = this.getRenderer(color);
|
|
||||||
const p = this._useLocalPosition ? this.worldToLocal(position) : position;
|
const p = this._useLocalPosition ? this.worldToLocal(position) : position;
|
||||||
const transform = this.rotate(p, rot);
|
const transform = this.rotate(p, rot);
|
||||||
renderer.addDrawCall((geometry) => {
|
this._renderer?.addPolygon(p, radius, color, segments, wireFrame, this._depthTest, true, true, transform);
|
||||||
geometry?.addPolygon(p, radius, color, segments, wireFrame, this._depthTest, true, true, transform);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public drawOctahedron(position: Vec3, radius: number, rot: Vec3 = Vec3.ZERO, wireFrame: boolean = false) {
|
public drawOctahedron(position: Vec3, radius: number, rot: Vec3 = Vec3.ZERO, wireFrame: boolean = false) {
|
||||||
const color = this._color.clone();
|
const color = this._color.clone();
|
||||||
const renderer = this.getRenderer(color);
|
|
||||||
const p = this._useLocalPosition ? this.worldToLocal(position) : position;
|
const p = this._useLocalPosition ? this.worldToLocal(position) : position;
|
||||||
const transform = this.rotate(p, rot);
|
const transform = this.rotate(p, rot);
|
||||||
renderer.addDrawCall((geometry) => {
|
this._renderer?.addOctahedron(p, radius, color, wireFrame, this._depthTest, false, true, transform);
|
||||||
geometry?.addOctahedron(p, radius, color, wireFrame, this._depthTest, false, true, transform);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public drawCross(position: Vec3, size: number) {
|
public drawCross(position: Vec3, size: number) {
|
||||||
const color = this._color.clone();
|
const color = this._color.clone();
|
||||||
const renderer = this.getRenderer(color);
|
|
||||||
const p = this._useLocalPosition ? this.worldToLocal(position) : position;
|
const p = this._useLocalPosition ? this.worldToLocal(position) : position;
|
||||||
renderer.addDrawCall((geometry) => {
|
this._renderer?.addCross(p, size, color, this._depthTest);
|
||||||
geometry?.addCross(p, size, color, this._depthTest);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public drawCapsule(
|
public drawCapsule(
|
||||||
|
@ -332,25 +265,33 @@ class GizmosDebugDraw extends Component {
|
||||||
height: number,
|
height: number,
|
||||||
rot: Vec3 = Vec3.ZERO,
|
rot: Vec3 = Vec3.ZERO,
|
||||||
wireFrame: boolean = false,
|
wireFrame: boolean = false,
|
||||||
|
segmentsX: number = 32,
|
||||||
|
segmentsY: number = 8,
|
||||||
) {
|
) {
|
||||||
const color = this._color.clone();
|
const color = this._color.clone();
|
||||||
const renderer = this.getRenderer(color);
|
|
||||||
const p = this._useLocalPosition ? this.worldToLocal(position) : position;
|
const p = this._useLocalPosition ? this.worldToLocal(position) : position;
|
||||||
const transform = this.rotate(p, rot);
|
const transform = this.rotate(p, rot);
|
||||||
renderer.addDrawCall((geometry) => {
|
this._renderer?.addCapsule(
|
||||||
geometry?.addCapsule(p, radius, height, color, 32, 8, wireFrame, this._depthTest, false, true, transform);
|
p,
|
||||||
});
|
radius,
|
||||||
|
height,
|
||||||
|
color,
|
||||||
|
segmentsX,
|
||||||
|
segmentsY,
|
||||||
|
wireFrame,
|
||||||
|
this._depthTest,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
transform,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public drawBox(position: Vec3, size: Vec3, rot: Vec3 = Vec3.ZERO, wireFrame: boolean = false) {
|
public drawBox(position: Vec3, size: Vec3, rot: Vec3 = Vec3.ZERO, wireFrame: boolean = false) {
|
||||||
const color = this._color.clone();
|
const color = this._color.clone();
|
||||||
const renderer = this.getRenderer(color);
|
|
||||||
const p = this._useLocalPosition ? this.worldToLocal(position) : position;
|
const p = this._useLocalPosition ? this.worldToLocal(position) : position;
|
||||||
const transform = this.rotate(p, rot);
|
const transform = this.rotate(p, rot);
|
||||||
let box = geometry?.AABB.create(p.x, p.y, p.z, size.x, size.y, size.z);
|
let box = geometry?.AABB.create(p.x, p.y, p.z, size.x, size.y, size.z);
|
||||||
renderer.addDrawCall((geometry) => {
|
this._renderer?.addBoundingBox(box, color, wireFrame, this._depthTest, false, true, transform);
|
||||||
geometry?.addBoundingBox(box, color, wireFrame, this._depthTest, false, true, transform);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public drawCylinder(
|
public drawCylinder(
|
||||||
|
@ -359,47 +300,66 @@ class GizmosDebugDraw extends Component {
|
||||||
height: number,
|
height: number,
|
||||||
rot: Vec3 = Vec3.ZERO,
|
rot: Vec3 = Vec3.ZERO,
|
||||||
wireFrame: boolean = false,
|
wireFrame: boolean = false,
|
||||||
|
segments: number = 32,
|
||||||
) {
|
) {
|
||||||
const color = this._color.clone();
|
const color = this._color.clone();
|
||||||
const renderer = this.getRenderer(color);
|
|
||||||
const p = this._useLocalPosition ? this.worldToLocal(position) : position;
|
const p = this._useLocalPosition ? this.worldToLocal(position) : position;
|
||||||
const transform = this.rotate(p, rot);
|
const transform = this.rotate(p, rot);
|
||||||
renderer.addDrawCall((geometry) => {
|
this._renderer?.addCylinder(
|
||||||
geometry?.addCylinder(p, radius, height, color, 32, wireFrame, this._depthTest, false, true, transform);
|
p,
|
||||||
});
|
radius,
|
||||||
|
height,
|
||||||
|
color,
|
||||||
|
segments,
|
||||||
|
wireFrame,
|
||||||
|
this._depthTest,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
transform,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public drawCone(position: Vec3, radius: number, height: number, rot: Vec3 = Vec3.ZERO, wireFrame: boolean = false) {
|
public drawCone(
|
||||||
|
position: Vec3,
|
||||||
|
radius: number,
|
||||||
|
height: number,
|
||||||
|
rot: Vec3 = Vec3.ZERO,
|
||||||
|
wireFrame: boolean = false,
|
||||||
|
segments: number = 32,
|
||||||
|
) {
|
||||||
const color = this._color.clone();
|
const color = this._color.clone();
|
||||||
const renderer = this.getRenderer(color);
|
|
||||||
const p = this._useLocalPosition ? this.worldToLocal(position) : position;
|
const p = this._useLocalPosition ? this.worldToLocal(position) : position;
|
||||||
const transform = this.rotate(p, rot);
|
const transform = this.rotate(p, rot);
|
||||||
renderer.addDrawCall((geometry) => {
|
this._renderer?.addCone(p, radius, height, color, segments, wireFrame, this._depthTest, false, true, transform);
|
||||||
geometry?.addCone(p, radius, height, color, 32, wireFrame, this._depthTest, false, true, transform);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public drawBezier(point1: Vec3, point2: Vec3, point3: Vec3, point4: Vec3, rot: Vec3 = Vec3.ZERO) {
|
public drawBezier(
|
||||||
|
point1: Vec3,
|
||||||
|
point2: Vec3,
|
||||||
|
point3: Vec3,
|
||||||
|
point4: Vec3,
|
||||||
|
rot: Vec3 = Vec3.ZERO,
|
||||||
|
segments: number = 32,
|
||||||
|
) {
|
||||||
const color = this._color.clone();
|
const color = this._color.clone();
|
||||||
const renderer = this.getRenderer(color);
|
|
||||||
const p1 = this._useLocalPosition ? this.worldToLocal(point1) : point1;
|
const p1 = this._useLocalPosition ? this.worldToLocal(point1) : point1;
|
||||||
const p2 = this._useLocalPosition ? this.worldToLocal(point2) : point2;
|
const p2 = this._useLocalPosition ? this.worldToLocal(point2) : point2;
|
||||||
const p3 = this._useLocalPosition ? this.worldToLocal(point3) : point3;
|
const p3 = this._useLocalPosition ? this.worldToLocal(point3) : point3;
|
||||||
const p4 = this._useLocalPosition ? this.worldToLocal(point4) : point4;
|
const p4 = this._useLocalPosition ? this.worldToLocal(point4) : point4;
|
||||||
const transform = this.rotate(p1, rot);
|
const transform = this.rotate(p1, rot);
|
||||||
renderer.addDrawCall((geometry) => {
|
this._renderer?.addBezier(p1, p2, p3, p4, color, segments, this._depthTest, true, transform);
|
||||||
geometry?.addBezier(p1, p2, p3, p4, color, 32, this._depthTest, true, transform);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public drawSpline(knots: Vec3[], mode: geometry.SplineMode = geometry?.SplineMode.BEZIER, knotSize = 0.5) {
|
public drawSpline(
|
||||||
|
knots: Vec3[],
|
||||||
|
mode: geometry.SplineMode = geometry?.SplineMode.BEZIER,
|
||||||
|
knotSize = 0.5,
|
||||||
|
segments: number = 32,
|
||||||
|
) {
|
||||||
const color = this._color.clone();
|
const color = this._color.clone();
|
||||||
const renderer = this.getRenderer(color);
|
|
||||||
const knotsList = this._useLocalPosition ? knots.map((knot) => this.worldToLocal(knot)) : knots;
|
const knotsList = this._useLocalPosition ? knots.map((knot) => this.worldToLocal(knot)) : knots;
|
||||||
let spline = geometry?.Spline.create(mode, knotsList);
|
let spline = geometry?.Spline.create(mode, knotsList);
|
||||||
renderer.addDrawCall((geometry) => {
|
this._renderer?.addSpline(spline, color, 0xffffffff, knotSize, segments, this._depthTest);
|
||||||
geometry?.addSpline(spline, color, 0xffffffff, knotSize, 32, this._depthTest);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -435,49 +395,45 @@ export default class Gizmos3D {
|
||||||
return debugNode;
|
return debugNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static registerDrawGizmos(node: Node) {
|
public static registerDrawGizmos(node: Node, component: new () => Component) {
|
||||||
this.getDebugNode(node).registerDrawGizmos(node);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
static beginLocalPosition(node: Node) {
|
static beginLocalPosition(node: Node) {
|
||||||
this.getDebugNode(node).setUseLocalPosition(true);
|
this.getDebugNode(node)?.setUseLocalPosition(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static endLocalPosition(node: Node) {
|
static endLocalPosition(node: Node) {
|
||||||
this.getDebugNode(node).setUseLocalPosition(false);
|
this.getDebugNode(node)?.setUseLocalPosition(false);
|
||||||
}
|
|
||||||
|
|
||||||
public static clearAll(node: Node) {
|
|
||||||
this.getDebugNode(node).clearAll();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static drawLine(node: Node, point1: Vec3, point2: Vec3) {
|
public static drawLine(node: Node, point1: Vec3, point2: Vec3) {
|
||||||
const debugNode = this.getDebugNode(node);
|
const debugNode = this.getDebugNode(node);
|
||||||
debugNode.drawLine(point1, point2);
|
debugNode?.drawLine(point1, point2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static drawLineList(node: Node, points: Vec3[], close: boolean = false) {
|
public static drawLineList(node: Node, points: Vec3[], close: boolean = false) {
|
||||||
const debugNode = this.getDebugNode(node);
|
const debugNode = this.getDebugNode(node);
|
||||||
debugNode.drawLineList(points, close);
|
debugNode?.drawLineList(points, close);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static drawDashLine(node: Node, point1: Vec3, point2: Vec3) {
|
public static drawDashLine(node: Node, point1: Vec3, point2: Vec3) {
|
||||||
const debugNode = this.getDebugNode(node);
|
const debugNode = this.getDebugNode(node);
|
||||||
debugNode.drawDashLine(point1, point2);
|
debugNode?.drawDashLine(point1, point2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static drawDashLineList(node: Node, points: Vec3[], close: boolean = false) {
|
public static drawDashLineList(node: Node, points: Vec3[], close: boolean = false) {
|
||||||
const debugNode = this.getDebugNode(node);
|
const debugNode = this.getDebugNode(node);
|
||||||
debugNode.drawLineList(points, close);
|
debugNode?.drawLineList(points, close);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static drawCircle(node: Node, center: Vec3, radius: number, rot: Vec3 = Vec3.ZERO) {
|
public static drawCircle(node: Node, center: Vec3, radius: number, rot: Vec3 = Vec3.ZERO, segments: number = 32) {
|
||||||
const debugNode = this.getDebugNode(node);
|
const debugNode = this.getDebugNode(node);
|
||||||
debugNode.drawCircle(center, radius, rot);
|
debugNode?.drawCircle(center, radius, rot, segments);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static drawDisc(
|
public static drawDisc(
|
||||||
|
@ -486,9 +442,10 @@ export default class Gizmos3D {
|
||||||
radius: number,
|
radius: number,
|
||||||
rot: Vec3 = Vec3.ZERO,
|
rot: Vec3 = Vec3.ZERO,
|
||||||
wireFrame: boolean = false,
|
wireFrame: boolean = false,
|
||||||
|
segments: number = 32,
|
||||||
) {
|
) {
|
||||||
const debugNode = this.getDebugNode(node);
|
const debugNode = this.getDebugNode(node);
|
||||||
debugNode.drawDisc(center, radius, rot, wireFrame);
|
debugNode?.drawDisc(center, radius, rot, wireFrame, segments);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static drawQuad(
|
public static drawQuad(
|
||||||
|
@ -500,12 +457,19 @@ export default class Gizmos3D {
|
||||||
wireFrame: boolean = false,
|
wireFrame: boolean = false,
|
||||||
) {
|
) {
|
||||||
const debugNode = this.getDebugNode(node);
|
const debugNode = this.getDebugNode(node);
|
||||||
debugNode.drawQuad(point1, point2, point3, point4, wireFrame);
|
debugNode?.drawQuad(point1, point2, point3, point4, wireFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static drawSphere(node: Node, center: Vec3, radius: number, wireFrame: boolean = false) {
|
public static drawSphere(
|
||||||
|
node: Node,
|
||||||
|
center: Vec3,
|
||||||
|
radius: number,
|
||||||
|
wireFrame: boolean = false,
|
||||||
|
segmentsX: number = 32,
|
||||||
|
segmentsY: number = 16,
|
||||||
|
) {
|
||||||
const debugNode = this.getDebugNode(node);
|
const debugNode = this.getDebugNode(node);
|
||||||
debugNode.drawSphere(center, radius, wireFrame);
|
debugNode?.drawSphere(center, radius, wireFrame, segmentsX, segmentsY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static drawArc(
|
public static drawArc(
|
||||||
|
@ -515,9 +479,10 @@ export default class Gizmos3D {
|
||||||
startAngle: number,
|
startAngle: number,
|
||||||
endAngle: number,
|
endAngle: number,
|
||||||
rot: Vec3 = Vec3.ZERO,
|
rot: Vec3 = Vec3.ZERO,
|
||||||
|
segments: number = 32,
|
||||||
) {
|
) {
|
||||||
const debugNode = this.getDebugNode(node);
|
const debugNode = this.getDebugNode(node);
|
||||||
debugNode.drawArc(center, radius, startAngle, endAngle, rot);
|
debugNode?.drawArc(center, radius, startAngle, endAngle, rot, segments);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static drawSolidArc(
|
public static drawSolidArc(
|
||||||
|
@ -528,9 +493,10 @@ export default class Gizmos3D {
|
||||||
endAngle: number,
|
endAngle: number,
|
||||||
rot: Vec3 = Vec3.ZERO,
|
rot: Vec3 = Vec3.ZERO,
|
||||||
wireFrame: boolean = false,
|
wireFrame: boolean = false,
|
||||||
|
segments: number = 32,
|
||||||
) {
|
) {
|
||||||
const debugNode = this.getDebugNode(node);
|
const debugNode = this.getDebugNode(node);
|
||||||
debugNode.drawSolidArc(center, radius, startAngle, endAngle, rot, wireFrame);
|
debugNode?.drawSolidArc(center, radius, startAngle, endAngle, rot, wireFrame, segments);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static drawPolygon(
|
public static drawPolygon(
|
||||||
|
@ -542,7 +508,7 @@ export default class Gizmos3D {
|
||||||
wireFrame: boolean = false,
|
wireFrame: boolean = false,
|
||||||
) {
|
) {
|
||||||
const debugNode = this.getDebugNode(node);
|
const debugNode = this.getDebugNode(node);
|
||||||
debugNode.drawPolygon(position, radius, segments, rot, wireFrame);
|
debugNode?.drawPolygon(position, radius, segments, rot, wireFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static drawOctahedron(
|
public static drawOctahedron(
|
||||||
|
@ -553,12 +519,12 @@ export default class Gizmos3D {
|
||||||
wireFrame: boolean = false,
|
wireFrame: boolean = false,
|
||||||
) {
|
) {
|
||||||
const debugNode = this.getDebugNode(node);
|
const debugNode = this.getDebugNode(node);
|
||||||
debugNode.drawOctahedron(position, radius, rot, wireFrame);
|
debugNode?.drawOctahedron(position, radius, rot, wireFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static drawCross(node: Node, center: Vec3, size: number) {
|
public static drawCross(node: Node, center: Vec3, size: number) {
|
||||||
const debugNode = this.getDebugNode(node);
|
const debugNode = this.getDebugNode(node);
|
||||||
debugNode.drawCross(center, size);
|
debugNode?.drawCross(center, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static drawCapsule(
|
public static drawCapsule(
|
||||||
|
@ -568,14 +534,16 @@ export default class Gizmos3D {
|
||||||
height: number,
|
height: number,
|
||||||
rot?: Vec3,
|
rot?: Vec3,
|
||||||
wireFrame?: boolean,
|
wireFrame?: boolean,
|
||||||
|
segmentsX: number = 32,
|
||||||
|
segmentsY: number = 8,
|
||||||
) {
|
) {
|
||||||
const debugNode = this.getDebugNode(node);
|
const debugNode = this.getDebugNode(node);
|
||||||
debugNode.drawCapsule(position, radius, height, rot, wireFrame);
|
debugNode?.drawCapsule(position, radius, height, rot, wireFrame, segmentsX, segmentsY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static drawBox(node: Node, center: Vec3, size: Vec3, rot?: Vec3, wireFrame?: boolean) {
|
public static drawBox(node: Node, center: Vec3, size: Vec3, rot?: Vec3, wireFrame?: boolean) {
|
||||||
const debugNode = this.getDebugNode(node);
|
const debugNode = this.getDebugNode(node);
|
||||||
debugNode.drawBox(center, size, rot, wireFrame);
|
debugNode?.drawBox(center, size, rot, wireFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static drawCylinder(
|
public static drawCylinder(
|
||||||
|
@ -585,9 +553,10 @@ export default class Gizmos3D {
|
||||||
height: number,
|
height: number,
|
||||||
rot: Vec3 = Vec3.ZERO,
|
rot: Vec3 = Vec3.ZERO,
|
||||||
wireFrame: boolean = false,
|
wireFrame: boolean = false,
|
||||||
|
segments: number = 32,
|
||||||
) {
|
) {
|
||||||
const debugNode = this.getDebugNode(node);
|
const debugNode = this.getDebugNode(node);
|
||||||
debugNode.drawCylinder(position, radius, height, rot, wireFrame);
|
debugNode?.drawCylinder(position, radius, height, rot, wireFrame, segments);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static drawCone(
|
public static drawCone(
|
||||||
|
@ -597,14 +566,23 @@ export default class Gizmos3D {
|
||||||
height: number,
|
height: number,
|
||||||
rot: Vec3 = Vec3.ZERO,
|
rot: Vec3 = Vec3.ZERO,
|
||||||
wireFrame: boolean = false,
|
wireFrame: boolean = false,
|
||||||
|
segments: number = 32,
|
||||||
) {
|
) {
|
||||||
const debugNode = this.getDebugNode(node);
|
const debugNode = this.getDebugNode(node);
|
||||||
debugNode.drawCone(position, radius, height, rot, wireFrame);
|
debugNode?.drawCone(position, radius, height, rot, wireFrame, segments);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static drawBezier(node: Node, point1: Vec3, point2: Vec3, point3: Vec3, point4: Vec3, rot?: Vec3) {
|
public static drawBezier(
|
||||||
|
node: Node,
|
||||||
|
point1: Vec3,
|
||||||
|
point2: Vec3,
|
||||||
|
point3: Vec3,
|
||||||
|
point4: Vec3,
|
||||||
|
rot?: Vec3,
|
||||||
|
segments: number = 32,
|
||||||
|
) {
|
||||||
const debugNode = this.getDebugNode(node);
|
const debugNode = this.getDebugNode(node);
|
||||||
debugNode.drawBezier(point1, point2, point3, point4, rot);
|
debugNode?.drawBezier(point1, point2, point3, point4, rot, segments);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static drawSpline(
|
public static drawSpline(
|
||||||
|
@ -612,8 +590,9 @@ export default class Gizmos3D {
|
||||||
knots: Vec3[],
|
knots: Vec3[],
|
||||||
mode: geometry.SplineMode = geometry?.SplineMode.BEZIER,
|
mode: geometry.SplineMode = geometry?.SplineMode.BEZIER,
|
||||||
knotSize = 0.5,
|
knotSize = 0.5,
|
||||||
|
segments: number = 32,
|
||||||
) {
|
) {
|
||||||
const debugNode = this.getDebugNode(node);
|
const debugNode = this.getDebugNode(node);
|
||||||
debugNode.drawSpline(knots, mode, knotSize);
|
debugNode?.drawSpline(knots, mode, knotSize, segments);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
import { Director, director, find } from 'cc';
|
|
||||||
import { Editor } from './Define';
|
|
||||||
|
|
||||||
if (Editor) {
|
|
||||||
if (!sessionStorage.getItem('gizmosUpdating')) {
|
|
||||||
sessionStorage.setItem('gizmosUpdating', 'true');
|
|
||||||
director.on(Director.EVENT_BEFORE_UPDATE, querySelected);
|
|
||||||
}
|
|
||||||
|
|
||||||
function querySelected() {
|
|
||||||
if (Editor) {
|
|
||||||
const selectedList: string[] = Editor.Selection.getSelected('node');
|
|
||||||
selectedList.forEach(callGizmos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function callGizmos(uuid: string) {
|
|
||||||
const node = await Editor.Message.request('scene', 'query-node-tree', uuid);
|
|
||||||
const comps = find(node.path).components;
|
|
||||||
comps.forEach((comp) => comp.onDrawGizmosSelected?.());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -226,7 +226,7 @@ export class GameManager extends Singleton<GameManager>() {
|
||||||
if (value > 0 && this._currentBallInGame >= 2) {
|
if (value > 0 && this._currentBallInGame >= 2) {
|
||||||
this._isMultiBall = true;
|
this._isMultiBall = true;
|
||||||
EventManger.instance.emit(GameEvent.MultiBall, true);
|
EventManger.instance.emit(GameEvent.MultiBall, true);
|
||||||
this._ballPool.actives.forEach((ball) => ball.getComponent(Ball).playMultiBallEffect());
|
this._ballPool.listActive.forEach((ball) => ball.getComponent(Ball).playMultiBallEffect());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._currentBallInGame <= 0) {
|
if (this._currentBallInGame <= 0) {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import GameState from '../Enum/GameState';
|
||||||
import ScoreType from '../Enum/ScoreType';
|
import ScoreType from '../Enum/ScoreType';
|
||||||
import { ScoreObject } from '../Environments/ScoreObject';
|
import { ScoreObject } from '../Environments/ScoreObject';
|
||||||
import GameEvent from '../Events/GameEvent';
|
import GameEvent from '../Events/GameEvent';
|
||||||
|
import { registerGizmo } from '../Gizmos/Decorator';
|
||||||
import Gizmos2D from '../Gizmos/Gizmos2D';
|
import Gizmos2D from '../Gizmos/Gizmos2D';
|
||||||
import ObjectPool from '../Pool/ObjectPool';
|
import ObjectPool from '../Pool/ObjectPool';
|
||||||
import { EventManger } from './EventManger';
|
import { EventManger } from './EventManger';
|
||||||
|
@ -25,6 +26,7 @@ class weightedObject {
|
||||||
public currentWeight;
|
public currentWeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@registerGizmo
|
||||||
@ccclass('SpawnObjectManager')
|
@ccclass('SpawnObjectManager')
|
||||||
export class SpawnObjectManager extends Component {
|
export class SpawnObjectManager extends Component {
|
||||||
@property({ type: weightedObject, visible: true })
|
@property({ type: weightedObject, visible: true })
|
||||||
|
@ -52,7 +54,7 @@ export class SpawnObjectManager extends Component {
|
||||||
private _boosterSpawned = false;
|
private _boosterSpawned = false;
|
||||||
private _spawnTimeObject = 0;
|
private _spawnTimeObject = 0;
|
||||||
|
|
||||||
onDrawGizmosSelected(): void {
|
onDrawGizmos(): void {
|
||||||
for (let i = 0; i < this._spawnPoints.length; i++) {
|
for (let i = 0; i < this._spawnPoints.length; i++) {
|
||||||
Gizmos2D.beginColor(this.node, new Color(0, 255, 0, 180));
|
Gizmos2D.beginColor(this.node, new Color(0, 255, 0, 180));
|
||||||
Gizmos2D.drawSolidCircle(this.node, this._spawnPoints[i].worldPosition, 15);
|
Gizmos2D.drawSolidCircle(this.node, this._spawnPoints[i].worldPosition, 15);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"__version__": "1.0.0",
|
"__version__": "1.0.1",
|
||||||
"information": {
|
"information": {
|
||||||
"customSplash": {
|
"customSplash": {
|
||||||
"id": "customSplash",
|
"id": "customSplash",
|
||||||
|
|
Loading…
Reference in New Issue