TransMgr.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { _decorator, Component, Node, tween, UIOpacity, UITransform, v3 } from 'cc';
  2. const { ccclass, property } = _decorator;
  3. @ccclass('Manager/TransMgr')
  4. export class TransMgr extends Component {
  5. private static inst: TransMgr = null
  6. public static get Inst(): TransMgr {
  7. return this.inst
  8. }
  9. @property(UITransform)
  10. private gc1UiTrans: UITransform = null
  11. @property(UITransform)
  12. private gc2UiTrans: UITransform = null
  13. @property(Node)
  14. private logo: Node = null
  15. private gc1OrgHeight: number = 0
  16. private gc2OrgHeight: number = 0
  17. protected onLoad(): void {
  18. TransMgr.inst = this
  19. this.gc1OrgHeight = this.gc1UiTrans.height
  20. this.gc2OrgHeight = this.gc2UiTrans.height
  21. this.node.active = false
  22. }
  23. public fadeIn() {
  24. return new Promise<void>((resolve, reject) => {
  25. this.node.active = true
  26. this.logo.setScale(v3(0, 0, 1))
  27. tween(this.logo).delay(0.2).to(0.5, { scale: v3(1, 1, 1) }, { easing: 'backOut' }).start()
  28. tween(this.gc1UiTrans).set({ height: 0 }).to(0.2, { height: this.gc1OrgHeight }).start()
  29. const tw = tween(this.gc2UiTrans)
  30. tw.set({ height: 0 })
  31. tw.to(1, { height: this.gc2OrgHeight }, { easing: 'cubicOut' })
  32. tw.call(() => {
  33. resolve()
  34. })
  35. tw.start()
  36. })
  37. }
  38. public fadeOut() {
  39. return new Promise<void>((resolve, reject) => {
  40. tween(this.logo).to(0.5, { scale: v3() }, { easing: 'backIn' }).start()
  41. tween(this.gc1UiTrans).delay(0.8).to(0.2, { height: 0 }).start()
  42. const tw = tween(this.gc2UiTrans)
  43. tw.to(1, { height: 0 }, { easing: 'cubicIn' })
  44. tw.call(() => {
  45. this.node.active = false
  46. resolve()
  47. })
  48. tw.start()
  49. })
  50. }
  51. }