mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-06-26 19:34:47 +00:00
44 lines
958 B
TypeScript
44 lines
958 B
TypeScript
import { Label } from 'cc';
|
|
import { _decorator, Component, Node } from 'cc';
|
|
import ResourceData, { ResourceEvent, ResourceType } from '../../../data/ResourceData';
|
|
import { Enum } from 'cc';
|
|
import { app } from '../../../App';
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass('PlayerResourceShow')
|
|
export class PlayerResourceShow extends Component {
|
|
|
|
|
|
//显示的资源
|
|
@property({type:Enum(ResourceType)})
|
|
type:ResourceType = ResourceType.Gold;
|
|
|
|
//显示文本
|
|
@property(Label)
|
|
show:Label;
|
|
|
|
protected onLoad(): void {
|
|
|
|
//更新
|
|
this.onUpdateView();
|
|
//监听
|
|
app.event.on(ResourceEvent.UPDATE,this.onUpdateView,this);
|
|
|
|
}
|
|
|
|
protected onDestroy(): void {
|
|
app.event.off(ResourceEvent.UPDATE,this.onUpdateView,this);
|
|
}
|
|
|
|
//刷新
|
|
onUpdateView(){
|
|
|
|
//更新资源数量
|
|
this.show.string = `${ResourceData.getIns().getValue(this.type)}`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|