|
|
@@ -1,4 +1,4 @@
|
|
|
-import { Component, _decorator, Node, EventTouch, systemEvent, input, Input, geometry, Camera, PhysicsSystem, director, v3, Vec3 } from "cc";
|
|
|
+import { Component, _decorator, Node, EventTouch, systemEvent, input, Input, geometry, Camera, PhysicsSystem, director, v3, Vec3, Color, Line, GradientRange, CurveRange } from "cc";
|
|
|
import { Checkpoint } from "../Checkpoint";
|
|
|
import { PuppetViewComp } from "../../puppet/view/PuppetViewComp";
|
|
|
import { oops } from "../../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
|
|
@@ -18,22 +18,48 @@ export class CheckpointViewController extends Component {
|
|
|
|
|
|
// @property({ type: Node, tooltip: '待触摸物体' })
|
|
|
// public node_touch_1: Node | null = null;
|
|
|
+ private line: Line = null;
|
|
|
|
|
|
private _ray: geometry.Ray = new geometry.Ray();
|
|
|
|
|
|
onLoad() {
|
|
|
const cameras = director.getScene().getComponentsInChildren(Camera);
|
|
|
this.mainCamera = cameras.find(camera => camera.node.name === 'MainCamera');
|
|
|
- input.on(Input.EventType.TOUCH_END, this.onTouchStart, this);
|
|
|
+ input.on(Input.EventType.TOUCH_START, this.onTouchStart, this);
|
|
|
+ // this.createLine();
|
|
|
}
|
|
|
|
|
|
onDestory() {
|
|
|
- input.off(Input.EventType.TOUCH_END, this.onTouchStart, this);
|
|
|
+ input.off(Input.EventType.TOUCH_START, this.onTouchStart, this);
|
|
|
}
|
|
|
|
|
|
+ createLine() {
|
|
|
+ const lineNode = new Node('Line');
|
|
|
+ lineNode.setParent(this.node);
|
|
|
+ this.line = lineNode.addComponent(Line);
|
|
|
+ const grad = new GradientRange()
|
|
|
+ grad.color = Color.RED;
|
|
|
+ this.line.color = grad;
|
|
|
+ }
|
|
|
+
|
|
|
+ drawRay(ray: geometry.Ray) {
|
|
|
+ const rayStart = ray.o;
|
|
|
+ const rayEnd = new Vec3();
|
|
|
+ Vec3.multiplyScalar(rayEnd, ray.d, 1000); // 假设射线长度为1000
|
|
|
+ Vec3.add(rayEnd, rayStart, rayEnd);
|
|
|
+ this.line.worldSpace = true;
|
|
|
+ const curve = new CurveRange()
|
|
|
+ curve.mode = CurveRange.Mode.Constant
|
|
|
+ curve.constant = 0.1
|
|
|
+ this.line.width = curve;
|
|
|
+ this.line.positions = [rayStart, rayEnd];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
onTouchStart(event: EventTouch) {
|
|
|
// 基于摄像机 画射线
|
|
|
this.mainCamera?.screenPointToRay(event.getLocation().x, event.getLocation().y, this._ray);
|
|
|
+ // this.drawRay(this._ray)
|
|
|
if (PhysicsSystem.instance.raycast(this._ray)) {
|
|
|
const r = PhysicsSystem.instance.raycastResults;
|
|
|
if (r.length > 0) {
|