import { _decorator, Component, Node, input, Input, EventMouse, Vec3, v2, Camera, } from 'cc';
const { ccclass, property } = _decorator;
export class NewComponent extends Component {
private _currotate = new Vec3();
private _speed: number = 0;
private IsMouseDown: boolean = false;
private headNode: Node = null!;
input.on(Input.EventType.MOUSE_DOWN, this.MouseDown, this);
input.on(Input.EventType.MOUSE_UP, this.MouseUp, this);
input.on(Input.EventType.MOUSE_WHEEL, this.MouseWheel, this);
input.on(Input.EventType.MOUSE_MOVE, this.OnMove, this);
MouseDown(event:EventMouse) {
MouseUp(event: EventMouse) {
this.IsMouseDown = false;
MouseWheel(event: EventMouse) {
//console.log(event.getScrollX);
//console.log(event.getScrollY);
//console.log(event.setScrollData);
let length: number = event.getScrollY();
let distance: Number = 1;
abc = this.headNode.getPosition();
this.headNode.setPosition(abc.x, abc.y, abc.z - 1);
//console.log(this.headNode.position);
abc = this.headNode.getPosition();
this.headNode.setPosition(abc.x, abc.y, abc.z + 1);
//this.headNode.getComponent<Camera>()
OnMove(event: EventMouse) {
if (!this.IsMouseDown) return;
let delat = event.getDelta();
if (event.getButton() == 1) {
campos = this.headNode.getPosition();
console.log(this.headNode.position);
let camposx: number = campos.x - delat.x * 0.01;
this.headNode.position = new Vec3(camposx, campos.y, campos.z);
let camposx: number = campos.x - delat.x * 0.01;
this.headNode.position = new Vec3(camposx, campos.y, campos.z);
let camposy: number = campos.y - delat.y * 0.01;
this.headNode.position = new Vec3(campos.x, camposy, campos.z);
let camposy: number = campos.y - delat.y * 0.01;
this.headNode.position = new Vec3(campos.x, camposy, campos.z);
if (event.getButton() == 0) {
let angle = this.node.eulerAngles;
let angleY = angle.y + angle_speed;
this.node.eulerAngles = new Vec3(angle.x, angleY, angle.z);
} else if (delat.x > 0) {
let angle = this.node.eulerAngles;
let angleY = angle.y - angle_speed;
this.node.eulerAngles = new Vec3(angle.x, angleY, angle.z);
} else if (delat.y > 0) {
let angle = this.node.eulerAngles;
let angleX = angle.x + angle_speed;
this.node.eulerAngles = new Vec3(angleX, angle.y, angle.z);
} else if (delat.y < 0) {
let angle = this.node.eulerAngles;
let angleX = angle.x - angle_speed;
this.node.eulerAngles = new Vec3(angleX, angle.y, angle.z);