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
112 lines (98 loc) · 3.4 KB
/
Copy pathcomponent.js
File metadata and controls
112 lines (98 loc) · 3.4 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
pc.extend(pc, function () {
/**
* @component
* @name pc.ZoneComponent
* @extends pc.Component
* @class 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 {pc.ZoneComponentSystem} system The ComponentSystem that created this Component
* @param {pc.Vec3} size The Size of Box of a Zone.
*/
var ZoneComponent = function ZoneComponent(system, entity) {
this._oldState = true;
this._size = new pc.Vec3();
this.on('set_enabled', this._onSetEnabled, this);
};
ZoneComponent = pc.inherits(ZoneComponent, pc.Component);
/**
* @event
* @name pc.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
* });
*/
/**
* @event
* @name pc.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
* });
*/
/**
* @event
* @name pc.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
* });
*/
/**
* @event
* @name pc.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
* });
*/
pc.extend(ZoneComponent.prototype, {
onEnable: function () {
ZoneComponent._super.onEnable.call(this);
this._checkState();
},
onDisable: function () {
ZoneComponent._super.onDisable.call(this);
this._checkState();
},
_onSetEnabled: function(prop, old, value) {
this._checkState();
},
_checkState: function() {
var state = this.enabled && this.entity.enabled;
if (state === this._oldState)
return;
this._oldState = state;
this.fire('enable');
this.fire('state', this.enabled);
},
_onBeforeRemove: function() {
this.fire('remove');
}
});
Object.defineProperty(ZoneComponent.prototype, 'size', {
set: function(data) {
if (data instanceof pc.Vec3) {
this._size.copy(data);
} else if (data instanceof Array && data.length >= 3) {
this.size.set(data[0], data[1], data[2]);
}
},
get: function() {
return this._size;
}
});
return {
ZoneComponent: ZoneComponent
};
}());