import { _decorator, Color, Component, instantiate, Node, Prefab, Sprite, Vec2, Vec3 } from 'cc'; import { SkinItem } from './SkinItem'; import EventMgr from '../../script/Manager/EventMgr'; import { Skin } from '../../script/Manager/LocalDataMgr'; const { ccclass, property } = _decorator; @ccclass('SkinItem2') export class SkinItem2 extends SkinItem { @property({type:Node}) lock:Node = null @property({type:Node}) usingLabel:Node = null @property(Sprite) bgSprite:Sprite = null @property({type:Node}) btnUse:Node = null private unlockColor = "C16D51" private lockColor = "FFFFFF" private key:number = -1 private isUnlock:boolean = false protected override start(): void { super.start() this.btnUse.on(Node.EventType.TOUCH_END,this.onBtnUseClick,this) } override init(key: number,spine:Prefab,animName:string = "idle",spineOffset:Vec2 = new Vec2(0,0),isUnlock:boolean = false) { let skin = instantiate(spine) this.skinRoot.addChild(skin) skin.active = true skin.setPosition(Vec3.ZERO) skin.position = skin.position.clone().add3f(spineOffset.x,spineOffset.y,0) this.lock.active = !isUnlock this.key = key this.setBgColor(isUnlock) this.isUnlock = isUnlock } override onClick() { this.isUnlock = true this.setBgColor(this.isUnlock) this.lock.active = !this.isUnlock Skin.addSelectSkin(this.key) } onBtnUseClick() { Skin.setSelectStatu(true) EventMgr.ins.dispatchEvent("showUsingLabel",[this.node,this.isUnlock]) EventMgr.ins.dispatchEvent("regenerate") } setBgColor(isUnlock) { let color = new Color() this.bgSprite.color = isUnlock ? Color.fromHEX(color, this.unlockColor) : Color.fromHEX(color, this.lockColor); } }