// Learn TypeScript: // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html // Learn Attribute: // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html import { SaveDataManager } from "../../component/SaveDataManager"; import { GameSceneObjTable } from "../../kernel/table/TableDefine"; import { MainSceneData } from "../../scenes/MainSceneData"; const { ccclass, property } = cc._decorator; @ccclass export default class GameSceneUnlockTip extends cc.Component { private _obj: GameSceneObjTable; private _txtNum: cc.Label; private _txtName: cc.Label; private _btn: cc.Node; //#region LIFE-CYCLE CALLBACKS: onLoad() { this._txtNum = this.node.getChildByName('btnUnlock').getComponentInChildren(cc.Label); this._txtName = this.node.getChildByName('txtName').getComponent(cc.Label); this._btn = this.node.getChildByName('btnUnlock'); } // update (dt) {} //#endregion //#region public method setObj(obj: GameSceneObjTable) { this._obj = obj; this.refresh(); } //#endregion //#region event onClick() { if (this._obj && !MainSceneData.isUnlockAni) { this.node.active = false; if (SaveDataManager.ins.runtimeData.star >= this._obj.Star) { let wpos = this._btn.convertToWorldSpaceAR(cc.v3(0, 0, 0)); if (SaveDataManager.ins.adjustStar(-this._obj.Star, true, wpos)) { SaveDataManager.ins.unlockGameSceneObj(this._obj.ID); } } } } //#endregion //#region private method private refresh() { this._txtName.string = this._obj.Name; this._txtNum.string = this._obj.Star.toString(); this._btn.getComponent(cc.Button).interactable = SaveDataManager.ins.runtimeData.star >= this._obj.Star; } //#endregion }