import { _decorator, Component, Node, Camera, View, Vec3, view, Prefab, geometry, SystemEvent, systemEvent, SystemEventType, EventTouch, Canvas, Touch, Label, UITransform } from ‘cc’;
const { ccclass, property } = _decorator;
@ccclass(‘Text’)
export class Text extends Component {
@property({ type: Label }) readonly label: Label = null!;
@property({ type: Camera }) readonly camera: Camera = null!;
// @property({ type: [Node] }) readonly bg: Node = [];
// @property({ type: [Prefab] }) mapPrefab: Prefab = [];
// @property({ type: Camera }) mainCamera: Camera = null;
// out: Vec3 = new Vec3();
// mapWigth: number = 1244;
// mapHight: number = 1364;
// line1 = [false, false, false, false]
// line2 = [false, false, false, false]
// screenWidth: number = 0;
// screenHigth: number = 0;
private _ray: geometry.Ray = new geometry.Ray();
private _aabb: geometry.AABB = new geometry.AABB();
start() {
}
onEnable() {
systemEvent.on(SystemEventType.TOUCH_START, this.onTouchStart, this);
}
onTouchStart(touch: Touch, event: EventTouch) {
const uiCamera = this.camera
const point = touch.getLocation();
uiCamera.screenPointToRay(point.x, point.y, this._ray);
const uiTrans = this.label.getComponent(UITransform)!;
uiTrans.getComputeAABB(this._aabb);
if (geometry.intersect.rayAABB(this._ray, this._aabb)) {
this.label.string = '检测成功';
systemEvent.off(SystemEventType.TOUCH_START, this.onTouchStart, this);
}
}
onDisable() {
systemEvent.off(SystemEventType.TOUCH_START, this.onTouchStart, this);
}