forked from playcanvas/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomponent.js
More file actions
116 lines (98 loc) · 3.08 KB
/
component.js
File metadata and controls
116 lines (98 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import { Vec3 } from '../../../math/vec3.js';
import { Component } from '../component.js';
/**
* @private
* @component
* @class
* @name ZoneComponent
* @augments Component
* @classdesc The ZoneComponent allows you to define an area in world space of certain size.
* This can be used in various ways, such as affecting audio reverb when audiolistener is within zone.
* Or create culling system with portals between zones to hide whole indoor sections for performance reasons.
* And many other possible options. Zones are building blocks and meant to be used in many different ways.
* @param {ZoneComponentSystem} system - The ComponentSystem that created this Component.
* @param {Vec3} size - The Size of Box of a Zone.
*/
class ZoneComponent extends Component {
constructor(system, entity) {
super(system, entity);
this._oldState = true;
this._size = new Vec3();
this.on('set_enabled', this._onSetEnabled, this);
}
/**
* @private
* @event
* @name ZoneComponent#enable
* @description Fired when Component becomes enabled
* Note: this event does not take in account entity or any of its parent enabled state.
* @example
* entity.zone.on('enable', function () {
* // component is enabled
* });
*/
/**
* @private
* @event
* @name ZoneComponent#disable
* @description Fired when Component becomes disabled
* Note: this event does not take in account entity or any of its parent enabled state.
* @example
* entity.zone.on('disable', function () {
* // component is disabled
* });
*/
/**
* @private
* @event
* @name ZoneComponent#state
* @description Fired when Component changes state to enabled or disabled
* Note: this event does not take in account entity or any of its parent enabled state.
* @param {boolean} enabled - True if now enabled, False if disabled.
* @example
* entity.zone.on('state', function (enabled) {
* // component changed state
* });
*/
/**
* @private
* @event
* @name ZoneComponent#remove
* @description Fired when a zone is removed from an entity.
* @example
* entity.zone.on('remove', function () {
* // zone has been removed from an entity
* });
*/
onEnable() {
this._checkState();
}
onDisable() {
this._checkState();
}
_onSetEnabled(prop, old, value) {
this._checkState();
}
_checkState() {
var 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');
}
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;
}
}
export { ZoneComponent };