import { _decorator, Animation, Component, Label, Node, ProgressBar, Sprite } from 'cc'; import { resMgr } from '../../Frames/ResourcesMgr'; const { ccclass, property } = _decorator; @ccclass('Card') export class Card extends Component { private _lock: Node = null; private _label: Node = null; private _sprite: Node = null; private _shadow: Node = null; private _oreCount: Node = null; private _consume: Node = null; consumeCount: number = null; //是否可以点击 clickable: boolean = true; //是否禁用 disabled: boolean = false; private _shadow001: Node = null; protected onLoad(): void { this._lock = this.node.getChildByName("Lock"); this._label = this.node.getChildByName("Label"); this._sprite = this.node.getChildByName("Sprite"); this._shadow = this.node.getChildByName("Shadow"); this._consume = this.node.getChildByName("Count"); this._shadow001 = this.node.getChildByName("Shadow-001"); this._oreCount = this.node.parent.parent.getChildByPath("OreSpeed/_oreSpeed"); } start() { //这个Card可以使用的条件:clickable === true; disabled === false this.consumeCount = Number(this._consume.getComponent(Label).string); } protected update(dt: number): void { const strOreCount: string = this._oreCount.getComponent(Label).string; if (this.consumeCount) { if (Number(strOreCount) <= this.consumeCount) { //开启阴影 this._shadow.active = true; //不可点击 this.clickable = false; } else { //阴影关闭 this._shadow.active = false; //可以点击 this.clickable = true; } } } //冷却当中 aniPlay() { this._shadow001.active = true; this._shadow001.getComponent(Animation).play(); } aniStart() { //如何没被禁用,则动画开始播放的时候,开始禁用 if (!this.disabled) { this.disabled = true; } } aniEnd() { //如何被禁用,则动画结束播放的时候,不禁用 if (this.disabled) { this.disabled = false; } this._shadow001.active = false; } setLock(b: boolean) { this._lock.active = b; } setlabel(b: boolean) { this._label.active = b; } setSprite(name: string) { this._sprite.getComponent(Sprite).spriteFrame = resMgr.getSpriteFrame(name); } }