AudienceManager.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import ccclass = cc._decorator.ccclass;
  2. import property = cc._decorator.property;
  3. import Audience from "../prefab/Audience";
  4. @ccclass
  5. export class AudienceManager extends cc.Component {
  6. @property(cc.Node)
  7. audienceNodeList: cc.Node[] = [];
  8. @property(cc.Prefab)
  9. audiencePrefab: cc.Prefab = null;
  10. private audienceList: Audience[] = [];
  11. protected onLoad() {
  12. }
  13. protected start() {
  14. }
  15. audienceShow(comboCount) {
  16. if (comboCount < 2) {
  17. return;
  18. }
  19. let audienceNode: cc.Node = cc.instantiate(this.audiencePrefab)
  20. let initNode = this.getNode()
  21. if (!initNode) {
  22. return;
  23. }
  24. initNode.addChild(audienceNode)
  25. let targetPos: cc.Vec3 = new cc.Vec3(0, 0, 0)
  26. audienceNode.position = new cc.Vec3(initNode.position.x > 0 ? 800 : -800, 0, 0)
  27. let audience = audienceNode.getComponent(Audience)
  28. this.audienceList.push(audience)
  29. cc.tween(audienceNode)
  30. .to(0.3, {position: targetPos})
  31. .call(() => {
  32. audience.showShadow()
  33. }).start()
  34. }
  35. audienceSigh() {
  36. //观众叹气
  37. for (let i = 0; i < this.audienceList.length; i++) {
  38. let audience = this.audienceList[i]
  39. audience.sigh(false, 1, () => {
  40. })
  41. }
  42. // this.audienceLeave()
  43. }
  44. audienceLeave() {
  45. if (this.audienceList.length > 0) {
  46. let index = this.audienceList.length - 1
  47. let last = this.audienceList[index]
  48. last.exit(false, 1, () => {
  49. cc.tween(last.node)
  50. .to(0.4, {opacity: 0, scale: 0.5})
  51. .call(() => {
  52. this.audienceList.splice(index, 1)
  53. this.audienceNodeList[index].removeAllChildren()
  54. }).start()
  55. })
  56. }
  57. }
  58. audienceApplaud() {
  59. //关注鼓掌
  60. for (let i = 0; i < this.audienceList.length; i++) {
  61. let audience = this.audienceList[i]
  62. audience.applaud(false, 0.5, () => {
  63. })
  64. }
  65. }
  66. reInit() {
  67. for (let i = 0; i < this.audienceList.length; i++) {
  68. this.audienceList[i].node.destroy()
  69. }
  70. this.audienceList = []
  71. }
  72. private getNode(): cc.Node {
  73. for (let i = 0; i < this.audienceNodeList.length; i++) {
  74. let node = this.audienceNodeList[i]
  75. if (node.children.length == 0) {
  76. return node
  77. }
  78. }
  79. return null;
  80. }
  81. }