import { _decorator,screen, AssetManager, AudioClip, Component, director, EventTouch, instantiate, isValid, IVec2Like, IVec3, IVec3Like, misc, Node, ParticleSystem2D, Prefab, Tween, tween, UIOpacity, Vec2, Vec3, sys } from "cc"; import MesMgr from "../MesEvent/MesMgr"; import { Global } from "../Global"; import { PREVIEW } from "cc/env"; const BlockEvents = [ Node.EventType.TOUCH_START, Node.EventType.TOUCH_MOVE, Node.EventType.TOUCH_END, Node.EventType.TOUCH_CANCEL, Node.EventType.MOUSE_DOWN, Node.EventType.MOUSE_MOVE, Node.EventType.MOUSE_UP, Node.EventType.MOUSE_ENTER, Node.EventType.MOUSE_LEAVE, Node.EventType.MOUSE_WHEEL ]; const {ccclass, property,menu} = _decorator; @ccclass("GlobalClick") export default class GlobalClick extends Component { @property(Prefab) effect:Prefab; private _Pool: Node[] = []; private getEffect(){ if (this._Pool.length) { return this._Pool.shift(); } else { let tNode = instantiate(this.effect); tNode.setParent(this.node); return tNode; } } private pushEffect(tNode:Node){ Tween.stopAllByTarget(tNode); tNode.getComponent(ParticleSystem2D).stopSystem(); tNode.active = false; this._Pool.push(tNode); } private _maxFarme:number = 3; private _curFarme:number = 0; private liftime:number = 0.5; private tempPos:Vec3 = new Vec3(); protected onLoad(): void { //this.node.addComponent(UIOpacity).opacity = 0; for (let i = 0; i < BlockEvents.length; i++) { const mType = BlockEvents[i]; switch(mType){ case Node.EventType.TOUCH_START: this.node.on(mType,this.TOUCH_START,this) break; case Node.EventType.TOUCH_END: this.node.on(mType, this.TOUCH_END, this) break; default: this.node.on(mType, this.default, this) break; } } } default(event: EventTouch){ event.preventSwallow = true; } TOUCH_START(event: EventTouch){ event.preventSwallow = true; //this.playEffect(event.getUILocation()); } TOUCH_END(event: EventTouch){ event.preventSwallow = true; if (!Global.Audio.firstClick) { Global.Audio.firstClick = true; } if (sys.isBrowser && sys.isMobile && !screen.fullScreen()) { screen.requestFullScreen().then((res) => { ConsoleEx.Com(res); }).catch((e) => { ConsoleEx.Error(e); }); } } playEffect(pos:IVec2Like){ if (this._curFarme >= this._maxFarme) { this._curFarme = 0; this.tempPos.x = pos.x; this.tempPos.y = pos.y; this.node.uiTrans.convertToNodeSpaceAR(this.tempPos,this.tempPos); let tNode = this.getEffect(); tNode.active = true; tNode.getComponent(ParticleSystem2D).resetSystem(); tNode.setPosition(this.tempPos.x,this.tempPos.y); tween(tNode).delay(this.liftime).call(()=>{ this.pushEffect(tNode); }).start(); } } protected update(dt: number): void { this._curFarme = Math.min(this._curFarme + 1, this._maxFarme); } }