SkinItem2.ts 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import { _decorator, Color, Component, instantiate, Node, Prefab, Sprite, sys, Vec2, Vec3 } from 'cc';
  2. import { SkinItem } from './SkinItem';
  3. import EventMgr from '../../script/Manager/EventMgr';
  4. import { allSkinList, Skin, SuperFind } from '../../script/Manager/LocalDataMgr';
  5. import { mainscene } from '../../script/mainscene';
  6. import PlatformService from '../../script/Platform/PlatformService';
  7. const { ccclass, property } = _decorator;
  8. @ccclass('SkinItem2')
  9. export class SkinItem2 extends SkinItem {
  10. @property({type:Node})
  11. lock:Node = null
  12. @property({type:Node})
  13. usingLabel:Node = null
  14. @property(Sprite)
  15. bgSprite:Sprite = null
  16. @property({type:Node})
  17. btnUse:Node = null
  18. private unlockColor = "C16D51"
  19. private lockColor = "FFFFFF"
  20. private key:number = -1
  21. private isUnlock:boolean = false
  22. protected override start(): void {
  23. super.start()
  24. this.btnUse.on(Node.EventType.TOUCH_END,this.onBtnUseClick,this)
  25. }
  26. override init(key: number,spine:Prefab,animName:string = "idle",spineOffset:Vec2 = new Vec2(0,0),isUnlock:boolean = false)
  27. {
  28. let skin = instantiate(spine)
  29. this.skinRoot.addChild(skin)
  30. skin.active = true
  31. skin.setPosition(Vec3.ZERO)
  32. skin.position = skin.position.clone().add3f(spineOffset.x,spineOffset.y,0)
  33. this.lock.active = !isUnlock
  34. this.key = key
  35. this.setBgColor(isUnlock)
  36. this.isUnlock = isUnlock
  37. }
  38. override onClick()
  39. {
  40. if (sys.Platform.BYTEDANCE_MINI_GAME == sys.platform) {
  41. mainscene.instance.ge.track(
  42. "ad_show", //追踪事件的名称
  43. {
  44. version: "123",
  45. ad_position: "小熊解锁皮肤",
  46. level_id: SuperFind.superFindData.currentBgKey
  47. } //需要上传的事件属性
  48. );
  49. }
  50. PlatformService.getInstance().platformApi.loadAndShowVideoAd(() => {
  51. // PlatformService.getInstance().platformApi.reportAnalytics("tips", {
  52. // level: this.data.title
  53. // })
  54. if (sys.Platform.BYTEDANCE_MINI_GAME == sys.platform) {
  55. mainscene.instance.ge.track(
  56. "ad_showend", //追踪事件的名称
  57. {
  58. version: "123",
  59. ad_position: "小熊解锁皮肤",
  60. level_id: SuperFind.superFindData.currentBgKey
  61. } //需要上传的事件属性
  62. );
  63. this.isUnlock = true
  64. this.setBgColor(this.isUnlock)
  65. this.lock.active = !this.isUnlock
  66. Skin.addSelectSkin(this.key)
  67. }
  68. })
  69. }
  70. onBtnUseClick()
  71. {
  72. Skin.setCurrentSelSingleSkin(this.key)
  73. Skin.setSelectStatu(true)
  74. EventMgr.ins.dispatchEvent("showUsingLabel",[this.node,this.isUnlock])
  75. EventMgr.ins.dispatchEvent("regenerate")
  76. // console.log("当前被选中的皮肤",allSkinList[this.key])
  77. }
  78. setBgColor(isUnlock)
  79. {
  80. let color = new Color()
  81. this.bgSprite.color = isUnlock ? Color.fromHEX(color, this.unlockColor) : Color.fromHEX(color, this.lockColor);
  82. }
  83. override getKey(): number {
  84. return this.key
  85. }
  86. }