UNPKG

playcanvas

Version:

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

104 lines (103 loc) 3.11 kB
var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); import { Vec3 } from "../../../core/math/vec3.js"; import { Component } from "../component.js"; class ZoneComponent extends Component { /** * Create a new ZoneComponent instance. * * @param {ZoneComponentSystem} system - The ComponentSystem that created this Component. * @param {Entity} entity - The Entity that this Component is attached to. */ constructor(system, entity) { super(system, entity); /** @private */ __publicField(this, "_oldState", true); /** @private */ __publicField(this, "_size", new Vec3()); this.on("set_enabled", this._onSetEnabled, this); } /** * The size of the axis-aligned box of this ZoneComponent. * * @type {Vec3} */ 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"); } } /** * Fired when the zone component is enabled. This event does not take into account the enabled * state of the entity or any of its ancestors. * * @event * @example * entity.zone.on('enable', () => { * console.log(`Zone component of entity '${entity.name}' has been enabled`); * }); */ __publicField(ZoneComponent, "EVENT_ENABLE", "enable"); /** * Fired when the zone component is disabled. This event does not take into account the enabled * state of the entity or any of its ancestors. * * @event * @example * entity.zone.on('disable', () => { * console.log(`Zone component of entity '${entity.name}' has been disabled`); * }); */ __publicField(ZoneComponent, "EVENT_DISABLE", "disable"); /** * Fired when the enabled state of the zone component changes. This event does not take into * account the enabled state of the entity or any of its ancestors. * * @event * @example * entity.zone.on('state', (enabled) => { * console.log(`Zone component of entity '${entity.name}' has been ${enabled ? 'enabled' : 'disabled'}`); * }); */ __publicField(ZoneComponent, "EVENT_STATE", "state"); /** * Fired when a zone component is removed from an entity. * * @event * @example * entity.zone.on('remove', () => { * console.log(`Zone component removed from entity '${entity.name}'`); * }); */ __publicField(ZoneComponent, "EVENT_REMOVE", "remove"); export { ZoneComponent };