ResultUI.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { _decorator, Component, Node, sp } from 'cc';
  2. const { ccclass, property } = _decorator;
  3. @ccclass('ResultUI')
  4. export class ResultUI extends Component {
  5. @property({type:Node,tooltip:'胜利界面'})
  6. win:Node = null;
  7. @property({type:Node,tooltip:'失败界面'})
  8. lose:Node = null;
  9. @property({type:sp.Skeleton,tooltip:'胜利动画'})
  10. winSpine:sp.Skeleton = null;
  11. @property({type:sp.Skeleton,tooltip:'失败动画'})
  12. loseSpine:sp.Skeleton = null;
  13. private _endcallback:Function
  14. protected onLoad(): void {
  15. this.loseSpine.setCompleteListener(this.actionComplete.bind(this))
  16. this.winSpine.setCompleteListener(this.actionComplete.bind(this))
  17. }
  18. show(bWin:boolean,callback:Function = null) {
  19. this.node.active = true
  20. if(bWin){
  21. this.win.active = true
  22. this.lose.active = false
  23. this.winSpine.setAnimation(0,'animation1',false)
  24. }else{
  25. this.win.active = false
  26. this.lose.active = true
  27. this.loseSpine.setAnimation(0,'animation1',false)
  28. }
  29. this._endcallback = callback
  30. }
  31. actionComplete(trackEntry:sp.spine.TrackEntry) {
  32. this.node.active = false
  33. this._endcallback&&this._endcallback()
  34. this._endcallback = null
  35. }
  36. onTouchButton(event, customStr) {
  37. if(event.target.name == "back"){
  38. this.node.active = false
  39. this._endcallback&&this._endcallback()
  40. this._endcallback = null
  41. }
  42. }
  43. }