forked from playcanvas/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystem.js
More file actions
90 lines (74 loc) · 3.3 KB
/
system.js
File metadata and controls
90 lines (74 loc) · 3.3 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
pc.extend(pc, function () {
var _schema = [ 'enabled' ];
/**
* @name pc.ScreenComponentSystem
* @description Create a new ScreenComponentSystem
* @class Manages creation of {@link pc.ScreenComponent}s.
* @param {pc.Application} app The application
* @extends pc.ComponentSystem
*/
var ScreenComponentSystem = function ScreenComponentSystem(app) {
this.id = 'screen';
this.app = app;
app.systems.add(this.id, this);
this.ComponentType = pc.ScreenComponent;
this.DataType = pc.ScreenComponentData;
this.schema = _schema;
this.windowResolution = new pc.Vec2();
this.app.graphicsDevice.on("resizecanvas", this._onResize, this);
pc.ComponentSystem.on('update', this._onUpdate, this);
this.on('beforeremove', this.onRemoveComponent, this);
};
ScreenComponentSystem = pc.inherits(ScreenComponentSystem, pc.ComponentSystem);
pc.Component._buildAccessors(pc.ScreenComponent.prototype, _schema);
pc.extend(ScreenComponentSystem.prototype, {
initializeComponentData: function (component, data, properties) {
if (data.screenSpace !== undefined) component.screenSpace = data.screenSpace;
if (data.scaleMode !== undefined) component.scaleMode = data.scaleMode;
if (data.scaleBlend !== undefined) component.scaleBlend = data.scaleBlend;
if (data.resolution !== undefined) {
if (data.resolution instanceof pc.Vec2){
component._resolution.copy(data.resolution);
} else {
component._resolution.set(data.resolution[0], data.resolution[1]);
}
component.resolution = component._resolution;
}
if (data.referenceResolution !== undefined) {
if (data.referenceResolution instanceof pc.Vec2){
component._referenceResolution.copy(data.referenceResolution);
} else {
component._referenceResolution.set(data.referenceResolution[0], data.referenceResolution[1]);
}
component.referenceResolution = component._referenceResolution;
}
ScreenComponentSystem._super.initializeComponentData.call(this, component, data, properties);
},
_onUpdate: function (dt) {
var components = this.store;
for (var id in components) {
if (components[id].entity.screen.update) components[id].entity.screen.update(dt);
}
},
_onResize: function (width, height) {
this.windowResolution.x = width;
this.windowResolution.y = height;
},
cloneComponent: function (entity, clone) {
var screen = entity.screen;
return this.addComponent(clone, {
enabled: screen.enabled,
screenSpace: screen.screenSpace,
scaleMode: screen.scaleMode,
resolution: screen.resolution.clone(),
referenceResolution: screen.referenceResolution.clone()
});
},
onRemoveComponent: function (entity, component) {
component.onRemove();
}
});
return {
ScreenComponentSystem: ScreenComponentSystem
};
}());