69 lines
1.5 KiB
TypeScript
Raw Normal View History

2023-11-17 18:29:39 +08:00
import { sp } from 'cc';
import { _decorator, Component, Node } from 'cc';
import { app } from '../../../App';
import { UIPetAnim } from '../../../consts/GData';
import { v3 } from 'cc';
2023-11-28 02:13:05 +08:00
import { PlayerPetOV } from '../../../consts/API';
import { Label } from 'cc';
import { PlayerPetEvent } from '../../../data/PlayerPetData';
2023-11-17 18:29:39 +08:00
const { ccclass, property } = _decorator;
@ccclass('PetIcon')
export class PetIcon extends Component {
@property(sp.Skeleton)
spine:sp.Skeleton;
2023-11-28 02:13:05 +08:00
@property(Node)
starNode:Node; //星星
info:PlayerPetOV;
onLoad(){
this.reset();
//监听
app.event.on(PlayerPetEvent.UPDATE_INFO,this.onUpdateInfo,this)
}
protected onDestroy(): void {
app.event.off(PlayerPetEvent.UPDATE_INFO,this.onUpdateInfo,this)
}
//初始化
reset(){
this.starNode.active = false;
2023-11-17 18:29:39 +08:00
2023-11-28 02:13:05 +08:00
}
//信息更新
onUpdateInfo(info:PlayerPetOV){
if(this.info && info.petId == this.info.petId){
this.onUpdateView(); //刷新页面
}
}
//刷新页面
onUpdateView(){
this.spine.skeletonData = app.battleRes.getRoleSpine(this.info.petTbId);
2023-11-17 18:29:39 +08:00
this.spine.setAnimation(0,UIPetAnim.std,true);
2023-11-28 02:13:05 +08:00
if(this.info.petStar){
this.starNode.active = true;
this.starNode.getComponentInChildren(Label).string = `${this.info.petStar}`;
}
2023-11-17 18:29:39 +08:00
}
2023-11-28 02:13:05 +08:00
//设置icon
set(info:PlayerPetOV){
this.reset();
this.info = info;
this.onUpdateView();
}
2023-11-17 18:29:39 +08:00
}