| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 | import { _decorator, Animation, Component, Label, Node, 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 = 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可以使用的条件:disabled === false; clickable === true        const consumeCount = this._consume?.getComponent(Label);        this.consumeCount = Number(consumeCount?.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.disabled = true;        this._shadow001.getComponent(Animation).play();        this._shadow001.getComponent(Animation).on(Animation.EventType.FINISHED,()=>{            this.disabled = false;            this._shadow001.active = false;        })    }    aniStart() {        //如何没被禁用,则动画开始播放的时候,开始禁用        this.disabled = true;    }    aniEnd() {        //如何被禁用,则动画结束播放的时候,不禁用        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);    }}
 |