EasyTwin Engine
引擎代码
使用引擎的 draw 模块
world.drawUtils.mode = 'multi-rect';
world.drawUtils.setActiveComponent(this);
world.drawUtils.showDrawPoint(this.group);
world.drawUtils.showDrawMoveRect(this.group);
world.drawUtils.startDraw();
在引擎中新增组件(Component)
export const TemplateComponentType = 'Template';
EasyTwinComponentTypeMap
- 这个 map 是用于判断所属组件是属于哪一种类型
- 前 8 代表某种类型, 后 8 单边具体对应
- 可以出现控制辅助器的类型为 1
getEntityArchetype
if (entity.getComponentByType('Model')) return 'Model';
isEntityDigital
if (entity.isEntityDigital(entity: EngineEntity)) return boolean;
组件可以被控制器依附
switch (this.type) {
case 'XXX':
}
getObjectById
getObjectById(id: string) {
return this.group;
}
组件拖动完成
onDragEnd(): void
setVisible
setVisible(visible: boolean, uuid?: string): void
在引擎中实现对于 dom 元素的选中
clickDom.dataset.id = id;
clickDom.dataset.entityId = entityId;
clickDom.dataset.componentId = componentId;
const componentId = target.getAttribute('data-component-id');
const objectId = target.getAttribute('data-id');
custom attribute
为了能在数字要素传出自定义属性 如果数字要素含有多个子,就在子的 data 数据中加上 customAttribute 字段 不然就放在最外层
removeObjectById
public removeObjectById(id: string): void {
const object = this.getObjectById(id);
if (object) {
const child = this.childMap.get(object.uuid);
this.childMap.delete(object.uuid);
child && child.dispose();
child && this.group.remove(child);
this.needDataUpdateServer = true;
}
}
setVisible
public setVisible(visible: boolean): PoiPanelV2Component {
const getExtendVisible = (object: Object3D, visible: boolean): boolean => {
if (object.parent) {
return getExtendVisible(object.parent, object.parent.visible && visible);
} else {
return visible;
}
};
const extendVisible = getExtendVisible(this.group, this.group.visible);
this.childMap.forEach((child) => {
child.setVisible(visible && extendVisible);
});
return this;
}
public loadPoiPanelV2Component(
world: World,
entity: EngineEntity,
options: ComponentOptions,
isAdded: boolean = false,
): PoiPanelV2Component {
const { type, id, name, states } = options;
const component = entity.addComponent<PoiPanelV2Component>(
id,
name ?? '',
PoiPanelV2Component,
isAdded,
);
......
component.setVisible(entity.visible);
.....
return component;
}