UNPKG

playcanvas

Version:

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

83 lines (82 loc) 2.41 kB
import { Component } from "../component.js"; import { ComponentSystem } from "../system.js"; import { ScrollViewComponent } from "./component.js"; import { ScrollViewComponentData } from "./data.js"; const _schema = ["enabled"]; const _properties = [ "horizontal", "vertical", "scrollMode", "bounceAmount", "friction", "dragThreshold", "useMouseWheel", "mouseWheelSensitivity", "horizontalScrollbarVisibility", "verticalScrollbarVisibility", "viewportEntity", "contentEntity", "horizontalScrollbarEntity", "verticalScrollbarEntity" ]; class ScrollViewComponentSystem extends ComponentSystem { constructor(app) { super(app); this.id = "scrollview"; this.ComponentType = ScrollViewComponent; this.DataType = ScrollViewComponentData; this.schema = _schema; this.on("beforeremove", this._onRemoveComponent, this); this.app.systems.on("update", this.onUpdate, this); } initializeComponentData(component, data, properties) { for (let i = 0; i < _properties.length; i++) { const property = _properties[i]; if (data[property] !== void 0) { component[property] = data[property]; } } super.initializeComponentData(component, data, _schema); } cloneComponent(entity, clone) { const c = entity.scrollview; return this.addComponent(clone, { enabled: c.enabled, horizontal: c.horizontal, vertical: c.vertical, scrollMode: c.scrollMode, bounceAmount: c.bounceAmount, friction: c.friction, dragThreshold: c.dragThreshold, useMouseWheel: c.useMouseWheel, mouseWheelSensitivity: c.mouseWheelSensitivity, horizontalScrollbarVisibility: c.horizontalScrollbarVisibility, verticalScrollbarVisibility: c.verticalScrollbarVisibility, viewportEntity: c.viewportEntity, contentEntity: c.contentEntity, horizontalScrollbarEntity: c.horizontalScrollbarEntity, verticalScrollbarEntity: c.verticalScrollbarEntity }); } onUpdate(dt) { const components = this.store; for (const id in components) { const entity = components[id].entity; const component = entity.scrollview; if (component.enabled && entity.enabled) { component.onUpdate(); } } } _onRemoveComponent(entity, component) { component.onRemove(); } destroy() { super.destroy(); this.app.systems.off("update", this.onUpdate, this); } } Component._buildAccessors(ScrollViewComponent.prototype, _schema); export { ScrollViewComponentSystem };