UNPKG

playcanvas

Version:

Open-source WebGL/WebGPU 3D engine for the web

49 lines (46 loc) 1.16 kB
import { Vec3 } from '../../../core/math/vec3.js'; import { Component } from '../component.js'; class ZoneComponent extends Component { set size(data) { if (data instanceof Vec3) { this._size.copy(data); } else if (data instanceof Array && data.length >= 3) { this.size.set(data[0], data[1], data[2]); } } get size() { return this._size; } onEnable() { this._checkState(); } onDisable() { this._checkState(); } _onSetEnabled(prop, old, value) { this._checkState(); } _checkState() { const state = this.enabled && this.entity.enabled; if (state === this._oldState) { return; } this._oldState = state; this.fire('enable'); this.fire('state', this.enabled); } _onBeforeRemove() { this.fire('remove'); } constructor(system, entity){ super(system, entity); this._oldState = true; this._size = new Vec3(); this.on('set_enabled', this._onSetEnabled, this); } } ZoneComponent.EVENT_ENABLE = 'enable'; ZoneComponent.EVENT_DISABLE = 'disable'; ZoneComponent.EVENT_STATE = 'state'; ZoneComponent.EVENT_REMOVE = 'remove'; export { ZoneComponent };