import FqLogin from "../../../../login/FqLogin"; import { AudioMgr } from "../../../../main/ViewManage"; import BaseEvent from "../base/BaseEvent"; /** * 多组按钮控制开门 */ const { ccclass, property } = cc._decorator; @ccclass export default class FOpenDoorButton extends BaseEvent { @property({ displayName: '替换的图片', type: cc.Sprite, }) mIcon: cc.Sprite = null; @property({ displayName: '未踩上图片', type: cc.SpriteFrame, }) mIcon0: cc.SpriteFrame = null; @property({ displayName: '踩上后的图片', type: cc.SpriteFrame, }) mIcon1: cc.SpriteFrame = null; /** * 控制的栅栏机关 */ @property({ displayName: '其它开关', type: [cc.Node], }) mButtons: Array = []; /** * 控制的栅栏机关 */ @property({ displayName: '控制的机关', type: [cc.Node], }) mFenceTrigger: Array = []; /** * 是否选中 */ public isHang = false; /** * 机关是否已经结束 */ public isOver = false; private count = 0; onBeginContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider) { if (other.node.group != 'bullet') { this.count++ this.onBegin(self.tag) } } onEndContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider) { if (other.node.group != 'bullet') { this.count-- if (this.count <= 0) { this.count = 0; this.onEnd(self.tag) } } } onBegin(tag: number) { this.isHang = true this.mIcon.spriteFrame = this.mIcon1 this.checkOpen() } onEnd(tag: number) { this.isHang = false this.mIcon.spriteFrame = this.mIcon0 this.isOver = false; for (let i = 0; i < this.mFenceTrigger.length; i++) { const element = this.mFenceTrigger[i]; element.active = true; this.showFence(element, 'open'); } } private checkOpen() { // cc.log('checkOpen : ',this.isOver) if (this.isOver) { return } //检查其它开关是否打开 for (let i = 0; i < this.mButtons.length; i++) { const element = this.mButtons[i]; let fdb = element.getComponent(FOpenDoorButton) if (!fdb.isHang) { for (let i = 0; i < this.mFenceTrigger.length; i++) { const element = this.mFenceTrigger[i]; this.showFence(element, 'shake'); } return } } this.isOver = true this.pause() this.moveCamera(this.mFenceTrigger[0].getPosition(), 1, () => { cc.tween(this.node).sequence( cc.callFunc(() => { for (let i = 0; i < this.mFenceTrigger.length; i++) { const element = this.mFenceTrigger[i]; this.showFence(element, 'close'); } this.ff.main.playerEffectByPath(AudioMgr.openDoor); }), cc.delayTime(1), cc.callFunc(() => { this.resume() FqLogin.commitEvent(this.node.name, '', ''); for (let i = 0; i < this.mFenceTrigger.length; i++) { const element = this.mFenceTrigger[i]; element.active = false; } }) ).start(); }) } private showFence(element, action) { let nodes = element.children; for (let i = 0; i < nodes.length; i++) { const element = nodes[i]; let spine = element.getComponent(sp.Skeleton); if (spine) { spine.setAnimation(0, action, false); } } } }