123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- import { _decorator, Color, Component, instantiate, Node, Prefab, Sprite, Vec2, Vec3 } from 'cc';
- import { SkinItem } from './SkinItem';
- import EventMgr from '../../script/Manager/EventMgr';
- import { allSkinList, 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.setCurrentSelSingleSkin(this.key)
- Skin.setSelectStatu(true)
- EventMgr.ins.dispatchEvent("showUsingLabel",[this.node,this.isUnlock])
- EventMgr.ins.dispatchEvent("regenerate")
- console.log("当前被选中的皮肤",allSkinList[this.key])
- }
- setBgColor(isUnlock)
- {
- let color = new Color()
- this.bgSprite.color = isUnlock ? Color.fromHEX(color, this.unlockColor) : Color.fromHEX(color, this.lockColor);
- }
- }
|