@needle-tools/engine
Version:
Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in.
47 lines (36 loc) • 1.06 kB
text/typescript
import { serializable } from "../engine/engine_serialization_decorator.js";
import { DeviceUtilities } from "../engine/engine_utils.js";
import { Behaviour, GameObject } from "./Component.js";
export enum DeviceType {
Never = 0,
Desktop = 1 << 0,
Mobile = 2 << 0,
}
/**
* @category Utilities
* @group Components
*/
export class DeviceFlag extends Behaviour {
visibleOn!: DeviceType;
onEnable() {
this.apply();
}
apply() {
if (!this.test()) {
GameObject.setActive(this.gameObject, false);
}
}
private test() : boolean {
if(this.visibleOn < 0) return true;
if(DeviceUtilities.isMobileDevice()) {
return (this.visibleOn & (DeviceType.Mobile)) !== 0;
}
const allowDesktop = (this.visibleOn & (DeviceType.Desktop)) !== 0;
return allowDesktop;
}
}
/**@deprecated use isMobileDevice() */
function isMobile() {
return DeviceUtilities.isMobileDevice();
};